public List <string> Find(string word) { StringCombinationGenerator combinationGenerator = new StringCombinationGenerator(); List <string> anagrams = combinationGenerator.ProvideSameLengthCombinations(word); return(anagrams.FindAll(anagram => repository.Contains(anagram))); }
public void DoesNotReturnAnagramsNotInRepository() { var word = "wired"; var anagramWord = "wierd"; IWordRepository repository = Substitute.For <IWordRepository>(); repository.Contains(anagramWord).Returns(false); var anagramFinder = new DeterministicAnagramFinder(repository); List <string> foundedAnagrams = anagramFinder.Find(word); Assert.IsFalse(foundedAnagrams.Contains(anagramWord)); }
public void ReturnsAnagramsInRepository() { var word = "abc"; List <string> anagrams = new List <string> { "acb", "bac", "bca", "cab", "cba" }; IWordRepository repository = Substitute.For <IWordRepository>(); anagrams.ForEach(a => repository.Contains(a).Returns(true)); var anagramFinder = new DeterministicAnagramFinder(repository); List <string> foundedAnagrams = anagramFinder.Find(word); anagrams.ForEach(anagram => Assert.IsTrue(foundedAnagrams.Contains(anagram))); }