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

            int result = divExpression.Evaluate(expression);

            Assert.That(result, Is.EqualTo(expectedResult));
        }
예제 #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));
            }
        }
예제 #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));
            }
        }
예제 #4
0
        public void DivideTwoIntegersWithTruncation()
        {
            DivExpression expr = new DivExpression(new ConstantExpression(5), new ConstantExpression(2));

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

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

            Assert.AreEqual(2, expr.Evaluate(null));
        }
예제 #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));
        }