Esempio n. 1
0
 public void TestCsSubtraction()
 {
     Calculator calc = new Calculator();
       calc.Number1 = 10;
       calc.Number2 = 10;
       double answer = calc.Subtract();
       //Ensure that 10-10=0
       Assert.AreEqual(answer, 0d);
 }
Esempio n. 2
0
 public void TestCsMultiplication()
 {
     Calculator calc = new Calculator();
       calc.Number1 = 10;
       calc.Number2 = 10;
       double answer = calc.Multiply();
       //Ensure that 10*10=100
       Assert.AreEqual(answer, 100d);
 }
Esempio n. 3
0
 public void TestCsDivision()
 {
     Calculator calc = new Calculator();
       calc.Number1 = 10;
       calc.Number2 = 10;
       double answer = calc.Divide();
       //Ensure that 10/10=1
       Assert.AreEqual(answer, 1d);
 }
Esempio n. 4
0
 public void TestCsAddition()
 {
     Calculator calc = new Calculator();
       calc.Number1 = 10;
       calc.Number2 = 10;
       double answer = calc.Add();
       //Ensure that 10+10=20
       Assert.AreEqual(answer, 20d);
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            //Get the input values from the console, and initiaze the answer to zero
              double num1 = 0;
              Console.WriteLine("Enter the value for Number 1:");
              double.TryParse(Console.ReadLine(), out num1);
              double num2 = 0;
              Console.WriteLine("Enter the value for Number 2:");
              double.TryParse(Console.ReadLine(), out num2);
              string op = "";
              Console.WriteLine("Enter the Operator (+,-,*,/):");
              op = Console.ReadLine();
              double answer = 0;

              //Instantiate a calculator instance, and supply the values for the operands
              Calculator calc = new Calculator();
              calc.Number1 = num1;
              calc.Number2 = num2;

              //Depending on which operator the user selected, call the approparite calculator method.
              //Store the result int the answer variable
              switch (op)
              {
            case "+":
              answer = calc.Add();
              break;
            case "-":
              answer = calc.Subtract();
              break;
            case "*":
              answer = calc.Multiply();
              break;
            case "/":
              answer = calc.Divide();
              break;
              }

              //Show the answer
              Console.WriteLine("{0} {1} {2} = {3}{4}{4}Press [ENTER] to continue...", num1, op, num2, answer, System.Environment.NewLine);
              Console.ReadLine();
        }
Esempio n. 6
0
        protected void CalculateButton_Click(object sender, EventArgs e)
        {
            //Get the input values from the form, and initiaze the answer to zero
              double num1 = 0;
              double.TryParse(Number1TextBox.Text, out num1);
              double num2 = 0;
              double.TryParse(Number2TextBox.Text, out num2);
              string op = OperatorComboBox.SelectedItem.ToString();
              double answer = 0;

              //Instantiate a calculator instance, and supply the values for the operands
              Calculator calc = new Calculator();
              calc.Number1 = num1;
              calc.Number2 = num2;

              //Depending on which operator the user selected, call the approparite calculator method.
              //Store the result int the answer variable
              switch (op)
              {
            case "+":
              answer = calc.Add();
              break;
            case "-":
              answer = calc.Subtract();
              break;
            case "*":
              answer = calc.Multiply();
              break;
            case "/":
              answer = calc.Divide();
              break;
              }

              //Show the answer
              AnswerTextBox.Text = answer.ToString();
        }