KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jruby > util > collections > test > SlottedHashMapTest


1 package org.jruby.util.collections.test;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import org.jruby.util.collections.SlottedHashMap;
7
8 import junit.framework.TestCase;
9
10 public class SlottedHashMapTest extends TestCase {
11     public SlottedHashMapTest(String JavaDoc arg0) {
12         super(arg0);
13     }
14
15     public void test1() {
16         SlottedHashMap top = new SlottedHashMap("top");
17         
18         top.put("one", "top one");
19         top.put("two", "top two");
20         top.put("three", "top three");
21         
22         display(top, "top");
23         
24         SlottedHashMap a = new SlottedHashMap("a", top);
25         SlottedHashMap b = new SlottedHashMap("b", top);
26         
27         a.put("three", "a three");
28         a.put("four", "a four");
29         a.put("five", "a five");
30         
31         b.put("two", "b two");
32         b.put("four", "b four");
33         b.put("five", "b five");
34         
35         display(a, "a");
36         display(b, "b");
37         
38         SlottedHashMap aa = new SlottedHashMap("aa", a);
39         
40         aa.put("one", "aa one");
41         aa.put("four", "aa four");
42         aa.put("six", "aa six");
43         
44         display(aa, "aa");
45         
46         assertEquals("top one", top.get("one"));
47         assertEquals("a three", a.get("three"));
48         assertEquals("b two", b.get("two"));
49         assertEquals("aa one", aa.get("one"));
50         assertEquals("top two", aa.get("two"));
51         assertEquals("a three", aa.get("three"));
52         
53         top.put("one", "new top one");
54         top.put("five", "new top five");
55         a.put("four", "new a four");
56         
57         display(top, "top");
58         display(a, "top");
59         display(b, "b");
60         display(aa, "aa");
61
62         assertEquals("new top one", a.get("one"));
63         assertEquals("aa one", aa.get("one"));
64         assertEquals("a five", a.get("five"));
65         assertEquals("a five", aa.get("five"));
66         assertEquals("aa four", aa.get("four"));
67         
68         assertEquals("new top one", a.remove("one"));
69         assertEquals("new top one", a.remove("one"));
70     }
71     
72     public void display(SlottedHashMap shm, String JavaDoc id) {
73         System.out.println("SHM '" + id + "' contains:");
74         for (Iterator JavaDoc iter = shm.entrySet().iterator(); iter.hasNext();) {
75             Map.Entry JavaDoc entry = (Map.Entry JavaDoc)iter.next();
76
77             System.out.println("\t" + entry.getKey() + " = " + entry.getValue());
78         }
79     }
80 }
81
Popular Tags