Пример #1
0
        /// <summary>
        /// Does the math operation.
        /// </summary>
        private void do_math_operation()
        {
            /// <sumamry> Variable lastOperator stores last operation which will be performed </summary>
            switch (lastOperator)
            {
            case "+":
                operand1 = Math.Add(operand1, dispString_to_numb(display.Text));
                break;

            case "-":
                operand1 = Math.Add(operand1, -(dispString_to_numb(display.Text)));
                break;

            case "*":
                operand1 = Math.Mul(operand1, dispString_to_numb(display.Text));
                break;

            case "/":
                operand1 = Math.Div(operand1, dispString_to_numb(display.Text));
                break;

            case "power":
                operand1 = Math.Pow(operand1, dispString_to_numb(display.Text));
                break;

            case "root":
                operand1 = Math.Root(operand1, dispString_to_numb(display.Text));
                break;

            case "log":
                operand1 = Math.Log(dispString_to_numb(display.Text), operand1);
                break;

            default:
                break;
            }
        }
Пример #2
0
        public void DivTest()
        {
            Assert.AreEqual(0, math.Div(0, 5));
            Assert.AreEqual(1, math.Div(10, 10));
            Assert.AreEqual(1, math.Div(-10, -10));
            Assert.AreEqual(-1, math.Div(-10, 10));
            Assert.AreEqual(-1, math.Div(10, -10));
            Assert.AreEqual(-5, math.Div(-100000000, 20000000));
            Assert.AreEqual(0.5, math.Div(1, 2), Exactness);
            Assert.AreEqual(-0.625, math.Div(-5, 8), Exactness);
            Assert.AreEqual(0.5, math.Div(128, 256));
            Assert.AreEqual(6.4127039, math.Div(42.6541, 6.6515), Exactness);
            Assert.AreEqual(4, math.Div(1, 0.25), Exactness);


            /// <summary> divided by zero</summary>
            string noFailMessage = "No exception message after dividing by zero.";

            try
            {
                math.Div(2, 0);
                Assert.Fail(noFailMessage);
            }
            catch (Exception)
            {
            }
        }