KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > prefuse > data > expression > ExpressionTest


1 package test.prefuse.data.expression;
2
3 import junit.framework.TestCase;
4 import prefuse.data.expression.AndPredicate;
5 import prefuse.data.expression.ArithmeticExpression;
6 import prefuse.data.expression.ColumnExpression;
7 import prefuse.data.expression.ComparisonPredicate;
8 import prefuse.data.expression.Expression;
9 import prefuse.data.expression.FunctionExpression;
10 import prefuse.data.expression.IfExpression;
11 import prefuse.data.expression.ObjectLiteral;
12 import prefuse.data.expression.parser.ExpressionParser;
13 import prefuse.data.expression.parser.ParseException;
14 import prefuse.data.expression.parser.TokenMgrError;
15
16 public class ExpressionTest extends TestCase {
17
18     private static String JavaDoc[] expr = {
19         "District <= 0",
20         "IF x < 0 THEN x^2 ELSE x%0",
21         "ABS(3+5*EXP(3)/SIN(5)*SIGN(32.3f)-ROUND(23.2e-1))",
22         "x && y",
23         "x & y",
24         "if x<0 else x^2 then x%0",
25         "((3+6)*(4+1))",
26         "2*3%6",
27         "2+3%6",
28         "2*3^6",
29         "2 + 3 3 + 4",
30         "[One Long Column]",
31         "An Invalid Column",
32         "\"Double Quoted String\"",
33         "'A tab\\t andd\\b a newline \\n'"
34     };
35     private static Class JavaDoc[] type = {
36         ComparisonPredicate.class,
37         IfExpression.class,
38         FunctionExpression.class,
39         AndPredicate.class,
40         null,
41         null,
42         ArithmeticExpression.class,
43         ArithmeticExpression.class,
44         ArithmeticExpression.class,
45         ArithmeticExpression.class,
46         null,
47         ColumnExpression.class,
48         null,
49         ObjectLiteral.class,
50         ObjectLiteral.class
51     };
52     
53     public void testExpressionParser() {
54         for ( int i=0; i<expr.length; ++i ) {
55             try {
56                 Expression e = ExpressionParser.parse(expr[i], true);
57                 assertEquals(true, type[i]!=null);
58                 assertEquals(true, type[i].isAssignableFrom(e.getClass()));
59             } catch ( TokenMgrError tme ) {
60                 System.out.println(tme);
61                 assertEquals(null, type[i]);
62             } catch ( ParseException pe ) {
63                 System.out.println(pe);
64                 assertEquals(null, type[i]);
65             }
66         }
67     }
68     
69 }
70
Popular Tags