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 GetNthFib_Should_ReturnOne_When_GivenTwoAsInput() { //arrange var input = 2; //act var result = NthFibonacci.GetNthFib(input); //assert Assert.That(result, Is.EqualTo(1)); }
public void NthFibonacciTests() { //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; //TODO check all test comments to ensure they are accurate if (PassCondition == true) {//Proper test for nth Fibonacci Assert.Equal(3, NthFibonacci.GetNthFib(4)); } else { //to set inital test to false Assert.Equal(1, 2); } }
public static int Run(int n, IConsole console) { try { // Execute var result = NthFibonacci.Fibonacci(n); // Display result console.Out.WriteLine($"Result: { result }"); return(0); } catch (ArgumentException) { console.Error.WriteLine($"Error: { nameof(n) } must at least zero"); return(1); } }
public static int Run(int from, int to, IConsole console) { if (from < 0 || to < 0) { console.Error.WriteLine($"Error: { nameof(from) } and { nameof(to) } must be at least 0"); return(1); } // Display result console.Out.Write($"Result: "); int result; if (from < to) { while (from <= to) { // Execute result = NthFibonacci.FibonacciIterative(from); // Display result console.Out.Write($"{ result } "); from++; } } else { while (from >= to) { result = NthFibonacci.FibonacciIterative(from); console.Out.Write($"{ result } "); from--; } } console.Out.WriteLine(); return(0); }
public void FibonacciIterative_WhenNLessThanZero_ThrowsArgumentException() { Action actual = () => NthFibonacci.FibonacciIterative(-1); Assert.Throws <ArgumentException>(actual); }
public void FibonacciIterative_WhenNGreaterThanZero_ReturnsValidResult(int n, int expected) { var actual = NthFibonacci.FibonacciIterative(n); Assert.Equal(expected, actual); }