public void interpretNodeTest_simple() { SillyParser p = new SillyParser(null); Assert.AreEqual(p.m(1d), p.InterpretNode("1")); Assert.AreEqual(p.m("a"), p.InterpretNode("a")); Assert.AreEqual(p.m("a"), p.InterpretNode("(a)")); Assert.AreEqual(p.m("sin", 1d), p.InterpretNode("sin(1)")); }
public void interpretListOfNodesTest() { SillyParser p = new SillyParser(null); Assert.AreEqual(p.m("atan2", 1d, 2d), p.InterpretNode("atan2(1, 2)")); Node inner1 = p.m("atan2", 1d, 2d); Node inner2 = p.m("atan2", 3d, 4d); Assert.AreEqual(inner1, p.InterpretNode("atan2(1, 2)")); Assert.AreEqual(inner2, p.InterpretNode("atan2(3, 4)")); Assert.AreEqual(p.m("atan2", inner1, inner2), p.InterpretNode("atan2(atan2(1, 2), atan2(3, 4))")); }
public void interpretNodeTest_multiplyTwoExpressions() { SillyParser p = new SillyParser(null); Node mul = p.m("*", p.m(2d), p.m(1d)); Node atan2 = p.m("atan2", p.m(3d), p.m(4d)); Node add = p.m("+", mul, p.m(5d)); Assert.AreEqual(mul, p.InterpretNode("*(2,1)")); Assert.AreEqual(atan2, p.InterpretNode("atan2(3,4)")); Assert.AreEqual(add, p.InterpretNode("5+atan2(3,4)")); Assert.AreEqual(p.m("+", add, atan2), p.InterpretNode("*(2,1)+5+atan2(3,4)")); }
public void interpretNodeTest_addNegOne() { SillyParser p = new SillyParser(null); Node actual = p.InterpretNode("2+-1"); Assert.AreEqual(p.m("+", 2d, -1d), actual); }
public void interpretNodeTest_multiplyTwoDoubles() { SillyParser p = new SillyParser(null); Node actual = p.InterpretNode("2*-1"); Assert.AreEqual(p.m("*", 2d, -1d), actual); }
public void pemdas() { SillyParser p = new SillyParser(null); Node atan2 = p.m("atan2", 5d, 6d); Node minParen = p.m("-", -1d, 2d); Node sin = p.m("sin", 3d); Node mid = p.m("/", p.m("*", sin, minParen), atan2); Node firstHalf = p.m("+", 2d, mid); Node end1 = p.m("+", firstHalf, 2d); Node end2 = p.m("-", end1, p.m("*", 5d, 7d)); Node whole = p.m("+", end2, 3d); Assert.AreEqual(whole, p.InterpretNode("2+sin(3)*(-1-2)/atan2(5,6)+2-5*7+3")); }