コード例 #1
0
 @Test
 public void testEvalConst() throws Exception {
   Expression expression = Expression.of("92");
   int actual = expression.evaluate();
   assertEquals(92, actual);
 }
コード例 #2
0
 @Test
 public void testVariableExpression() throws Exception {
   Expression.of("foo");
 }
コード例 #3
0
 @Test
 public void testEvaluateInEnvironment() throws Exception {
   Map<String, Integer> environment = Collections.singletonMap("x", 92);
   Expression expression = Expression.of("x");
   assertEquals(92, expression.evaluate(environment));
 }
コード例 #4
0
 @Test
 public void testComplicatedExpression() throws Exception {
   Expression expression = Expression.of("((2)+(2 + 2))");
   int actual = expression.evaluate();
   assertEquals(6, actual);
 }
コード例 #5
0
 @Test
 public void testSumWithParenthesis() throws Exception {
   Expression expression = Expression.of("2+(2 + 2)");
   int actual = expression.evaluate();
   assertEquals(6, actual);
 }
コード例 #6
0
 @Test
 public void testSpacedExpression() throws Exception {
   Expression expression = Expression.of("(2 + 2)");
   int actual = expression.evaluate();
   assertEquals(4, actual);
 }
コード例 #7
0
 @Test(expected = ParseException.class)
 public void testInvalidParenthesis() throws Exception {
   Expression.of("((");
 }
コード例 #8
0
 @Test
 public void testScopeInteger() throws Exception {
   Expression expression = Expression.of("(42)");
   int actual = expression.evaluate();
   assertEquals(42, actual);
 }