public void EvaluateTests(string expression, int expectedResult)
        {
            var divExpression = new DivExpression();

            int result = divExpression.Evaluate(expression);

            Assert.That(result, Is.EqualTo(expectedResult));
        }
Esempio n. 2
0
        public void RaiseIfDivideRealByInteger()
        {
            DivExpression expr = new DivExpression(new ConstantExpression(6.5), new ConstantExpression(2));

            try
            {
                expr.Evaluate(null);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidCastException));
            }
        }
Esempio n. 3
0
        public void RaiseIfDivideRealByInteger()
        {
            DivExpression expr = new DivExpression(new ConstantExpression(6.5), new ConstantExpression(2));

            try
            {
                expr.Evaluate(null);
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(InvalidCastException));
            }
        }
Esempio n. 4
0
        public void DivideTwoIntegersWithTruncation()
        {
            DivExpression expr = new DivExpression(new ConstantExpression(5), new ConstantExpression(2));

            Assert.AreEqual(2, expr.Evaluate(null));
        }
Esempio n. 5
0
        public void DivideTwoIntegers()
        {
            DivExpression expr = new DivExpression(new ConstantExpression(6), new ConstantExpression(2));

            Assert.AreEqual(3, expr.Evaluate(null));
        }
Esempio n. 6
0
        public void DivideTwoIntegersWithTruncation()
        {
            DivExpression expr = new DivExpression(new ConstantExpression(5), new ConstantExpression(2));

            Assert.AreEqual(2, expr.Evaluate(null));
        }
Esempio n. 7
0
        public void DivideTwoIntegers()
        {
            DivExpression expr = new DivExpression(new ConstantExpression(6), new ConstantExpression(2));

            Assert.AreEqual(3, expr.Evaluate(null));
        }
        public void EvaluateDivideByZero()
        {
            var divExpression = new DivExpression();

            Assert.Throws(typeof(DivideByZeroException), () => divExpression.Evaluate("div(1,0)"));
        }
        public void ErrorEvaluateTests(string expression)
        {
            var divExpression = new DivExpression();

            Assert.Throws(typeof(ArithmeticException), () => divExpression.Evaluate(expression));
        }