PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/interpreter/tags/at2dist110511/test/edu/vub/at/objects/natives/TestFieldMap.java

http://ambienttalk.googlecode.com/
Java | 72 lines | 45 code | 10 blank | 17 comment | 0 complexity | 069958b0306bdab5eb48f6262018b16c MD5 | raw file
 1package edu.vub.at.objects.natives;
 2
 3import edu.vub.at.AmbientTalkTestCase;
 4import edu.vub.at.objects.natives.grammar.AGSymbol;
 5
 6/**
 7 * @author tvc
 8 *
 9 * A Unit Test for the FieldMap class.
10 * Tests the Field Map's behaviour for adding and looking up field names.
11 */
12public class TestFieldMap extends AmbientTalkTestCase {
13
14	public static void main(String[] args) {
15		junit.swingui.TestRunner.run(TestFieldMap.class);
16	}
17
18	private FieldMap map_;
19
20	/**
21	 * Constructs the map
22	 * [ x -> 0
23	 *   y -> 1
24	 *   z -> 2
25	 *   u -> 3
26	 *   v -> 4
27	 *   w -> 5
28	 *   a -> 6
29	 *   b -> 7 ]
30	 */
31	protected void setUp() throws Exception {
32		map_ = new FieldMap();
33		assertTrue(map_.put(AGSymbol.jAlloc("x")));
34		map_.put(AGSymbol.jAlloc("y"));
35		map_.put(AGSymbol.jAlloc("z"));
36		map_.put(AGSymbol.jAlloc("u"));
37		assertTrue(map_.put(AGSymbol.jAlloc("v")));
38		map_.put(AGSymbol.jAlloc("w"));
39		map_.put(AGSymbol.jAlloc("a"));
40		map_.put(AGSymbol.jAlloc("b"));
41		assertFalse(map_.put(AGSymbol.jAlloc("x")));
42	}
43
44	public void testMap() {
45		assertEquals(0, map_.get(AGSymbol.jAlloc("x")));
46		assertEquals(1, map_.get(AGSymbol.jAlloc("y")));
47		assertEquals(2, map_.get(AGSymbol.jAlloc("z")));
48		assertEquals(3, map_.get(AGSymbol.jAlloc("u")));
49		assertEquals(4, map_.get(AGSymbol.jAlloc("v")));
50		assertEquals(5, map_.get(AGSymbol.jAlloc("w")));
51		assertEquals(6, map_.get(AGSymbol.jAlloc("a")));
52		assertEquals(7, map_.get(AGSymbol.jAlloc("b")));
53		assertEquals(-1, map_.get(AGSymbol.jAlloc("c")));
54	}
55	
56	public void testRemoval() {
57		assertEquals(2, map_.get(AGSymbol.jAlloc("z")));
58		assertEquals(2, map_.remove(AGSymbol.jAlloc("z")));
59
60		assertEquals(0, map_.get(AGSymbol.jAlloc("x")));
61		assertEquals(1, map_.get(AGSymbol.jAlloc("y")));
62		assertEquals(-1, map_.get(AGSymbol.jAlloc("z")));
63		assertEquals(2, map_.get(AGSymbol.jAlloc("u")));
64		assertEquals(3, map_.get(AGSymbol.jAlloc("v")));
65		assertEquals(4, map_.get(AGSymbol.jAlloc("w")));
66		assertEquals(5, map_.get(AGSymbol.jAlloc("a")));
67		assertEquals(6, map_.get(AGSymbol.jAlloc("b")));
68		
69		assertEquals(-1, map_.remove(AGSymbol.jAlloc("foo")));
70	}
71
72}