Пример #1
0
        public Dictionary <string, List <string> > read()
        {
            var text  = File.ReadAllText(config["dictionaryFileName"]);
            var lines = text.Replace("\r", "").Split('\n');
            var dict  = new Dictionary <string, List <string> >();

            foreach (var line in lines)
            {
                var sameWords = line.Split('=').Select(word => word.Trim()).ToList();
                if (sameWords.Count() < 2)
                {
                    continue;
                }
                var key = new AnagramChecker().sortLetters(sameWords[0]);
                if (dict.ContainsKey(key))
                {
                    dict[key].AddRange(sameWords);
                    dict[key] = dict[key].Distinct().ToList();
                }
                else
                {
                    dict.Add(key, sameWords);
                }
            }
            return(dict);
        }
Пример #2
0
        public void AnagramCheckerTest_OneWord_True()
        {
            string         testWord              = "bread";
            string         testWordList          = "beard";
            AnagramChecker testAnagramChecker    = new AnagramChecker(testWord, testWordList);
            List <string>  results               = testAnagramChecker.Check();
            string         sortedTestWord        = AnagramChecker.SortWord(testWord);
            string         sortedPossibleAnagram = AnagramChecker.SortWord(results[0]);

            Assert.Equal(true, sortedPossibleAnagram == sortedTestWord);
        }
Пример #3
0
 public HomeModule()
 {
     Get["/"] = _ => {
         //List<string> anagramList = new List<string>();
         return(View["index.cshtml"]);
     };
     Post["/anagram"] = _ => {
         AnagramChecker newAnagram  = new AnagramChecker(Request.Form["user-word"], Request.Form["user-anagrams"]);
         var            anagramList = newAnagram.Check();
         return(View["anagram.cshtml", anagramList]);
     };
 }
Пример #4
0
        public static void Main()
        {
            Console.WriteLine("Please enter a word:");
            string         word   = Console.ReadLine();
            AnagramChecker myWord = new AnagramChecker(word);

            Console.WriteLine("Enter a list of possible anagram words separate by space:");
            string wordString = Console.ReadLine();
            string result     = myWord.FindAnagram(wordString);

            if (result.Length > 0)
            {
                Console.WriteLine("\'" + result + "\' are anagrams of " + myWord.GetWord());
            }
            else
            {
                Console.WriteLine("None of the words are anagrams of " + myWord.GetWord());
            }
        }
Пример #5
0
        public void AnagramCheckerTest_WillReturnNonAnagrams_False()
        {
            bool           goodData           = true;
            string         testWord           = "bread";
            string         testWordList       = "beard,bared,kite,flyer";
            AnagramChecker testAnagramChecker = new AnagramChecker(testWord, testWordList);
            List <string>  results            = testAnagramChecker.Check();
            string         sortedTestWord     = AnagramChecker.SortWord(testWord);

            foreach (string possibleAnagram in results)
            {
                Console.WriteLine(possibleAnagram);
                string sortedPossibleAnagram = AnagramChecker.SortWord(possibleAnagram);
                if (sortedPossibleAnagram != sortedTestWord)
                {
                    goodData = false;
                }
            }
            Assert.Equal(true, goodData);
        }