public void Setup() { _sw = new Stopwatch(); _runtime = new MoLangRuntime(); _runtime.Environment.Structs.TryAdd("query", new InteropStruct(new TestClass(_sw)) { }); }
private MoLangRuntime Setup(double a, double b) { MoLangRuntime runtime = new MoLangRuntime(); runtime.Environment.Structs["variable"] = new VariableStruct( new List <KeyValuePair <string, IMoValue> >() { new KeyValuePair <string, IMoValue>("a", new DoubleValue(a)), new KeyValuePair <string, IMoValue>("b", new DoubleValue(b)) }); return(runtime); }
public void PropertyWrite() { var expression = MoLangParser.Parse("query.life_time = 5"); MoLangRuntime runtime = new MoLangRuntime(); var testStruct = new TestClass(Environment.TickCount); runtime.Environment.Structs.TryAdd( "query", new InteropStruct(testStruct)); runtime.Execute(expression); Assert.AreEqual(5d, testStruct.Lifetime); }
public void PropertyRead() { var expression = MoLangParser.Parse("query.life_time"); var expected = Environment.TickCount * 3.5d; MoLangRuntime runtime = new MoLangRuntime(); runtime.Environment.Structs.TryAdd( "query", new InteropStruct(new TestClass(expected))); var result = runtime.Execute(expression); Assert.AreEqual(expected, result.AsDouble()); }
public void MathFunctions() { MoLangParser parser = new MoLangParser(new TokenIterator("math.floor(10.1 + 20.1)")); parser.ExpressionTraverser.Visitors.Add(new MathOptimizationVisitor()); var expr = parser.Parse(); Assert.IsInstanceOfType(expr, typeof(NumberExpression)); MoLangRuntime runtime = new MoLangRuntime(); var result = runtime.Execute(expr); Assert.AreEqual(30, result.AsDouble()); }
public void Constants() { MoLangParser parser = new MoLangParser(new TokenIterator("7 + 2 * (6 + 3) / 3 - 7")); parser.ExpressionTraverser.Visitors.Add(new MathOptimizationVisitor()); var expr = parser.Parse(); Assert.IsInstanceOfType(expr, typeof(NumberExpression)); MoLangRuntime runtime = new MoLangRuntime(); var result = runtime.Execute(expr); Assert.AreEqual(6, result.AsDouble()); }
public void Setup() { _runtime = new MoLangRuntime(); }