public void ParseSuccess() { var parser = new RWLayout.alpha2.ConstraintParser(); var tests = new TestSuccessEntry[] { new TestSuccessEntry( "dlayout.height == dlayout.intrinsicHeight", new string[] { "1×dlayout.height", "-1×dlayout.intrinsicHeight" }, Cl.Operator.EqualTo ), new TestSuccessEntry( "noexamples.top == aaass.bottom+20", new string[] { "1×noexamples.top", "-1×aaass.bottom", "-20" }, Cl.Operator.EqualTo ), new TestSuccessEntry( "a.x/10 + b.y*10 >= test.tt - test.dd - 2*test.ac + 0*test.d", new string[] { "0.1×a.x", "10×b.y", "-1×test.tt", "1×test.dd", "2×test.ac" }, Cl.Operator.GreaterThanOrEqualTo ), new TestSuccessEntry( "a.x + 10 + 20 + 30 >= 0", new string[] { "1×a.x", "10", "20", "30" }, Cl.Operator.GreaterThanOrEqualTo ), new TestSuccessEntry( "0<=55*a.bb", new string[] { "-55×a.bb" }, Cl.Operator.LessThanOrEqualTo ), new TestSuccessEntry( "a.x + ==", new string[] { "1×a.x" }, Cl.Operator.EqualTo ), new TestSuccessEntry( "a.x ==", new string[] { "1×a.x" }, Cl.Operator.EqualTo ), new TestSuccessEntry( "== a.x", new string[] { "-1×a.x" }, Cl.Operator.EqualTo ), }; foreach (var test in tests) { var result = parser.Parse(test.Constraint); Assert.IsTrue(result.Terms.Select(x => x.ToString()).SequenceEqual(test.ExpectedTerms), test.Constraint); Assert.AreEqual(test.Operator, result.Operator); } }
public void ParseThrows() { var parser = new RWLayout.alpha2.ConstraintParser(); var tests = new TestThrowsEmtry[] { new TestThrowsEmtry( "test", typeof(SyntaxErrorException) ), new TestThrowsEmtry( "test.ab", typeof(SyntaxErrorException) ), new TestThrowsEmtry( "2*test", typeof(SyntaxErrorException) ), new TestThrowsEmtry( "2*test.ab*2", typeof(SyntaxErrorException) ), new TestThrowsEmtry( "a.x = b.y", typeof(SyntaxErrorException) ), new TestThrowsEmtry( "a.x/b.y == 1", typeof(SyntaxErrorException) ), new TestThrowsEmtry( "2/b.y == 1", typeof(SemanticErrorException) ), new TestThrowsEmtry( "a.x/0 == 1", typeof(SemanticErrorException) ), new TestThrowsEmtry( "<=", typeof(SemanticErrorException) ), }; foreach (var test in tests) { try { var result = parser.Parse(test.Constraint); } catch (Exception e) { Assert.AreEqual(test.ExceptionType, e.GetType(), test.Constraint); continue; } Assert.Fail($"No exception was thrown for constraint \"{test.Constraint}\""); } }
//[TestMethod] public void PerfTest() { var tests = new string[] { "dlayout.top == root.top", "vlogging.top == dlayout.bottom+2", "lognull.top == vlogging.bottom+10", "sticky.top == lognull.bottom+2", "aaass.top == sticky.bottom+2", "noexamples.top == aaass.bottom+20", "dlayout.height == dlayout.intrinsicHeight", "vlogging.height == vlogging.intrinsicHeight", "lognull.height == lognull.intrinsicHeight", "sticky.height == sticky.intrinsicHeight", "aaass.height == aaass.intrinsicHeight", "noexamples.height == noexamples.intrinsicHeight", "dlayout.left == root.left", "vlogging.left == root.left", "lognull.left == root.left", "sticky.left == root.left", "aaass.left == root.left", "noexamples.left == root.left", "dlayout.right == root.right", "vlogging.right == root.right", "lognull.right == root.right", "sticky.right == root.right", "aaass.right == root.right", "noexamples.right == root.right", }; var parser = new RWLayout.alpha2.ConstraintParser(); for (int i = 0; i < 100000; i++) { foreach (var test in tests) { var result = parser.Parse(test); } } }