Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions csharp-scrabble-challenge.Main/Scrabble.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,65 @@ namespace csharp_scrabble_challenge.Main
{
public class Scrabble
{
private string _word;
public Dictionary<char, int> scoreMap = new Dictionary<char, int>
{
{ 'A', 1 },
{ 'B', 3 },
{ 'C', 3 },
{ 'D', 2 },
{ 'E', 1 },
{ 'F', 4 },
{ 'G', 2 },
{ 'H', 4 },
{ 'I', 1 },
{ 'J', 8 },
{ 'K', 5 },
{ 'L', 1 },
{ 'M', 3 },
{ 'N', 1 },
{ 'O', 1 },
{ 'P', 3 },
{ 'Q', 10 },
{ 'R', 1 },
{ 'S', 1 },
{ 'T', 1 },
{ 'U', 1 },
{ 'V', 4 },
{ 'W', 4 },
{ 'X', 8 },
{ 'Y', 4 },
{ 'Z', 10 }
};
public Scrabble(string word)
{
//TODO: do something with the word variable
_word = word;
}

public int score()
{
//TODO: score calculation code goes here
throw new NotImplementedException(); //TODO: Remove this line when the code has been written
if (_word == "")
{
return 0;
}
int score = 0;
foreach (char letter in this._word)
{
if (!Char.IsLetter(letter))
{
return 0;
}

int letterScore = scoreMap[Char.ToUpper(letter)];

if (letterScore < 0)
{
return 0;
}
score += letterScore;
}

return score;
}
}
}
2 changes: 1 addition & 1 deletion csharp-scrabble-challenge.Test/CoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class CoreTests
[TestCase("street", 6)]
public void WordScoreTests(string word, int targetScore)
{
Assert.AreEqual(this.GetWordScore(word), targetScore);
Assert.That(this.GetWordScore(word), Is.EqualTo(targetScore));
}

private int GetWordScore(string word) => new Scrabble(word).score();
Expand Down
2 changes: 1 addition & 1 deletion csharp-scrabble-challenge.Test/ExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ExtensionTests
[TestCase("[OXyPHEnBUTaZoNE]", 123)]
public void ExtendedCriteriaTests(string word, int targetScore)
{
Assert.AreEqual(this.GetWordScore(word), targetScore);
Assert.That(this.GetWordScore(word), Is.EqualTo(targetScore));
}

private int GetWordScore(string word) => new Scrabble(word).score();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading