예제 #1
0
        public static void LongTest(int maxStringLength = 300, int diffCharCount = 5, int testsPerLength = 200)
        {
            char[] alpha = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
            Random rand  = new Random();

            for (int testStringLenNr = 0; testStringLenNr < testsPerLength; testStringLenNr++)
            {
                int testStringLength = rand.Next() % (maxStringLength + 1);

                for (int test = 0; test < testsPerLength; test++)
                {
                    char[] testStringAr = new char[testStringLength];
                    for (int j = 0; j < testStringLength; j++)
                    {
                        testStringAr[j] = alpha[rand.Next() % diffCharCount];
                    }

                    var testString = new string(testStringAr);
                    var palindrome = LargestPalindromeFinder.FindLargestPalindrome(testString);

                    var expectedPalindrome = FindLargestPalindrome(testString);
                    var l1 = palindrome.Length;
                    var l2 = expectedPalindrome.Length;
                    if (palindrome != expectedPalindrome)
                    {
                        throw new Exception("Long test failed");
                    }
                }
            }
        }
예제 #2
0
        public static void BasicTest()
        {
            var str1   = "ABCDEFCBA";
            var result = LargestPalindromeFinder.FindLargestPalindrome(str1);

            if (result.Length > 1)
            {
                throw new Exception("Basic test failed");
            }

            var str2 = "acdabacdc";

            if (LargestPalindromeFinder.FindLargestPalindrome(str2) != "aba")
            {
                throw new Exception("Basic test failed");
            }
        }