public void IsAnagram() { Assert.IsTrue(LinkTypes.IsAnagram("bat", "tab")); Assert.IsTrue(LinkTypes.IsAnagram("angel", "angle")); Assert.IsFalse(LinkTypes.IsAnagram("cat", "angle")); Assert.IsFalse(LinkTypes.IsAnagram("cat", "cat")); }
public void AddWord(Word word) { if (words.Contains(word)) { return; } words.Add(word); // Check if word can be linked to others foreach (Word other in words) { if (LinkTypes.IsOneLetterChange(word.Text, other.Text)) { Link link = new Link(word, other, LinkType.OneLetterChange); AddLink(link); } if (LinkTypes.IsOneLetterAddOrRemove(word.Text, other.Text)) { Link link = new Link(word, other, LinkType.OneLetterAddOrRemove); AddLink(link); } if (LinkTypes.IsAnagram(word.Text, other.Text)) { Link link = new Link(word, other, LinkType.Anagram); AddLink(link); } } }
public Link(Word wordA, Word wordB, LinkType type) { this.WordA = wordA; this.WordB = wordB; this.Type = type; if (type == LinkType.Anagram && !LinkTypes.IsAnagram(WordA.Text, WordB.Text)) { throw new Exception(WordA.Text + " is not an anagram of " + WordB.Text); } if (type == LinkType.OneLetterChange && !LinkTypes.IsOneLetterChange(WordA.Text, WordB.Text)) { throw new Exception(WordA.Text + " is not a letter change from " + WordB.Text); } if (type == LinkType.OneLetterAddOrRemove && !LinkTypes.IsOneLetterAddOrRemove(WordA.Text, WordB.Text)) { throw new Exception(WordA.Text + " is not a letter additon or subtraction to " + WordB.Text); } }