🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉 # RN0311's solution

## to Scrabble Score in the C# Track

Published at Oct 24 2020 · 0 comments
Instructions
Test suite
Solution

Given a word, compute the scrabble score for that word.

## Letter Values

You'll need these:

``````Letter                           Value
A, E, I, O, U, L, N, R, S, T       1
D, G                               2
B, C, M, P                         3
F, H, V, W, Y                      4
K                                  5
J, X                               8
Q, Z                               10
``````

## Examples

"cabbage" should be scored as worth 14 points:

• 3 points for C
• 1 point for A, twice
• 3 points for B, twice
• 2 points for G
• 1 point for E

And to total:

• `3 + 2*1 + 2*3 + 2 + 1`
• = `3 + 2 + 6 + 3`
• = `5 + 9`
• = 14

## Extensions

• You can play a double or a triple letter.
• You can play a double or a triple word.

## Running the tests

To run the tests, run the command `dotnet test` from within the exercise directory.

Initially, only the first test will be enabled. This is to encourage you to solve the exercise one step at a time. Once you get the first test passing, remove the `Skip` property from the next test and work on getting that test passing. Once none of the tests are skipped and they are all passing, you can submit your solution using `exercism submit ScrabbleScore.cs`

## Further information

For more detailed information about the C# track, including how to get help if you're having trouble, please visit the exercism.io C# language page.

## Source

Inspired by the Extreme Startup game https://github.com/rchatley/extreme_startup

### ScrabbleScoreTests.cs

``````// This file was auto-generated based on version 1.1.0 of the canonical data.

using Xunit;

public class ScrabbleScoreTests
{
[Fact]
public void Lowercase_letter()
{
Assert.Equal(1, ScrabbleScore.Score("a"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Uppercase_letter()
{
Assert.Equal(1, ScrabbleScore.Score("A"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Valuable_letter()
{
Assert.Equal(4, ScrabbleScore.Score("f"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Short_word()
{
Assert.Equal(2, ScrabbleScore.Score("at"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Short_valuable_word()
{
Assert.Equal(12, ScrabbleScore.Score("zoo"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Medium_word()
{
Assert.Equal(6, ScrabbleScore.Score("street"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Medium_valuable_word()
{
Assert.Equal(22, ScrabbleScore.Score("quirky"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Long_mixed_case_word()
{
Assert.Equal(41, ScrabbleScore.Score("OxyphenButazone"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void English_like_word()
{
Assert.Equal(8, ScrabbleScore.Score("pinata"));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Empty_input()
{
Assert.Equal(0, ScrabbleScore.Score(""));
}

[Fact(Skip = "Remove this Skip property to run this test")]
public void Entire_alphabet_available()
{
Assert.Equal(87, ScrabbleScore.Score("abcdefghijklmnopqrstuvwxyz"));
}
}``````
``````using System;

public static class ScrabbleScore
{
public static int Score(string input)
{
if(String.IsNullOrWhiteSpace(input) == true){
return 0;
}
int sum = 0;
foreach(var character in input.ToUpper()){
switch(character){
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'L':
case 'N':
case 'R':
case 'S':
case 'T':
sum+=1;
break;
case 'D':
case 'G':
sum+=2;
break;
case 'B':
case 'C':
case 'M':
case 'P':
sum +=3;
break;
case 'F':
case 'H':
case 'V':
case 'W':
case 'Y':
sum+=4;
break;
case 'K':
sum+=5;
break;
case 'J':
case 'X':
sum+=8;
break;
case 'Q':
case 'Z':
sum+=10;
break;
default:
throw new ArgumentException();
}
}
return sum;
}
}``````