public void Find() { IEnumerable <string> words = WordListLoader.Load( @"D:\Projects\perth-code-dojo-5-anagram-algorithm\AnagramAlgorithm\AlgorithmEngine\App_Data\wordlist.txt") .Where(w => w.Length >= 3 && Regex.IsMatch(w.ToString(), @"^[a-z]+$")); var sw = new Stopwatch(); sw.Reset(); sw.Start(); TestTimer tt = new TestTimer(); tt.Start(); List <string> matches = AnagramEngine.Find("webster", words.ToList()); Console.Write("webster" + " - "); foreach (var match in matches) { Console.Write(match + " "); } tt.Start(); Console.WriteLine(tt.ElapsedMilliseconds); sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds); //600 - 700 list //450 - 550 }
static void Main(string[] args) { Console.WriteLine("Enter a word:"); var word = Console.ReadLine(); IEnumerable <string> words = WordListLoader.Load( @"D:\Projects\perth-code-dojo-5-anagram-algorithm\AnagramAlgorithm\AlgorithmEngine\App_Data\wordlist.txt") .Where(w => w.Length >= 3 && Regex.IsMatch(w.ToString(), @"^[a-z]+$")); Console.Write(word + " - "); List <string> matches = AnagramEngine.Find(word, words.ToList()); matches = matches.OrderBy(m => m.Length).ToList(); if (matches.Count == 0) { Console.WriteLine("No matches found!"); } foreach (var match in matches) { Console.Write(match + " "); } Console.WriteLine(); Console.ReadLine(); }
static void Main(string[] args) { var stopwatch = new Stopwatch(); stopwatch.Start(); //Refactoring filtering down IEnumerable <string> words = WordListLoader.Load(@"D:\Projects\perth-code-dojo-5-anagram-algorithm\AnagramAlgorithm\AlgorithmEngine\App_Data\wordlist.txt") .Where(w => w.Length >= 3 && Regex.IsMatch(w.ToString(), @"^[a-z]+$")); foreach (var word in words) { Console.Write(word + " - "); List <string> matches = AnagramEngine.Find(word, words.ToList()); foreach (var match in matches) { Console.Write(match + " "); } Console.WriteLine(); } stopwatch.Stop(); Console.WriteLine("Time to completion -" + stopwatch.ElapsedMilliseconds); Console.ReadLine(); }
public void Find_Simple_Anagram_Removed_Words_Containing_Uppercase() { List <string> matches = AnagramEngine.Find("cat", new List <string> { "At", "bla", "rah", "cTa" }); Assert.Equal(0, matches.Count); }
public void Find_Does_Not_Return_Pural_Matches() { List <string> matches = AnagramEngine.Find("teta", new List <string> { "teta's" }); Assert.Equal(0, matches.Count); }
public void Find_Does_Not_Return_Original_Word_As_Match() { List <string> matches = AnagramEngine.Find("test", new List <string> { "test" }); Assert.Equal(0, matches.Count); }
public void Find_Simple_Anagram_Allowed_Punctuation() { List <string> matches = AnagramEngine.Find("cat's", new List <string> { "at", "bla", "rah", "ct", "cts", "cta's" }); Assert.Equal(1, matches.Count); }
public void Find_Simple_Anagram_Ignore_Spaces_And_Special_Characters() { List <string> matches = AnagramEngine.Find("cat", new List <string> { "at!", " bla", "rah", "cta" }); Assert.Equal(1, matches.Count); }
public void Find_Simple_Anagram() { List <string> matches = AnagramEngine.Find("cat", new List <string> { "at", "bla", "rah", "cta" }); Assert.Equal(1, matches.Count); }