1
2
3
4
5
6
7public
8class Test {
9
10
11
12 static
13 int failed = 0;
14
15
16
17 static
18 void test( Object result,
19 Object expected,
20 String testCase )
21 {
22 if ( ! result.equals(expected) ) {
23 ++ failed;
24 System.out.println
25 ("Test Case " + testCase + " failed\n" +
26 "result : " + result.toString() + "\n" +
27 "expected : " + expected.toString() );
28 }
29 }
30
31
32
33 static
34 void test( SExpr result,
35 SExpr expected,
36 String testCase )
37 {
38 if ( result.isEqual(expected) == SExpr.nil ) {
39 test((Object)result, (Object)expected, testCase);
40 }
41 }
42
43
44
45 public static
46 void main(String[] argv) {
47
48 test(SExpr.nil.toString(),
49 "()",
50 "toString 1.1");
51 test(SExpr.t.toString(),
52 "#t",
53 "toString 1.2");
54 test((new Symbol("abc")).toString(),
55 "abc",
56 "toString 1.3");
57 test((new Number((long)123)).toString(),
58 "123",
59 "toString 1.4");
60 test(SExpr.t.cons(SExpr.t).toString(),
61 "( #t . #t )",
62 "toString 1.5");
63
64
65
66 test(SExpr.t.isEqual(SExpr.t),
67 SExpr.t,
68 "isEqual 1.1");
69
70 test(SExpr.nil.isEqual(SExpr.nil),
71 SExpr.t,
72 "isEqual 1.2");
73
74 test(SExpr.t.isEqual(SExpr.nil),
75 SExpr.nil,
76 "isEqual 1.3");
77
78 test(SExpr.nil.isEqual(SExpr.t),
79 SExpr.nil,
80 "isEqual 1.4");
81
82 test((new Symbol("abc")).isEqual(new Symbol("abc")),
83 SExpr.t,
84 "isEqual 1.5");
85
86 test((new Symbol("abc")).isEqual(new Symbol("xyz")),
87 SExpr.nil,
88 "isEqual 1.6");
89
90 {
91 SExpr t = SExpr.t;
92 SExpr nil = SExpr.nil;
93
94 SExpr s1 = new Symbol("abc");
95 SExpr s2 = new Symbol("xyz");
96
97 SExpr n1 = new Number(0);
98 SExpr n2 = new Number(1);
99
100 SExpr l1 = s1.cons(SExpr.nil);
101
102 SExpr p1 = s2.cons(s1);
103
104 test(s1.isEqual(s1),SExpr.t,"isEqual 1.7.1");
105 test(n1.isEqual(n1),SExpr.t,"isEqual 1.7.2");
106 test(l1.isEqual(l1),SExpr.t,"isEqual 1.7.3");
107
108 test(s1.isEqual(s2),SExpr.nil,"isEqual 1.8.1");
109 test(n1.isEqual(n2),SExpr.nil,"isEqual 1.8.2");
110 test(l1.isEqual(p1),SExpr.nil,"isEqual 1.8.3");
111
112 test(s1.isEqual(n1),SExpr.nil,"isEqual 1.9.1");
113 test(s1.isEqual(l1),SExpr.nil,"isEqual 1.9.2");
114 test(n1.isEqual(l1),SExpr.nil,"isEqual 1.9.3");
115
116 test( t.isList(),SExpr.nil,"isList 1.1");
117 test(nil.isList(),SExpr.t ,"isList 1.2");
118 test( n1.isList(),SExpr.nil,"isList 1.3");
119 test( s1.isList(),SExpr.nil,"isList 1.4");
120 test( l1.isList(),SExpr.t ,"isList 1.5");
121 test( p1.isList(),SExpr.nil,"isList 1.6");
122
123 test( t.isPair(),SExpr.nil,"isPair 1.1");
124 test(nil.isPair(),SExpr.nil,"isPair 1.2");
125 test( n1.isPair(),SExpr.nil,"isPair 1.3");
126 test( s1.isPair(),SExpr.nil,"isPair 1.4");
127 test( l1.isPair(),SExpr.t ,"isPair 1.5");
128 test( p1.isPair(),SExpr.t ,"isPair 1.6");
129
130 test( t.isAtom(),SExpr.t ,"isAtom 1.1");
131 test(nil.isAtom(),SExpr.t ,"isAtom 1.2");
132 test( n1.isAtom(),SExpr.t ,"isAtom 1.3");
133 test( s1.isAtom(),SExpr.t ,"isAtom 1.4");
134 test( l1.isAtom(),SExpr.nil,"isAtom 1.5");
135
136 test( t.isNull(),SExpr.nil,"isNull 1.1");
137 test(nil.isNull(),SExpr.t ,"isNull 1.2");
138 test( n1.isNull(),SExpr.nil,"isNull 1.3");
139 test( s1.isNull(),SExpr.nil,"isNull 1.4");
140 test( l1.isNull(),SExpr.nil,"isNull 1.5");
141
142 test( t.isNull(),SExpr.t, "wrong test case 1.42");
143 }
144
145
146
147
148 System.out.println
149 ( (failed == 0)
150 ? "all tests passed"
151 : (failed + " Test(s) failed") );
152 }
153}