public void ParseMultipleOps_OperatorPrecedence_MulAdd() { var t = new TermParse(); var result = t.Parse("2 * 2 + 4"); Assert.AreEqual(result.Eval(null), 8f); }
public void ParseMultipleOps_Brackets_EvaluatedCorrectly() { var t = new TermParse(); var result = t.Parse("2 * (2 + 4)"); Assert.AreEqual(result.Eval(null), 12f); }
public void ParseJustAString_YieldsVariableLookupNode() { var t = new TermParse(); var result = t.Parse("ThisIsAVariable"); Assert.IsTrue(result is VarRefNode); }
public void ParseNoOperators_YieldsStaticValue() { var t = new TermParse(); var result = t.Parse("11"); Assert.IsTrue(result is StaticValueNode); }
public void ParseAdd_CreatesAdderNode() { var t = new TermParse(); var result = t.Parse("1 + 1"); Assert.IsTrue(result is AddNode); }
static void Main(string[] args) { SetupEnvironment(); TermParse prs = new TermParse(); while (!done) { var cmd = Console.ReadLine(); try { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(">> " + prs.EvalString(cmd, environment)); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine(e.Message); } finally { Console.ForegroundColor = ConsoleColor.Gray; } } }
public void Parse_VarIsEvaluated() { var vt = new SymbolTable(); vt.Register("x", 2.0f); var t = new TermParse(); var result = t.Parse("x * 2"); Assert.AreEqual(result.Eval(vt), 4.0f); }
public void ParseMultipleOps_OperatorPrecedence_AddMul() { var t = new TermParse(); var result = t.Parse("1 + 1 * 4"); Assert.IsTrue(result is AddNode); var n = result as AddNode; Assert.IsTrue(n.Right is MulNode); Assert.AreEqual(result.Eval(null), 5f); }
public void Parse_NestedFuncCall_YieldsFuncCallNode() { var result = new TermParse().Parse("fnord(fark())"); Assert.IsInstanceOfType(result, typeof(FuncCallNode)); }
public void Parse_List_YieldsListNode() { var lst = new TermParse().Parse("{a, 1, 2, 5}"); Assert.IsInstanceOfType(lst, typeof(ListNode)); }
public void Parse_MultipleParameters_YieldsFuncCallNode() { var result = new TermParse().Parse("fnord(1, 3, 5 + foo())"); Assert.IsInstanceOfType(result, typeof(FuncCallNode)); }