public void Palindrome_False()
        {
            var s = "madsam".ToCharArray();

            var ret = new StringPalindrome().IsPalindrome(s);

            Assert.AreEqual(false, ret);
        }
        public void Palindrome_True()
        {
            var s = "madam".ToCharArray();

            var ret = new StringPalindrome().IsPalindrome(s);

            Assert.AreEqual(true, ret);
        }
示例#3
0
        public void Can_Instantiate_String_Palindrome_Fails_When_Index_Is_Less_Than_Zero()
        {
            // act & assert
            try
            {
                var palindrome = new StringPalindrome(value: "value", index: -1);

                Assert.Fail("Exception expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentOutOfRangeException));
            }
        }
示例#4
0
        public void Can_Instantiate_String_Palindrome_Fails_When_Value_Is_Null()
        {
            // act & assert
            try
            {
                var palindrome = new StringPalindrome(value: null, index: default(int));

                Assert.Fail("Exception expected");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentNullException));
            }
        }
示例#5
0
        public void Can_Instantiate_String_Palindrome_Successfully()
        {
            // arrange
            const string EXPECTED_VALUE = "value";
            const int    EXPECTED_INDEX = 1;

            // act
            var palindrome = new StringPalindrome(value: EXPECTED_VALUE, index: EXPECTED_INDEX);

            // assert
            Assert.AreEqual(EXPECTED_VALUE, palindrome.Value);
            Assert.AreEqual(EXPECTED_INDEX, palindrome.Index);
            Assert.AreEqual(EXPECTED_VALUE.Length, palindrome.Length);
        }
示例#6
0
        public void DisplayArrayAndString()
        {
            Console.WriteLine("Select Question[1-10]");
            int choice = int.Parse(Console.ReadLine());

            switch (choice)
            {
                #region Max Sub Array Sum Using Kadens Algo
            case 1:
                Console.WriteLine("--------" + choice + ".Max Sub Array Sum Using Kadens Algo--------");
                FindMaxSubArraySumUsingKadensAlgo o1 = new FindMaxSubArraySumUsingKadensAlgo();
                int[] arr1 = { 2, -1, -3, 4, -1, 7, -2 };
                Console.WriteLine(o1.MaxSub(arr1));
                break;
                #endregion

                #region Binary Search
            case 2:
                Console.WriteLine("--------" + choice + ".Binary Search--------");
                BinarySearch o2   = new BinarySearch();
                int[]        arr2 = { 5, 10, 20, 30, 40 };
                Console.WriteLine(o2.BSEarch(arr2, 0, arr2.Length - 1, 40));
                break;
                #endregion

                #region Check Palindrome
            case 3:
                Console.WriteLine("--------" + choice + ".Check Palindrome--------");
                StringPalindrome o3 = new StringPalindrome();
                Console.WriteLine("Enter a String to check Palindrome or not");
                string str3 = Console.ReadLine();
                Console.WriteLine($"{str3} is palindrome {o3.CheckPalindrome(str3)}");
                break;
                #endregion

                #region Bubble Sort
            case 4:
                Console.WriteLine("--------" + choice + ".Bubble Sort--------");
                int[]      arr = { 1, 2, 3, 4 };
                BubbleSort o4  = new BubbleSort(arr, arr.Length);
                break;
                #endregion

                #region Insertion Sort
            case 5:
                Console.WriteLine("--------" + choice + ".Insertion Sort--------");
                var o5 = new InsertionSort(new int[] { 8, 4, 1, 5 });
                break;
                #endregion

                #region Selection sort
            case 6:
                Console.WriteLine("--------" + choice + ".Selection Sort--------");
                var o6 = new SelectionSort(new int[] { 4, 6, 9, 2, 3, 1 });
                break;
                #endregion

                #region Quick Sort
            case 7:
                Console.WriteLine("--------" + choice + ".Quick Sort--------");
                var o7 = new SelectionSort(new int[] { 4, 6, 9, 2, 3, 1 });
                break;
                #endregion

                #region Merge Sort
            case 8:
                Console.WriteLine("--------" + choice + ".Merge Sort--------");
                var o8 = new MergeSort(new int[] { 4, 6, 9, 2, 3, 1 });
                break;
                #endregion

                #region
            case 9:
                Console.WriteLine("--------" + choice + ".String Reverse--------");
                Console.WriteLine($"Test the String Reverse! : { ReverseString.Reverse("Test the String Reverse!")}");
                break;
                #endregion

                #region
            case 10:
                Console.WriteLine("--------" + choice + ".--------");

                break;
                #endregion

            default:
                Console.WriteLine("Oops! Inavalid Choice.");
                break;
            }
        }
示例#7
0
        public static string Process(string input1, string input2, string input3)
        {
            string output = string.Empty;

            switch (input3)
            {
            case "add":
                output = Addition.Add(input1, input2).ToString();
                break;

            case "subtraction":
                output = Subtraction.Sub(input1, input2).ToString();
                break;

            case "multiplication":
                output = Multiplication.Mul(input1, input2).ToString();
                break;

            case "division":
                output = Division.Div(input1, input2).ToString();
                break;

            case "divby3notby6":
                output = Divisionbythreenotbysix.Run(input1).ToString();
                break;

            case "armstrongornot":
                output = Armstrongnumber.Check(input1).ToString();
                break;

            case "factorial":
                output = Factorial.Calculate(input1).ToString();
                break;

            case "palindrome":
                output = PalindromeNumber.Find(input1).ToString();
                break;

            case "reverse":
                output = ReverseNumber.Reverse(input1).ToString();
                break;

            case "sumofdigits":
                output = Sumofdigits.Find(input1).ToString();
                break;

            case "decimaltobinary":
                output = DecimaltoBinary.Converts(input1).ToString();
                break;

            case "numberincharacter":
                output = NumbersInCharacters.Print(input1).ToString();
                break;

            case "strreverse":
                output = StringReverse.Reverse(input1).ToString();
                break;

            case "duplicate":
                output = DuplicateElement.Find(input1).ToString();
                break;

            case "unique":
                output = UniqueElement.Return(input1).ToString();
                break;

            case "strpalindrome":
                output = StringPalindrome.Find(input1).ToString();
                break;

            case "length":
                output = StringLength.Calculate(input1).ToString();
                break;

            case "vowels":
                output = NumofVowels.Print(input1).ToString();
                break;

            case "search":
                output = CharacterSearching.Search(input1, input2).ToString();
                break;

            case "count":
                output = WordCount.Count(input1).ToString();
                break;

            case "date":
                output = DateandTime.Calculate(input1).ToString();
                break;
            }
            return(output);
        }