Skip to content
Permalink
Browse files

LetterBoxStrWords - CountsWords

  • Loading branch information...
bobbymcr committed Apr 4, 2019
1 parent ab17c56 commit 777b0a1e5d55fc5909cf251241502fe2f72b5527
Showing with 30 additions and 1 deletion.
  1. +6 −1 src/Words.Core/LetterBoxStrWords.cs
  2. +24 −0 test/Words.Test/LetterBoxStrWordsTest.cs
@@ -17,6 +17,8 @@ public LetterBoxStrWords()
this.words = new Dictionary<Ch, HashSet<Word>>();
}

public int Count { get; private set; }

public void Add(Str word, LetterBoxStr.Vertices verts)
{
HashSet<Word> keyedWords;
@@ -27,7 +29,10 @@ public void Add(Str word, LetterBoxStr.Vertices verts)
this.words.Add(key, keyedWords);
}

keyedWords.Add(new Word(word, verts));
if (keyedWords.Add(new Word(word, verts)))
{
++this.Count;
}
}

public void Find(Action<Str, Str> found)
@@ -69,6 +69,30 @@ public void ManyWordsFindsAllSolutions()
FindSolutions(words).Should().BeEquivalentTo("ADB-BECFHJGKIL", "ADBECF-FGJHKIL", "ADBECF-FAHKILJG");
}

[Fact]
public void CountsWords()
{
LetterBoxStrWords words = new LetterBoxStrWords();

words.Count.Should().Be(0);

words.Add(default(Str).Append(Ch.A).Append(Ch.B), default(LetterBoxStr.Vertices));

words.Count.Should().Be(1);

words.Add(default(Str).Append(Ch.A).Append(Ch.B), default(LetterBoxStr.Vertices));

words.Count.Should().Be(1);

words.Add(default(Str).Append(Ch.A).Append(Ch.B).Append(Ch.C), default(LetterBoxStr.Vertices));

words.Count.Should().Be(2);

words.Add(default(Str).Append(Ch.B).Append(Ch.C).Append(Ch.D), default(LetterBoxStr.Vertices));

words.Count.Should().Be(3);
}

private static IList<string> FindSolutions(LetterBoxStrWords words)
{
List<string> found = new List<string>();

0 comments on commit 777b0a1

Please sign in to comment.
You can’t perform that action at this time.