Example #1
0
        private void SubmitButton_Click(object sender, EventArgs e)
        {
            if (ValidateData())
            {
                if (currentSelection == "Find three largest numbers in array")
                {
                    int[] array = Array.ConvertAll(UserInputBox.Text.Split(','), int.Parse);
                    AnswerTxtBox.Text = string.Join(",", FindThreeLargestNumbers.FIndTheThreeLargestNum(array));
                }
                else if (currentSelection == "Move elements in array to end")
                {
                    List <int> listOfNums = UserInputBox.Text.Split(',').Select(Int32.Parse).ToList();
                    int        intToMove  = Int32.Parse(AdditionalInputTxtBox.Text);
                    AnswerTxtBox.Text = string.Join("", ElementsToEnd.MoveElementToEnd(listOfNums, intToMove));
                }
                else if (currentSelection == "Palindrome validator")
                {
                    AnswerTxtBox.Text = PalindromeChecker.IsPalindrome(UserInputBox.Text.ToLower()).ToString();
                }
                else if (currentSelection == "Sub sequence validator")
                {
                    List <int> array           = UserInputBox.Text.Split(',').Select(Int32.Parse).ToList();
                    List <int> potentialSubSeq = AdditionalInputTxtBox.Text.Split(',').Select(Int32.Parse).ToList();

                    AnswerTxtBox.Text = SubsetChecker.IsValidSubsequence(array, potentialSubSeq).ToString();
                }
                else if (currentSelection == "Nth Fibonacci")
                {
                    int num = Int32.Parse(UserInputBox.Text);
                    AnswerTxtBox.Text = NthFibonacci.GetNthFib(num).ToString();
                }
            }
        }
        public void SubsetChecktest()
        {
            //boolean to set test conditions
            //dedault is set to false to create fail condition for test.
            //once fail condition is set, change boolean to true to test
            bool PassCondition = false;

            if (PassCondition == true)
            {//Passing test
                List <int> array = new List <int> {
                    -3, -2, -1, 0, 1, 2, 3,
                };

                List <int> subset = new List <int> {
                    -2, 0, 2, 3
                };

                bool expected = true;

                Assert.Equal(expected, SubsetChecker.IsValidSubsequence(array, subset));
            }
            else
            {//inital fail test to set test to fail condition
                List <int> array = new List <int> {
                    -3, -2, -1, 0, 1, 2, 3,
                };

                List <int> subset = new List <int> {
                    -2, -3, 1, 0, 2
                };

                bool expected = true;

                Assert.Equal(expected, SubsetChecker.IsValidSubsequence(array, subset));
            }
        }