public static string StringVariantToInvariant(Worksheet worksheet, string variantString) { if (worksheet == null) { return(variantString); } bool flag = worksheet.ReferenceStyle == ReferenceStyle.A1; string str = variantString; bool flag2 = (str != null) && str.StartsWith("="); try { CalcParser parser = new CalcParser(); CalcExpression expr = parser.Parse(variantString, new SpreadCalcParserContext(worksheet, !flag, 0, 0, CultureInfo.CurrentCulture)); str = parser.Unparse(expr, new SpreadCalcParserContext(worksheet, !flag, 0, 0, CultureInfo.InvariantCulture)); if (flag2) { variantString = "=" + variantString; } } catch { } return(str); }
public void Interpreter_GivenEquationSolve_7_ShouldFail() { //Arrange var text = "2^-(4+9*6/7)a"; var lexer = new CalcLexer(text); var parser = new CalcParser(new CalcLexer(text)); //Act //Assert Assert.Throws <Exception>(() => parser.Parse()); }
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_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_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_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); }