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); }
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); }
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); }
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); }
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); }