예제 #1
0
        public void FindAnagrams_Multiple()
        {
            var input    = new string(@"dog god cat tac bag");
            var result   = AnagramAggregator.FindAll(input.Split(" ").ToList());
            var expected = new Dictionary <string, LinkedList <string> >()
            {
                {
                    "dgo",
                    new LinkedList <string>
                    (
                        new string[]
                    {
                        "dog",
                        "god"
                    }
                    )
                },
                {
                    "act",
                    new LinkedList <string>
                    (
                        new string[]
                    {
                        "cat",
                        "tac"
                    }
                    )
                },
                {
                    "abg",
                    new LinkedList <string>
                    (
                        new string[]
                    {
                        "bag"
                    }
                    )
                }
            };

            result.Should().BeEquivalentTo(expected);
        }
예제 #2
0
        public void FindAnagrams_NegativeMatch()
        {
            var input    = new string(@"dog god cat tac bag");
            var result   = AnagramAggregator.FindAll(input.Split(" ").ToList());
            var expected = new Dictionary <string, LinkedList <string> >()
            {
                {
                    "dgo",
                    new LinkedList <string>
                    (
                        new string[]
                    {
                        "dog",
                        "god"
                    }
                    )
                },
            };

            result.Should().NotEqual(expected);
        }
예제 #3
0
 static void Main(string[] args)
 {
     try
     {
         if (args == null)
         {
             throw new Exception("No fileName provided!");
         }
         // The path is passed as the first argument
         string fileName = args[0];
         if (!File.Exists(fileName))
         {
             throw new FileNotFoundException();
         }
         Console.WriteLine($"File : {fileName}");
         Console.WriteLine($"Begin Reading File...");
         var lines = FileReader.GetWords(fileName);
         Console.WriteLine($"Finished Reading File.");
         if (lines.Count == 0)
         {
             throw new Exception("No lines found!");
         }
         Console.WriteLine($"Finding Anagrams from {lines.Count} lines...");
         var anagrams = AnagramAggregator.FindAll(lines);
         Console.WriteLine($"Found {anagrams.Count} anagrams.");
         Console.WriteLine($"Anagrams:\n{anagrams.FormatResult()}");
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error - Exception : {e}");
     }
     finally
     {
         Console.WriteLine("Press Any key to exit.");
         Console.ReadLine();
     }
 }
예제 #4
0
 public void FindAnagrams_FormatResult()
 {
     var input  = new string(@"dog god cat tac bag");
     var result = AnagramAggregator.FindAll(input.Split(" ").ToList()).FormatResult();
 }