Beispiel #1
0
        public void DivExprTest(double firstInput, double secondInput, double expected)
        {
            Expression expr1;
            Expression expr2;

            if (firstInput < 0)
            {
                Expression expr = new TerminalExpression(Math.Abs(firstInput));
                expr1 = new NegativeExpression(expr);
            }
            else
            {
                expr1 = new TerminalExpression(firstInput);
            }

            if (secondInput < 0)
            {
                Expression expr = new TerminalExpression(Math.Abs(secondInput));
                expr2 = new NegativeExpression(expr);
            }
            else
            {
                expr2 = new TerminalExpression(secondInput);
            }

            Expression exprResult = new DivExpression(expr1, expr2);

            Assert.Equal(expected, exprResult.Solve(), 5);
        }
Beispiel #2
0
        public void NegativeExprTest(double expected, double action)
        {
            Expression         expr    = new TerminalExpression(action);
            NegativeExpression negExpr = new NegativeExpression(expr);

            Assert.Equal(expected, negExpr.Solve(), 5);
        }
Beispiel #3
0
        public void AddExprTest(double firstInput, double secondInput, double expected)
        {
            Expression expr1      = new TerminalExpression(firstInput);
            Expression expr2      = new TerminalExpression(secondInput);
            Expression exprResult = new AddExpression(expr1, expr2);

            Assert.Equal(expected, exprResult.Solve(), 5);
        }
Beispiel #4
0
        public void RootExprTest(double firstInput, double expected)
        {
            Expression expr = new TerminalExpression(firstInput);

            Expression exprResult = new RootExpression(expr);

            Assert.Equal(expected, exprResult.Solve(), 5);
        }
Beispiel #5
0
        public void SubstractExprTest(double firstInput, double secondInput, double expected)
        {
            Expression expr1 = new TerminalExpression(firstInput);
            Expression expr2 = new TerminalExpression(secondInput);

            NegativeExpression negExpr = new NegativeExpression(expr2);

            Expression exprResult = new AddExpression(expr1, negExpr);

            Assert.Equal(expected, exprResult.Solve(), 5);
        }
Beispiel #6
0
        public void TerminalExprTest(double expected, double action)
        {
            Expression expr = new TerminalExpression(action);

            Assert.Equal(expected, expr.Solve(), 5);
        }