3 import Analysis.OwnershipAnalysis.*;
10 static boolean aTestFailed;
13 protected static void test( String test,
17 if( expected == result ) {
18 outcome = "...\tpassed";
20 outcome = "...\tFAILED";
24 System.out.println( test+" expected "+expected+outcome );
28 public static void main(String args[]) throws Exception {
33 System.out.println( "---------------------------------------" );
35 System.out.println( "---------------------------------------" );
37 System.out.println( "---------------------------------------" );
40 System.out.println( "<><><><><><><><><><><><><><><><><><><><><><><><>" );
41 System.out.println( "<><><> WARNING: At least one test failed. <><><>" );
42 System.out.println( "<><><><><><><><><><><><><><><><><><><><><><><><>" );
44 System.out.println( "All tests passed." );
49 public static void testExample() {
51 // example test to know the testing routine is correct!
52 test( "4 == 5?", false, 4 == 5 );
53 test( "3 == 3?", true, 3 == 3 );
57 public static void testTokenTuple() {
59 TokenTuple tt0 = new TokenTuple( new Integer( 1 ), true, TokenTuple.ARITY_ONE );
60 TokenTuple tt1 = new TokenTuple( new Integer( 1 ), true, TokenTuple.ARITY_ONE );
61 TokenTuple tt2 = new TokenTuple( new Integer( 2 ), true, TokenTuple.ARITY_ONE );
62 TokenTuple tt3 = new TokenTuple( new Integer( 1 ), true, TokenTuple.ARITY_MANY );
63 TokenTuple tt4 = new TokenTuple( new Integer( 3 ), false, TokenTuple.ARITY_ONE );
64 TokenTuple tt5 = new TokenTuple( new Integer( 3 ), false, TokenTuple.ARITY_ONE );
66 test( "tt0 equals tt1?", true, tt0.equals( tt1 ) );
67 test( "tt1 equals tt0?", true, tt1.equals( tt0 ) );
68 test( "tt1.hashCode == tt0.hashCode?", true, tt1.hashCode() == tt0.hashCode() );
70 test( "tt0 equals tt2?", false, tt0.equals( tt2 ) );
71 test( "tt2 equals tt0?", false, tt2.equals( tt0 ) );
72 test( "tt2.hashCode == tt0.hashCode?", false, tt2.hashCode() == tt0.hashCode() );
74 test( "tt0 equals tt3?", false, tt0.equals( tt3 ) );
75 test( "tt3 equals tt0?", false, tt3.equals( tt0 ) );
76 test( "tt3.hashCode == tt0.hashCode?", false, tt3.hashCode() == tt0.hashCode() );
78 test( "tt2 equals tt3?", false, tt2.equals( tt3 ) );
79 test( "tt3 equals tt2?", false, tt3.equals( tt2 ) );
80 test( "tt3.hashCode == tt2.hashCode?", false, tt3.hashCode() == tt2.hashCode() );
82 tt1 = tt1.increaseArity();
84 test( "tt1 equals tt2?", false, tt1.equals( tt2 ) );
85 test( "tt2 equals tt1?", false, tt2.equals( tt1 ) );
86 test( "tt2.hashCode == tt1.hashCode?", false, tt2.hashCode() == tt1.hashCode() );
88 test( "tt1 equals tt3?", true, tt1.equals( tt3 ) );
89 test( "tt3 equals tt1?", true, tt3.equals( tt1 ) );
90 test( "tt3.hashCode == tt1.hashCode?", true, tt3.hashCode() == tt1.hashCode() );
92 test( "tt4 equals tt5?", true, tt4.equals( tt5 ) );
93 test( "tt5 equals tt4?", true, tt5.equals( tt4 ) );
94 test( "tt5.hashCode == tt4.hashCode?", true, tt5.hashCode() == tt4.hashCode() );
96 tt4 = tt4.increaseArity();
98 test( "tt4 equals tt5?", true, tt4.equals( tt5 ) );
99 test( "tt5 equals tt4?", true, tt5.equals( tt4 ) );
100 test( "tt5.hashCode == tt4.hashCode?", true, tt5.hashCode() == tt4.hashCode() );
103 TokenTuple tt6 = new TokenTuple( new Integer( 6 ), false, TokenTuple.ARITY_ONE );
104 TokenTuple tt7 = new TokenTuple( new Integer( 6 ), false, TokenTuple.ARITY_ONE );
105 TokenTuple tt8 = new TokenTuple( new Integer( 8 ), false, TokenTuple.ARITY_ONE );
106 TokenTuple tt9 = new TokenTuple( new Integer( 9 ), false, TokenTuple.ARITY_ONE );
108 test( "tt6 equals tt7?", true, tt6.equals( tt7 ) );
109 test( "tt6.hashCode == tt7.hashCode?", true, tt6.hashCode() == tt7.hashCode() );
111 test( "tt8 equals tt7?", false, tt8.equals( tt7 ) );
112 test( "tt8.hashCode == tt7.hashCode?", false, tt8.hashCode() == tt7.hashCode() );
114 // notice that this makes tt7 canonical
115 tt7 = tt7.changeTokenTo( new Integer( 8 ) );
117 test( "tt6 equals tt7?", false, tt6.equals( tt7 ) );
118 test( "tt6.hashCode == tt7.hashCode?", false, tt6.hashCode() == tt7.hashCode() );
120 test( "tt8 equals tt7?", true, tt8.equals( tt7 ) );
121 test( "tt8.hashCode == tt7.hashCode?", true, tt8.hashCode() == tt7.hashCode() );
123 test( "tt6 == tt7?", false, tt6 == tt7 );
124 test( "tt8 == tt7?", false, tt8 == tt7 );
125 test( "tt9 == tt7?", false, tt9 == tt7 );
127 tt6 = tt6.makeCanonical();
128 tt8 = tt8.makeCanonical();
129 tt9 = tt9.makeCanonical();
131 test( "tt6 == tt7?", false, tt6 == tt7 );
132 test( "tt8 == tt7?", true, tt8 == tt7 );
133 test( "tt9 == tt7?", false, tt9 == tt7 );
137 public static void testTokenTupleSet() {
145 public static void garbage() {
151 TokenTupleSet tts0 = new TokenTupleSet( tt0 );
152 TokenTupleSet tts1 = new TokenTupleSet( tt1 );
153 TokenTupleSet tts2 = new TokenTupleSet( tt2 );
154 TokenTupleSet tts3 = new TokenTupleSet( tt3 );
155 TokenTupleSet tts4 = tts1.union( tts3 );
156 TokenTupleSet tts5 = tts0.union( tts2 );
157 TokenTupleSet tts6 = tts1.union( tts1 );
159 System.out.println( "tts4 is "+tts4 );
160 System.out.println( "tts5 is "+tts5 );
161 System.out.println( "tts6 is "+tts6 );
163 ReachabilitySet rs0 = new ReachabilitySet( tts0 );
164 rs0 = rs0.union( new ReachabilitySet( tts2 ) );
165 rs0 = rs0.union( new ReachabilitySet( tts5 ) );
167 System.out.println( "rs0 is "+rs0 );
169 TokenTuple tt4 = new TokenTuple( new Integer( 4 ),
171 TokenTuple.ARITY_ONE );
173 TokenTuple tt5 = new TokenTuple( new Integer( 4 ),
175 TokenTuple.ARITY_ONE );
177 TokenTuple tt6 = new TokenTuple( new Integer( 6 ),
179 TokenTuple.ARITY_ONE );
181 TokenTupleSet tts7 = new TokenTupleSet( tt4 );
182 //TokenTupleSet tts8 = new TokenTupleSet( tt5 );
183 TokenTupleSet tts9 = new TokenTupleSet( tt1 );
184 tts9 = tts9.union( tts2 );
186 ReachabilitySet rs1 = new ReachabilitySet( tts7 );
187 //rs1 = rs1.union( new ReachabilitySet( tts8 ) );
188 rs1 = rs1.union( new ReachabilitySet( tts9 ) );
190 System.out.println( "rs1 is "+rs1 );
193 ChangeTupleSet cts0 = rs0.unionUpArityToChangeSet( rs1 );
194 System.out.println( "cts0 is "+cts0 );
198 TokenTuple tt00 = new TokenTuple( new Integer( 9 ),
200 TokenTuple.ARITY_ONE );
202 TokenTuple tt01 = new TokenTuple( new Integer( 9 ),
204 TokenTuple.ARITY_ONE );
206 test( "tt00 equals tt01?", true, tt00.equals( tt01 ) );
207 test( "tt00 == tt01?", false, tt00 == tt01 );
209 tt00 = (TokenTuple) Canonical.makeCanonical( tt00 );
210 tt01 = (TokenTuple) Canonical.makeCanonical( tt01 );
212 test( "tt00 equals tt01?", true, tt00.equals( tt01 ) );
213 test( "tt00 == tt01?", true, tt00 == tt01 );
217 (TokenTuple) Canonical.makeCanonical(
218 new TokenTuple( new Integer( 10 ),
220 TokenTuple.ARITY_ONE )
224 (TokenTuple) Canonical.makeCanonical(
225 new TokenTuple( new Integer( 11 ),
227 TokenTuple.ARITY_ONE )
231 (TokenTuple) Canonical.makeCanonical(
232 new TokenTuple( new Integer( 12 ),
234 TokenTuple.ARITY_ONE )
237 TokenTupleSet ttsT00 =
238 (TokenTupleSet) Canonical.makeCanonical( new TokenTupleSet( tt00 ) );
240 TokenTupleSet ttsT01 =
241 (TokenTupleSet) Canonical.makeCanonical( new TokenTupleSet( tt01 ) );
243 TokenTupleSet ttsT02 =
244 (TokenTupleSet) Canonical.makeCanonical( new TokenTupleSet( tt02 ) );
246 TokenTupleSet ttsT03 =
247 (TokenTupleSet) Canonical.makeCanonical( new TokenTupleSet( tt03 ) );
249 TokenTupleSet ttsT04 =
250 (TokenTupleSet) Canonical.makeCanonical( new TokenTupleSet( tt04 ) );
252 TokenTupleSet tts00 = ttsT00.union( ttsT02.union( ttsT03.union( ttsT04 ) ) );
253 TokenTupleSet tts01 = ttsT01.union( ttsT02.union( ttsT03.union( ttsT04 ) ) );
255 test( "tts00 equals tts01?", true, tts00.equals( tts01 ) );
257 // It's OK that this one turns out true--I changed the union operator
258 // to automatically canonicalize stuff!
259 test( "tts00 == tts01?", false, tts00 == tts01 );
261 tts00 = (TokenTupleSet) Canonical.makeCanonical( tts00 );
262 tts01 = (TokenTupleSet) Canonical.makeCanonical( tts01 );
264 test( "tts00 equals tts01?", true, tts00.equals( tts01 ) );
265 test( "tts00 == tts01?", true, tts00 == tts01 );
269 ReachabilitySet rs2 = new ReachabilitySet( tts00 );
270 ReachabilitySet rs3 = new ReachabilitySet( tts01 ).union( rs2 );
272 System.out.println( "rs3 is "+rs3 );
274 rs3 = rs3.increaseArity( new Integer( 11 ) );
275 System.out.println( "rs3 is "+rs3 );
279 TokenTuple tt11 = new TokenTuple( new Integer( 1 ),
281 TokenTuple.ARITY_ONE );
283 TokenTuple tt12 = new TokenTuple( new Integer( 2 ),
285 TokenTuple.ARITY_ONE );
287 TokenTuple tt13 = new TokenTuple( new Integer( 3 ),
289 TokenTuple.ARITY_MANY );
291 TokenTuple tt14 = new TokenTuple( new Integer( 4 ),
293 TokenTuple.ARITY_ONE );
295 TokenTuple tt15 = new TokenTuple( new Integer( 5 ),
297 TokenTuple.ARITY_ONE );
299 TokenTuple tt16 = new TokenTuple( new Integer( 6 ),
301 TokenTuple.ARITY_MANY );
304 TokenTupleSet tts10 = new TokenTupleSet();
305 tts10 = tts10.add( tt11 );
306 tts10 = tts10.add( tt12 );
307 tts10 = tts10.add( tt13 );
308 tts10 = tts10.add( tt14 );
309 tts10 = tts10.add( tt15 );
310 tts10 = tts10.add( tt16 );
314 TokenTuple tt21 = new TokenTuple( new Integer( 1 ),
316 TokenTuple.ARITY_ONE );
318 TokenTuple tt22 = new TokenTuple( new Integer( 5 ),
320 TokenTuple.ARITY_ONE );
322 TokenTuple tt23 = new TokenTuple( new Integer( 3 ),
324 TokenTuple.ARITY_ONE );
326 TokenTuple tt24 = new TokenTuple( new Integer( 6 ),
328 TokenTuple.ARITY_MANY );
330 TokenTuple tt25 = new TokenTuple( new Integer( 7 ),
332 TokenTuple.ARITY_ONE );
334 TokenTuple tt26 = new TokenTuple( new Integer( 8 ),
336 TokenTuple.ARITY_MANY );
339 TokenTupleSet tts20 = new TokenTupleSet();
340 tts20 = tts20.add( tt21 );
341 tts20 = tts20.add( tt22 );
342 tts20 = tts20.add( tt23 );
343 tts20 = tts20.add( tt24 );
344 tts20 = tts20.add( tt25 );
345 tts20 = tts20.add( tt26 );
347 TokenTupleSet tts30 = tts10.unionUpArity( tts20 );
349 System.out.println( "tts10 is "+tts10 );
350 System.out.println( "tts20 is "+tts20 );
351 System.out.println( "" );
352 System.out.println( "tts30 is "+tts30 );
355 TokenTupleSet tts40 = new TokenTupleSet();
356 tts40 = tts40.add( tt21 );
357 tts40 = tts40.add( tt23 );
359 TokenTupleSet tts50 = new TokenTupleSet();
360 tts50 = tts50.add( tt21 );
361 tts50 = tts50.add( tt23 );
362 tts50 = tts50.add( tt22 );
364 TokenTupleSet tts60 = new TokenTupleSet();
365 tts60 = tts60.add( tt21 );
366 tts60 = tts60.add( tt24 );
368 TokenTupleSet tts70 = new TokenTupleSet();
369 tts70 = tts70.add( tt11 );
370 tts70 = tts70.add( tt13 );
371 tts70 = tts70.add( tt12 );
373 TokenTupleSet tts71 = new TokenTupleSet();
374 tts71 = tts71.add( tt13 );
375 tts71 = tts71.add( tt11 );
376 tts71 = tts71.add( tt15 );
378 TokenTupleSet tts72 = new TokenTupleSet();
379 tts72 = tts72.add( tt11 );
380 tts72 = tts72.add( tt16 );
382 TokenTupleSet tts73 = new TokenTupleSet();
383 tts73 = tts73.add( tt12 );
385 ReachabilitySet rs40 = new ReachabilitySet();
386 rs40 = rs40.add( tts40 );
387 rs40 = rs40.add( tts50 );
388 rs40 = rs40.add( tts60 );
390 ReachabilitySet rs50 = new ReachabilitySet();
391 rs50 = rs50.add( tts70 );
392 rs50 = rs50.add( tts71 );
393 rs50 = rs50.add( tts72 );
394 rs50 = rs50.add( tts73 );
396 ReachabilitySet rs60 = rs50.unionUpArity( rs40 );
398 System.out.println( "rs40 is "+rs40 );
399 System.out.println( "rs50 is "+rs50 );
400 System.out.println( "" );
401 System.out.println( "rs60 is "+rs60 );