コード例 #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();
                }
            }
        }
コード例 #2
0
        public void ElementsToEndTests()
        {
            //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 = true;

            if (PassCondition == true)
            {//Passing Test
                List <int> array = new List <int> {
                    1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8, 7
                };

                int numToMove = 7;

                List <int> expectedStart = new List <int> {
                    1, 2, 3, 4, 5, 6, 8
                };
                List <int> expectedEnd = new List <int> {
                    7, 7, 7, 7, 7, 7, 7, 7, 7
                };

                List <int> testingOutput = ElementsToEnd.MoveElementToEnd(array, numToMove);



                //test to see if the start of the list array is the same
                List <int> actualStart = testingOutput.GetRange(0, 7);
                actualStart.Sort();
                Assert.Equal(expectedStart, actualStart);

                //Test to see if the number meant to move has infact moved to the end
                List <int> actualEnd = testingOutput.GetRange(7, testingOutput.Count - 7);
                Assert.Equal(expectedEnd, actualEnd);
            }
            else
            {//to set inital test to false
                bool expected = true;
                bool actual   = false;

                Assert.Equal(expected, actual);
            }
        }