-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashMapTest.java
111 lines (92 loc) · 1.88 KB
/
HashMapTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class HashMapTest
{
HashMap<String, String> mm;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception
{
mm = new HashMap<>();
}
@After
public void tearDown() throws Exception
{
mm = null;
}
private void addsToMap()
{
mm.add("a", "1");
mm.add("b", "2");
mm.add("c", "3");
}
private void addsManyToMap()
{
mm.add("a", "1");
mm.add("b", "2");
mm.add("c", "3");
mm.add("a", "one");
for (int i = 0; i < 26; i++)
{
mm.add(Integer.toString(i), "x");
}
}
@Test
public void testSize0()
{
assertEquals(0, mm.size());
assertTrue(mm.isEmpty());
}
@Test
public void testAddSize()
{
addsToMap();
assertEquals(3, mm.size());
assertFalse(mm.isEmpty());
}
@Test
public void testAddManySize()
{
addsManyToMap();
assertEquals(29, mm.size());
assertFalse(mm.isEmpty());
}
@Test
public void testAddContainsKey()
{
assertFalse(mm.containsKey("a"));
assertFalse(mm.containsKey("b"));
assertFalse(mm.containsKey("c"));
addsToMap();
assertTrue(mm.containsKey("c"));
assertTrue(mm.containsKey("b"));
assertTrue(mm.containsKey("a"));
}
@Test
public void testRemoveKey()
{
addsManyToMap();
mm.remove("b");
assertTrue(mm.getValue("b") == null);
}
@Test
public void testRemoveAndSize()
{
addsManyToMap();
String s1 = mm.remove("a");
assertTrue("one".equals(s1));
assertEquals(28, mm.size());
String s2 = mm.remove("a");
assertEquals(null, s2);
assertEquals(28, mm.size());
}
}