Example #1
0
        public void WhenNullShouldBeEmptyArray()
        {
            var sut = new Anagram();

            var expected = new string[]{};
            var actual = sut.Generate(null);

            Assert.AreEqual(expected, actual);
        }
Example #2
0
        public void WhenTwoLettersShouldBeTwoLetterArray()
        {
            var sut = new Anagram();

            var anonymous = "ab";
            var expected = new string[]{"ab","ba"};
            var actual = sut.Generate(anonymous);

            Assert.AreEqual(expected, actual);
        }
Example #3
0
        public void WhenSingleLetterShouldBeOneMemberArray()
        {
            var sut = new Anagram();

            var anonymous = "a";
            var expected = new string[]{anonymous};
            var actual = sut.Generate(anonymous);

            Assert.AreEqual(expected, actual);
        }
Example #4
0
        public void WhenManyLettersShouldGenerateAnagrams()
        {
            var sut = new Anagram();

            var anonymous = "biro";
            var expected = new string[]{"biro","bior","brio","broi","boir","bori",
                "ibro","ibor","irbo","irob","iobr","iorb",
                "rbio","rboi","ribo","riob","robi","roib",
                "obir","obri","oibr","oirb","orbi","orib"};
            var actual = sut.Generate(anonymous);

            Assert.AreEqual(expected, actual);
        }
Example #5
0
        public static List <string> Of(string s)
        {
            if (s.Length <= 1)
            {
                return new List <string> {
                           s
                }
            }
            ;
            var anagrams = new List <string>();

            for (var i = 0; i < s.Length; i++)
            {
                var droppedCharacter = s.Substring(i, 1);
                var anagramsOfRest   = Anagram.Of(DropCharacter(s, i));
                foreach (var anagramOfRest in anagramsOfRest)
                {
                    anagrams.Add(droppedCharacter + anagramOfRest);
                }
            }
            return(anagrams);
        }