assertEquals(evaluated, N.create(3));
}
@Test(dependsOnMethods = { "testExponentiation" })
public void testSum() {
ExpressionParser parser = new ExpressionParser();
Expression sum = parser.parse("45/2 + 3/2 * sqrt(249) + 15/8 * sqrt(249) + 237/8 + 1");
Expression evaluated = sum.evaluate();
System.out.printf("%s = %s%n", sum, evaluated);
Expression expected = parser.parse("(27sqrt(249) + 425) / 8");
assertEquals(evaluated, expected);
Variable x = Numbers.variable("x");
x.setValue(parser.parse("(15 + sqrt(249)) / 4"));
ExpressionContext.getInstance().addVariable(x);
Expression quadratic = parser.parse("x^2 - 6x + 1");
evaluated = quadratic.evaluate();
System.out.printf("%s (%s = %s) = %s%n", quadratic, x.name(), x.evaluate(), evaluated);
expected = parser.parse("(3 sqrt(249) + 65) / 8");
assertEquals(evaluated, expected);
}