public void TestNonUniquePalindromes()
        {
            string s   = "aaa";
            var    res = LongestUniquePalindromesFinder.GetLongestUniquePalindromes(numberOfPalindromes, s);
            LongestUniquePalindromes expected = new LongestUniquePalindromes();

            expected.Add(new PalindromeData(0, 3, "aaa"));
            expected.Add(new PalindromeData(0, 0, string.Empty));
            Assert.Equal(expected.ToString(), res.ToString());
        }
        public void TestPalindromeContainingExactlyKPalindromes()
        {
            string s   = "aaabbbbcc";
            var    res = LongestUniquePalindromesFinder.GetLongestUniquePalindromes(numberOfPalindromes, s);
            LongestUniquePalindromes expected = new LongestUniquePalindromes();

            expected.Add(new PalindromeData(3, 4, "bbbb"));
            expected.Add(new PalindromeData(0, 3, "aaa"));
            expected.Add(new PalindromeData(7, 2, "cc"));

            Assert.Equal(expected.ToString(), res.ToString());
        }
        public void TestOnlyCharactersPalindromeContainingLessThanKPalindromes()
        {
            string s   = "ab";
            var    res = LongestUniquePalindromesFinder.GetLongestUniquePalindromes(numberOfPalindromes, s);
            LongestUniquePalindromes expected = new LongestUniquePalindromes();

            expected.Add(new PalindromeData(0, 1, "a"));
            expected.Add(new PalindromeData(1, 1, "b"));
            expected.Add(new PalindromeData(0, 0, string.Empty));

            Assert.Equal(expected.ToString(), res.ToString());
        }
        public void TestPalindromeFromSpecification()
        {
            string s   = "sqrrqabccbatudefggfedvwhijkllkjihxymnnmzpop";
            var    res = LongestUniquePalindromesFinder.GetLongestUniquePalindromes(numberOfPalindromes, s);
            LongestUniquePalindromes expected = new LongestUniquePalindromes();

            expected.Add(new PalindromeData(23, 10, "hijkllkjih"));
            expected.Add(new PalindromeData(13, 8, "defggfed"));
            expected.Add(new PalindromeData(5, 6, "abccba"));

            Assert.Equal(expected.ToString(), res.ToString());
        }
        public void TestPalindromeLongestButNotUnique()
        {
            string s   = "abcba4bcb";
            var    res = LongestUniquePalindromesFinder.GetLongestUniquePalindromes(numberOfPalindromes, s);
            LongestUniquePalindromes expected = new LongestUniquePalindromes();

            expected.Add(new PalindromeData(0, 5, "abcba"));
            expected.Add(new PalindromeData(5, 1, "4"));
            expected.Add(new PalindromeData(0, 0, string.Empty));

            Assert.Equal(expected.ToString(), res.ToString());
        }
Example #6
0
        public void TestLongestPalindromeUniqueTrue()
        {
            PalindromeData p1 = new PalindromeData(0, 2, "aa");
            PalindromeData p2 = new PalindromeData(2, 2, "bb");

            LongestUniquePalindromes l = new LongestUniquePalindromes();

            l.Add(p1);
            l.Add(p2);

            PalindromeData candidate = new PalindromeData(1, 2, "cc");
            bool           expected  = l.Contains(candidate);

            Assert.False(expected);
        }
        public void TestOnlyCharactersPalindromeContainingMoreThanKPalindromes()
        {
            string s   = "abcd";
            var    res = LongestUniquePalindromesFinder.GetLongestUniquePalindromes(numberOfPalindromes, s);
            LongestUniquePalindromes expected1 = new LongestUniquePalindromes();

            expected1.Add(new PalindromeData(0, 1, "a"));
            expected1.Add(new PalindromeData(1, 1, "b"));
            expected1.Add(new PalindromeData(2, 1, "c"));

            Assert.Equal(expected1.ToString(), res.ToString());

            //NOTE: this is not the only solution ( "a", "b", "d") or ("b", "c", "d") are also valid
            //if the implmentation changes, this test may fail.
            //TO DO: add to the test all sets of longest unique palindromes.
        }
        public void TestPalindromeContainingMoreThanKPalindromes()
        {
            string s   = "aaaabbbbbbcccddd";
            var    res = LongestUniquePalindromesFinder.GetLongestUniquePalindromes(numberOfPalindromes, s);

            LongestUniquePalindromes expected1 = new LongestUniquePalindromes();

            expected1.Add(new PalindromeData(4, 6, "bbbbbb"));
            expected1.Add(new PalindromeData(0, 4, "aaaa"));
            expected1.Add(new PalindromeData(10, 3, "ccc"));

            Assert.Equal(expected1.ToString(), res.ToString());

            //NOTE: this is not the only solution.
            //if the implmentation changes, this test may fail.
            //TO DO: add to the test all sets of longest unique palindromes.
        }
Example #9
0
        public void TestLongestPalindromeIntervalContainsTrue()
        {
            PalindromeData           p = new PalindromeData(0, 3, "abba");
            LongestUniquePalindromes l = new LongestUniquePalindromes();

            l.Add(p);
            PalindromeData candidate = new PalindromeData(1, 2, "bb");
            bool           expected  = l.IntervalContains(candidate);

            Assert.True(expected);
        }
Example #10
0
        public void TestLongestPalindromeIntervalContainsFalse()
        {
            PalindromeData           p = new PalindromeData(0, 3, "abcbacc");
            LongestUniquePalindromes l = new LongestUniquePalindromes();

            l.Add(p);
            PalindromeData candidate = new PalindromeData(4, 3, "ada");
            bool           expected  = l.IntervalContains(candidate);

            Assert.False(expected);
        }