예제 #1
0
        public void ProcessList_ReturnsListOfListsOfWordsAsExpected()
        {
            var wordlist = new List <string>
            {
                "act",
                "cat",
                "rate",
                "tare",
                "tear",
                "zephyr"
            };

            var expectedResult = new List <List <string> >
            {
                new List <string> {
                    "act", "cat"
                },
                new List <string> {
                    "rate", "tare", "tear"
                },
                new List <string> {
                    "zephyr"
                }
            };

            var result = Anagrammer.ProcessList(wordlist);

            Assert.AreEqual(expectedResult, result);
        }
예제 #2
0
        public void GetListOfAnagrams()
        {
            var wordlist = new List <string>
            {
                "act", "cat", "dog", "eat", "tea"
            };

            var expectedResult = new List <List <string> >
            {
                new List <string> {
                    "act", "cat"
                },
                new List <string> {
                    "dog"
                },
                new List <string> {
                    "eat", "tea"
                }
            };

            var result = Anagrammer.GetListOfAnagrams(wordlist);

            Assert.AreEqual(expectedResult.First().First(), result.First().First());
            Assert.AreEqual(expectedResult.Last().Last(), result.Last().Last());
        }
예제 #3
0
        public void WhenWordListIsNull_FindAnagramsInList_ReturnsEmptyList()
        {
            string        word     = String.Empty;
            List <string> wordlist = null;
            var           result   = Anagrammer.FindAnagramsInList(word, wordlist);

            Assert.AreEqual(new List <string>(), result);
        }
예제 #4
0
        public void GivenAnEmptyWordList_ProcessList_ReturnsAnEmptyListOfListsOfWords()
        {
            var wordlist       = new List <string>();
            var expectedResult = new List <List <string> >();

            var result = Anagrammer.ProcessList(wordlist);

            Assert.AreEqual(expectedResult, result);
        }
예제 #5
0
        public void WhenWordListHasNoAnagrams_FindAnagramsInList_ReturnsEmptyList()
        {
            string        word     = "right";
            List <string> wordlist = new List <string> {
                "wrong"
            };
            var result = Anagrammer.FindAnagramsInList(word, wordlist);

            Assert.AreEqual(new List <string>(), result);
        }
예제 #6
0
        public void GivenAnEmptyList_PairAlphabetizedWords_ReturnsAnEmptyList()
        {
            var wordlist = new List <string>();

            var expectedResult = new List <Tuple <string, string> >();

            var result = Anagrammer.PairAlphabeticalCharsWithWords(wordlist);

            Assert.AreEqual(expectedResult, result);
        }
예제 #7
0
        public void WhenWordListContainsOnlyGivenWord_FindAnagramsInList_ReturnsAnEmptyList()
        {
            string        word     = "right";
            List <string> wordlist = new List <string> {
                "right"
            };
            var expectedResult = new List <string>();

            var result = Anagrammer.FindAnagramsInList(word, wordlist);

            Assert.AreEqual(expectedResult, result);
        }
예제 #8
0
        public void WhenWordListContainsAnagrams_FindAnagramsInList_ReturnsCorrectList()
        {
            string        word     = "cat";
            List <string> wordlist = new List <string> {
                "tac", "act", "wrong", "excellent"
            };
            List <string> expectedWordlist = new List <string> {
                "act", "tac"
            };

            var result = Anagrammer.FindAnagramsInList(word, wordlist).OrderBy(x => x);

            Assert.AreEqual(expectedWordlist, result);
        }
예제 #9
0
        public void PairAlphabetizedWords()
        {
            var wordlist = new List <string>
            {
                "act", "cat", "dog"
            };

            var expectedResult = new List <Tuple <string, string> >
            {
                new Tuple <string, string>("act", "act"),
                new Tuple <string, string>("act", "cat"),
                new Tuple <string, string>("dgo", "dog")
            };

            var result = Anagrammer.PairAlphabeticalCharsWithWords(wordlist);

            Assert.AreEqual(expectedResult, result);
        }
예제 #10
0
        static void Main(string[] args)
        {
            var wordlist = File.ReadAllLines(filepath).ToList();
            var anagrams = Anagrammer.GetListOfAnagrams(wordlist);

            string anagramsOutput = @"anagrams.txt";

            using (StreamWriter sr = new StreamWriter(anagramsOutput))
            {
                foreach (var anagramList in anagrams)
                {
                    foreach (var word in anagramList)
                    {
                        sr.Write(word + ",");
                    }
                    sr.WriteLine();
                }

                File.SetAttributes(anagramsOutput, FileAttributes.Normal);
            }
        }
예제 #11
0
        public void WordsAreAnagramsReturnsExpectedResult(string word1, string word2, bool expectedResult)
        {
            var result = Anagrammer.AreAnagrams(word1, word2);

            Assert.AreEqual(expectedResult, result);
        }
예제 #12
0
        public void AllAnagramPermutationsAreCreated(string testWord, int expectedCount)
        {
            var result = Anagrammer.MakeAnagrams(testWord);

            Assert.AreEqual(expectedCount, result.Count);
        }
예제 #13
0
        public void AllAnagramPermutationsAreCreated(string testWord, string expectedResult)
        {
            var result = Anagrammer.AlphabetizeByChar(testWord);

            Assert.AreEqual(expectedResult, result);
        }