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, 5)] // |Test Case No. 04.| public void IsDivideWorkingWithTestCases(double a, double b, double expected) // This Method Will Be Tested 4 Times; One Time Per Test Case. { double testResult = CalculatorLib.Divide(a, b); // |Arrange , Assert| Assert.AreEqual(expected, testResult); // |-----Assert-----| Assert.Throws <System.DivideByZeroException>(() => CalculatorLib.Divide(3, 0)); }
//Takes The Doubled Clicked Item From The History And Allow it To do Further Operations On its Result. private void OnListClick(object sender, MouseButtonEventArgs e) { var item = (sender as ListBox).SelectedItem; if (item != null) { inputPanel.Text = "0"; HistoryPanel.Text = ""; ErrorPanel.Text = item.ToString().Substring(item.ToString().IndexOf(':') + 1); CalculatorLib.opperants.Clear(); double papas = double.Parse(ErrorPanel.Text.Substring(ErrorPanel.Text.IndexOf('=') + 1)); CalculatorLib.Add(papas); } }
[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"; } } } }
public void MainSetUp() { _calc = new CalculatorLib(); }
// Brackers To Be Implemented //private void Brackets_Click(object sender, RoutedEventArgs e) // checking if there are previuse open brackers if there are then add a closing bracket else add an opening bracket //{ // var counter = 0; // foreach (char x in inputPanel.Text) // { // if (x == '(') // { // counter = 1; // } // else if (x == ')') { counter = 0; } // } // if (counter == 0) // { // inputPanel.Text += " ( "; // } // else inputPanel.Text += " ) "; //} // Method For The = Button. One Of the Mains. private void Equals_Click(object sender, RoutedEventArgs e) { //First It Checkes If the history panel is empty if (HistoryPanel.Text == "") { return; // If it is, It can not compate it; Thus, It returns and continues to the rest of the method. } //If It is not Empty Then It proceeds With The Operation. char x = HistoryPanel.Text[HistoryPanel.Text.Length - 2]; // It Checs For A sign In Order to do the correct opperation. switch (x) // Possible Cases For This Swich are 1: '+', 2: '-', 3: '*', 4: '/' { //In case x = '+' case '+': if (ErrorPanel.Text == "") //If The Output panel = null { ErrorPanel.FontSize = 30; // Sets The Font Of the Output Panel to 30px string s = HistoryPanel.Text.Replace(" + ", ""); // The historyPanel.Text would be "x + " And we transform it to "x" ErrorPanel.Text = CalculatorLib.Add(double.Parse(s), double.Parse(inputPanel.Text)).ToString(); // Calls The Addition method From The CalculatorLib Class to perform the Addition. historyList.Items.Add($"{HistoryPanel.Text}{inputPanel.Text} = {ErrorPanel.Text}"); // Adds The Operation to the History List //Resets The fields to their default inputPanel.Text = "0"; HistoryPanel.Text = ""; //Resets The Opperants List CalculatorLib.opperants.Clear(); } else { ErrorPanel.FontSize = 30; // Sets The Font Of the Output Panel to 30px ErrorPanel.Text = CalculatorLib.Add(double.Parse(ErrorPanel.Text), double.Parse(inputPanel.Text)).ToString(); // Calls The Addition method From The CalculatorLib Class to perform the Addition. //Resets The fields to their default inputPanel.Text = "0"; HistoryPanel.Text = ""; //Resets The Opperants List CalculatorLib.opperants.Clear(); } break; case '-': if (ErrorPanel.Text == "") { ErrorPanel.FontSize = 30; string s = HistoryPanel.Text.Replace(" - ", ""); ErrorPanel.Text = (Math.Round(double.Parse(s) - double.Parse(inputPanel.Text))).ToString(); historyList.Items.Add($"{HistoryPanel.Text}{inputPanel.Text} = {ErrorPanel.Text}"); inputPanel.Text = "0"; HistoryPanel.Text = ""; CalculatorLib.opperants.Clear(); } else { ErrorPanel.FontSize = 30; ErrorPanel.Text = (double.Parse(ErrorPanel.Text) - double.Parse(inputPanel.Text)).ToString(); inputPanel.Text = "0"; HistoryPanel.Text = ""; CalculatorLib.opperants.Clear(); } break; case '*': if (ErrorPanel.Text == "") { ErrorPanel.FontSize = 30; string s = HistoryPanel.Text.Replace(" * ", ""); ErrorPanel.Text = (Math.Round(double.Parse(s) * double.Parse(inputPanel.Text))).ToString(); historyList.Items.Add($"{HistoryPanel.Text}{inputPanel.Text} = {ErrorPanel.Text}"); inputPanel.Text = "0"; HistoryPanel.Text = ""; CalculatorLib.opperants.Clear(); } else { ErrorPanel.FontSize = 30; ErrorPanel.Text = (double.Parse(ErrorPanel.Text) * double.Parse(inputPanel.Text)).ToString(); inputPanel.Text = "0"; HistoryPanel.Text = ""; CalculatorLib.opperants.Clear(); } break; case '/': if (inputPanel.Text == "0") { ErrorPanel.Text = "I am Sorry, You can not divide by 0 :("; } else { if (ErrorPanel.Text == "") { ErrorPanel.FontSize = 30; string s = HistoryPanel.Text.Replace(" / ", ""); ErrorPanel.Text = (double.Parse(s) / double.Parse(inputPanel.Text)).ToString(); historyList.Items.Add($"{HistoryPanel.Text}{inputPanel.Text} = {ErrorPanel.Text}"); inputPanel.Text = "0"; HistoryPanel.Text = ""; CalculatorLib.opperants.Clear(); } else { ErrorPanel.FontSize = 30; ErrorPanel.Text = (double.Parse(ErrorPanel.Text) / double.Parse(inputPanel.Text)).ToString(); inputPanel.Text = "0"; HistoryPanel.Text = ""; CalculatorLib.opperants.Clear(); } } break; default: break; } }
public void Substract_DivideZero() { Assert.AreEqual(0, CalculatorLib.Division(15, 0)); }
public void Substract_HappyPath() { Assert.AreEqual(3, CalculatorLib.Substract(15, 10)); Assert.AreEqual(3, CalculatorLib.Substract(15, 10)); }
public void Multiplication_HappyPath() { Assert.AreEqual(75, CalculatorLib.Multiplication(15, 5)); Assert.AreEqual(45, CalculatorLib.Multiplication(15, 3)); Assert.AreEqual(90, CalculatorLib.Multiplication(15, 6)); }
public void Sum_HappyPath() { Assert.AreEqual(10, CalculatorLib.Substract(15, 5)); }
public void Add_HappyPath() { Assert.AreEqual(20, CalculatorLib.Sum(15, 5)); }