public void Setup() { _addResult = CalculatorLib.Add(3, 5); // Calls The CalculatorLib.Add Method with parameters of (3,5) and assigns the output to the _addResult variable. _subtractResult = CalculatorLib.Subtract(8, 8); // Calls The CalculatorLib.Subtract Method with parameters of (8,8) and assigns the output to the _subtractResult variable. _multiplyResult = CalculatorLib.Multiply(9, 2); // Calls The CalculatorLib.Multiply Method with parameters of (9,2) and assigns the output to the _multiplyResult variable. _divideResult = CalculatorLib.Divide(8, 2); // Calls The CalculatorLib.Divide Method with parameters of (8,2) and assigns the output to the _divideResult variable. }
[TestCase(125, 25, 3125)] // |Test Case No. 04.| public void IsMultiplyWorkingWithTestCases(double a, double b, double expected) // This Method Will Be Tested 4 Times; One Time Per Test Case. { double testResult = CalculatorLib.Multiply(a, b); // |Arrange , Assert| Assert.AreEqual(expected, testResult); // |-----Assert-----| }
private void doOperation(char operation, char symbol) { //If there is no current operation, but there exists the result of the previus one, then operate on that. if (inputPanel.Text == "0" && HistoryPanel.Text == "" && ErrorPanel.Text != "") { if (ErrorPanel.Text.Length > 5) { HistoryPanel.Text = $"{ErrorPanel.Text.Substring(ErrorPanel.Text.IndexOf('=') + 1)} {symbol} "; ErrorPanel.Text = ""; ErrorPanel.FontSize = 15; } else { CalculatorLib.opperants.Clear(); CalculatorLib.opperants.Add(double.Parse(ErrorPanel.Text)); HistoryPanel.Text = $"{ErrorPanel.Text.Substring(ErrorPanel.Text.IndexOf('=') + 1)} {symbol} "; ErrorPanel.Text = ""; ErrorPanel.FontSize = 15; } } else { switch (operation) // There are 7 possible Cases All of them Calling the according method from the CalculatorLib Class { case '+': ErrorPanel.Text = CalculatorLib.Add(double.Parse(inputPanel.Text)); break; case '-': ErrorPanel.Text = CalculatorLib.Subtract(double.Parse(inputPanel.Text)); break; case '*': ErrorPanel.Text = CalculatorLib.Multiply(double.Parse(inputPanel.Text)); break; case '/': string evaluationByZeroText = CalculatorLib.Divide(double.Parse(inputPanel.Text)); if (evaluationByZeroText == "01") { ErrorPanel.Text = "I am Sorry, You can Not Divide By 0 :( "; } else { ErrorPanel.Text = evaluationByZeroText; } break; case '%': ErrorPanel.Text = CalculatorLib.Percentage(double.Parse(inputPanel.Text)); break; case 'p': ErrorPanel.Text = CalculatorLib.PowerOfTwo(double.Parse(inputPanel.Text)); break; case 's': ErrorPanel.Text = CalculatorLib.SquareRoot(double.Parse(inputPanel.Text)); break; } if (ErrorPanel.Text != "") { historyList.Items.Add($"{HistoryPanel.Text}{inputPanel.Text} = {ErrorPanel.Text}"); HistoryPanel.Text = ErrorPanel.Text + $" {symbol} "; inputPanel.Text = "0"; } else { if (HistoryPanel.Text == "") { HistoryPanel.Text = inputPanel.Text + $" {symbol} "; inputPanel.Text = "0"; } else { historyList.Items.Add($"{HistoryPanel.Text}{inputPanel.Text} = {ErrorPanel.Text}"); HistoryPanel.Text = inputPanel.Text + $" {symbol} "; inputPanel.Text = "0"; } } } }