PageRenderTime 43ms CodeModel.GetById 27ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/test/kilim/test/TestUsage.java

http://github.com/kilim/kilim
Java | 56 lines | 36 code | 5 blank | 15 comment | 2 complexity | 70ca0ea045d2729a6fe33828a7d26cb8 MD5 | raw file
 1/* Copyright (c) 2006, Sriram Srinivasan
 2 *
 3 * You may distribute this software under the terms of the license 
 4 * specified in the file "License"
 5 */
 6
 7package kilim.test;
 8
 9import java.util.ArrayList;
10
11import kilim.analysis.Usage;
12import junit.framework.TestCase;
13
14public class TestUsage extends TestCase {
15    /**
16     * Tests whether a bunch of reads and writes produces the appropriate live-in 
17     */
18    public void testReadWrite() {
19        Usage u = new Usage(4);
20        u.read(1);
21        u.read(2);
22        u.write(2);
23        u.write(3);
24        u.evalLiveIn(new ArrayList<Usage>(),null);
25        assertFalse(u.isLiveIn(0));
26        assertTrue(u.isLiveIn(1));
27        assertTrue(u.isLiveIn(2));
28        assertFalse(u.isLiveIn(3));
29    }
30    
31    public void testChange() {
32        Usage u = new Usage(31);
33        Usage ufollow1 = new Usage(31);
34        Usage ufollow2 = new Usage(31);
35        //       29:R 
36        //       30:W
37        // Usage 1 and 2.
38        //   28:in    28:not_in 
39        //   29:in    29:not_in
40        //   30:in    30:in
41        // Expected usage.in :  28:in 29:in 30:not_in
42        u.read(29); u.write(30);
43        for (int ii=0; ii < 31; ii++) u.setBornIn(ii);
44        ufollow1.setLiveIn(28); ufollow1.setLiveIn(29); ufollow1.setLiveIn(30);
45        ufollow2.setLiveIn(30);
46        ArrayList<Usage> ua = new ArrayList<Usage>(2);
47        ua.add(ufollow1); ua.add(ufollow2);
48        assertTrue(u.evalLiveIn(ua,null)); // should return changed == true
49        for (int i = 0; i < 28; i++) {
50            assertFalse(u.isLiveIn(i));
51        }
52        assertTrue(u.isLiveIn(28));
53        assertTrue(u.isLiveIn(29));
54        assertFalse(u.isLiveIn(30));
55    }
56}