public void When_Brackets_Expect_Reference() { var parser = new SimpleParser(); Check(1 - (5.8 - 12) - 3, parser.Parse("1 - (5.8 - 12) - 3")); Check(2 * (2 + 3) * 4, parser.Parse("2 * ((2 + 3)) * 4")); }
public void When_NotEqual_Expect_Reference() { var parser = new SimpleParser(); Check(1, parser.Parse("3 != 5 ? 1 : 2")); Check(2, parser.Parse("3 != 3 ? 1 : 2")); }
public void When_Conditional_Expect_Reference() { var parser = new SimpleParser(); Check(1, parser.Parse("1 >= 0 ? 1 : 2")); Check(2, parser.Parse("1 >= 3 ? 1 : 2")); }
public void When_NotEqual_With_NonZeroTolerance_Expect_Reference() { var parser = new SimpleParser(); parser.EqualityTolerance = 0.1; Check(1, parser.Parse("3 != 4.05 ? 1 : 2")); Check(2, parser.Parse("3 != 3.05 ? 1 : 2")); }
public void FuncCalls2() { var e = SimpleParser.Parse("AVG(1,2,3,4,5,5,6,7,8,9,)"); var f = e.Compile <Func <double> >(); Assert.IsTrue(f() == 5); }
private void Demo1() { ParseResult e; // f(x, y) = x + y e = SimpleParser.Parse("x+ y", new Parameter(typeof(int), "x"), new Parameter(typeof(int), "y")); var f1 = e.Compile <Func <int, int, int> >(); // f(x) = x^2 + 2*x + 1 e = SimpleParser.Parse("x^2 + 2*x + 1", typeof(float), new Parameter(typeof(float), "x")); var f2 = e.Compile <Func <float, float> >(); // f(x) = x + SUM(x- 1, 3, 2) - 2 e = SimpleParser.Parse("x + SUM(x- 1, 3, 2) - 2", new Parameter(typeof(double), "x")); var f3 = e.Compile <Func <double, double> >(); // f(x) = (x == "raf") [predicate] e = SimpleParser.Parse("x == \"raf\"", Parameter.Create <string>("x")); var f4 = e.Compile <Func <string, bool> >(); }
private static INode GetTree(string str) { var parser = new SimpleParser<Arithmetic, double>(double.Parse, t => t.IsGenericType && t.IsSubclassOf(typeof(BinaryOp))); var tree = parser.Parse(str); return tree; }
public void FuncCalls3() { var e = SimpleParser.Parse("POW(2, 3)"); var f = e.Compile <Func <double> >(); Assert.IsTrue(f() == 8); }
public void Numerical5() { var e = SimpleParser.Parse("x^4 - 1", new Parameter(typeof(double), "x")); var f = e.Compile <Func <double, double> >(); Assert.IsTrue(f(1) == 0); }
private void PortOnDataReceived(object sender, SerialDataReceivedEventArgs e) { var data = new byte[14]; _port.Read(data, 0, _port.BytesToRead); _parser.Parse(data); }
// private IEnumerable <Node> Parse(string template) { var tokens = lexer .Tokenize(template) .ToTokenList(); return(parser.Parse(tokens)); }
public void Test() { SimpleParser parser = Setup(); bool b = parser.Parse(); Assert.True(b); Assert.Equal(new String(_test), parser.Current[0]); }
public void FuncCalls1() { var e = SimpleParser.Parse("x + SUM(x- 1, 3, 2) - 2", new Parameter(typeof(double), "x")); var f = e.Compile <Func <double, double> >(); Assert.IsTrue(f(-1) == 0); }
public void Predicate6() { var e = SimpleParser.Parse("x >=1 && x<5", Parameter.Create <int>("x")); var f = e.Compile <Func <int, bool> >(); Assert.IsTrue(f(3)); Assert.IsFalse(f(6)); }
public void TestSymbolEval() { var parser = new SimpleParser(); var result = parser.Parse("2+x+3", "x", "2"); var expected = 7; Assert.AreEqual(expected, result); }
public void Predicate4() { var e = SimpleParser.Parse("2+(x + 5)* 3 >1", Parameter.Create <int>("x")); var f = e.Compile <Func <int, bool> >(); Assert.IsFalse(f(-6)); Assert.IsTrue(f(5)); }
public void Predicate5() { var e = SimpleParser.Parse("x == \"raf\"", Parameter.Create <string>("x")); var f = e.Compile <Func <string, bool> >(); Assert.IsFalse(f("Raf")); Assert.IsTrue(f("raf")); }
public void Predicate3() { var e = SimpleParser.Parse("x + 5.2 > 9.2", Parameter.Create <double>("x")); var f = e.Compile <Func <double, bool> >(); Assert.IsFalse(f(4)); Assert.IsTrue(f(4.1)); }
public void Predicate2() { var e = SimpleParser.Parse("x+4<=2", Parameter.Create <int>("x")); var f = e.Compile <Func <int, bool> >(); Assert.IsFalse(f(1)); Assert.IsTrue(f(-10)); }
public void TestParse() { var parser = new SimpleParser(Ops); var result = parser.Parse("1+2+3"); var expected = 6; Assert.AreEqual(expected, result); }
public void Numerical3() { var e = SimpleParser.Parse("(4+x) * (y-3) + 1", new Parameter(typeof(double), "x"), new Parameter(typeof(double), "y")); var f = e.Compile <Func <double, double, double> >(); Assert.IsTrue(f(1, 5) == 11); }
public void Numerical4() { var e = SimpleParser.Parse("x^2 + 2*x + 1", typeof(float), new Parameter(typeof(float), "x")); var f = e.Compile <Func <float, float> >(); Assert.IsTrue(f(-1) == 0); }
public void Numerical1() { var e = SimpleParser.Parse("x+ y", new Parameter(typeof(int), "x"), new Parameter(typeof(int), "y")); var f = e.Compile <Func <int, int, int> >(); Assert.IsTrue(f(2, 2) == 4); Assert.IsFalse(f(2, 3) == 4); }
public void Numerical2() { var e = SimpleParser.Parse("x * y", new Parameter(typeof(double), "x"), new Parameter(typeof(double), "y")); var f = e.Compile <Func <double, double, double> >(); Assert.IsTrue(f(3.5, 1.5) == 5.25); Assert.IsFalse(f(2, 2) == 4.1); }
public void Predicate7() { var e = SimpleParser.Parse("x >=1 && x<5 && y>0 && y<10", Parameter.Create <int>("x"), Parameter.Create <int>("y")); var f = e.Compile <Func <int, int, bool> >(); Assert.IsTrue(f(3, 3)); Assert.IsFalse(f(6, 3)); Assert.IsFalse(f(3, 10)); }
public void SimpleParser_ShouldParse() { // Arrange var path = "D:\\Git\\PolygonMesh\\PolygonMesh.Library.Tests\\Resources\\cube.obj"; // Act var vecs = SimpleParser.Parse(path, out var faces); // Assert Assert.AreEqual(8, vecs.Length); Assert.AreEqual(6, faces.Length); }
public void VertexRingIterator_ShouldWork() { // Arrange var path = "D:\\Git\\PolygonMesh\\PolygonMesh.Library.Tests\\Resources\\cube.obj"; var vecs = SimpleParser.Parse(path, out var faces); var mesh = Mesh.Core.Mesh.CreateFromPositions(vecs, faces); // Act var neighbors = mesh.GetVertexNeighbours(0); // Assert Assert.AreEqual(3, neighbors.Count); }
public void Compare1() { var e1 = SimpleParser.Parse("x >= 10", Parameter.Create <int>("x")); var left = Expression.Parameter(typeof(int), "x"); var right = Expression.Constant(10, typeof(int)); var binary = Expression.MakeBinary(ExpressionType.GreaterThanOrEqual, left, right); // building the predicate var lambda = Expression.Lambda <Func <int, bool> >(binary, left); Assert.AreEqual(e1.Expression.ToString(), lambda.ToString()); }
public void SimpleParser_ParseShouldCreateKernel() { // Arrange var path = "D:\\Git\\PolygonMesh\\PolygonMesh.Library.Tests\\Resources\\cube.obj"; // Act var vecs = SimpleParser.Parse(path, out var faces); var mesh = Mesh.Core.Mesh.CreateFromPositions(vecs, faces); // Assert Assert.AreEqual(vecs.Length, mesh.VertexCount); Assert.AreEqual(faces.Length, mesh.FaceCount); Assert.AreEqual(24, mesh.HalfEdgeCount); }
public void TryAssignment() { mockTokens.Enqueue(new Token { TokenType = TokenType.VAR, Value = "string" }); mockTokens.Enqueue(new Token { TokenType = TokenType.NAME, Value = "abc" }); mockTokens.Enqueue(new Token { TokenType = TokenType.ASSIGN, Value = "=" }); mockTokens.Enqueue(new Token { TokenType = TokenType.VALUE, Value = "5" }); mockTokens.Enqueue(new Token { TokenType = TokenType.SEMI, Value = ";" }); lexerStub.Stub(x => x.Tokenize("")).IgnoreArguments().Return(mockTokens); sut.Parse(""); Assert.DoesNotThrow(() => sut.Parse("")); }
private static void ReadInputAndValidateBySchema(string[] args) { if (args.Length != REQUIRED_ARGUMENTS_LENGTH_IS_TWO) { Console.Out.WriteLine("Usage: Console <input SDF> <schema SDF>"); return; } var input = SimpleParser.Parse(args[INPUT_SDF_FILENAME_ARGUMENT_INDEX]); Printer.Print(input); var schema = new Schema(args[INPUT_SDF_SCHEMA_FILENAME_ARGUMENT_INDEX]); var matchesSchema = schema.Validate(input); Console.WriteLine(matchesSchema ? "data matches schema" : schema.ErrorMessage); }