示例#1
0
        public void Interpreter_GivenEquationSolve_5_ShouldPass()
        {
            //Arrange
            var text        = "2^(-3)";
            var lexer       = new CalcLexer(text);
            var parser      = new CalcParser(new CalcLexer(text));
            var tree        = parser.Parse();
            var interpreter = new CalcInterpreter();
            //Act
            var result = interpreter.Interpret(tree);

            //Assert
            Assert.AreEqual(0.125, result);
        }
示例#2
0
        public void Interpreter_GivenEquationSolve_3_ShouldPass()
        {
            //Arrange
            var text        = "2^4+9*6/7";
            var lexer       = new CalcLexer(text);
            var parser      = new CalcParser(new CalcLexer(text));
            var tree        = parser.Parse();
            var interpreter = new CalcInterpreter();
            //Act
            var result = interpreter.Interpret(tree);

            //Assert
            Assert.GreaterOrEqual(result, 23.7);
        }
示例#3
0
        public void Interpreter_GivenEquationSolve_13_ShouldPass()
        {
            //Arrange
            var text        = "!((1.3*4 >= 5/2) & (6^2 >= 7^2))";
            var lexer       = new CalcLexer(text);
            var parser      = new CalcParser(new CalcLexer(text));
            var tree        = parser.Parse();
            var interpreter = new CalcInterpreter();
            //Act
            var result = interpreter.Interpret(tree);

            //Assert
            Assert.AreEqual(1, result);
        }
示例#4
0
        public void Interpreter_GivenEquationSolve_1_ShouldPass()
        {
            //Arrange
            var text        = "8.23987456*0.3+9-2+45";
            var lexer       = new CalcLexer(text);
            var parser      = new CalcParser(new CalcLexer(text));
            var tree        = parser.Parse();
            var interpreter = new CalcInterpreter();
            //Act
            var result = interpreter.Interpret(tree);

            //Assert
            Assert.AreEqual(54.471962368, result);
        }
示例#5
0
        public void Interpreter_GivenEquationSolve_6_ShouldPass()
        {
            //Arrange
            var text        = "2^-(4+9*6/7)";
            var lexer       = new CalcLexer(text);
            var parser      = new CalcParser(new CalcLexer(text));
            var tree        = parser.Parse();
            var interpreter = new CalcInterpreter();
            //Act
            var result = interpreter.Interpret(tree);

            //Assert
            Assert.AreEqual(0.0002976107554210143, result);
        }