Beispiel #1
0
        public void CanAddIntAndDecimal()
        {
            var firstNumber  = 3;
            var secondNumber = 5.5m;

            var result = BasicMath.Addition(firstNumber, secondNumber);

            Assert.AreEqual(result, 8.5m);
        }
Beispiel #2
0
        public void CanAddFloatAndDouble()
        {
            var firstNumber  = 3.3f;
            var secondNumber = 5.5;

            var result = BasicMath.Addition(firstNumber, secondNumber);

            Assert.AreEqual(result, 8.8);
        }
Beispiel #3
0
        public void CanAddIntegers()
        {
            var firstNumber  = 3;
            var secondNumber = 5;

            var result = BasicMath.Addition(firstNumber, secondNumber);

            Assert.AreEqual(result, 8);
        }
 protected void GetAddition()
 {
     // call the getNumbers method and pass
     //it the min, max, and operator
     GetNumbers(0, 100, "+");
     //get the answer from the class
     answer = m.Addition();
     //store it in a session variable
     Session["answer"] = answer;
 }
Beispiel #5
0
 private void BtnEquals_Click(object sender, EventArgs e)
 {
     /*depending on the last button to be clicked perform the correct operation
      * and output the result to the user
      */
     if (!(multiplyButtonClicked && minusButtonClicked &&
           plusButtonClicked && divisionButtonClicked) && CheckForInput(tbResult.Text))
     {
         total = double.Parse(tbResult.Text);
     }
     if (!double.TryParse(tbResult.Text, out double lastInput))
     {
         return;
     }
     if (plusButtonClicked)
     {
         total = BasicMath.Addition(valueHolder, lastInput);
     }
     else if (minusButtonClicked)
     {
         total = BasicMath.Subtraction(valueHolder, lastInput);
     }
     else if (multiplyButtonClicked)
     {
         total = BasicMath.Multiplication(valueHolder, lastInput);
     }
     else if (divisionButtonClicked)
     {
         if (BasicMath.Division(valueHolder, lastInput, out double setTotal))
         {
             total = setTotal;
         }
         else
         {
             MessageBox.Show("Error: Cannot Divide By Zero");
             return;
         }
     }
     //print result
     tbResult.Text = $"{total}";
     //reset calculator
     valueHolder       = 0;
     total             = 0;
     isTotal           = true;
     plusButtonClicked = minusButtonClicked = divisionButtonClicked = multiplyButtonClicked = false;
 }
Beispiel #6
0
        private void BtnPlus_Click(object sender, EventArgs e)
        {
            //if there is input in the textbox add input to valueHolder
            if (CheckForInput(tbResult.Text))
            {
                valueHolder = BasicMath.Addition(valueHolder, double.Parse(tbResult.Text));
                tbResult.Clear();

                plusButtonClicked     = true;
                minusButtonClicked    = false;
                divisionButtonClicked = false;
                multiplyButtonClicked = false;
            }
            else
            {
                MessageBox.Show("Please enter valid input");
            }
        }