|
@@ -0,0 +1,68 @@
|
|
1
|
+import org.junit.Assert;
|
|
2
|
+import org.junit.Before;
|
|
3
|
+import org.junit.Test;
|
|
4
|
+
|
|
5
|
+public class MyMapTest {
|
|
6
|
+ MyMap testMap;
|
|
7
|
+
|
|
8
|
+ @Before
|
|
9
|
+ public void setUp() throws Exception {
|
|
10
|
+ testMap = new MyMap<Integer, String>();
|
|
11
|
+ }
|
|
12
|
+
|
|
13
|
+ @Test
|
|
14
|
+ public void testPut() {
|
|
15
|
+ int expectedSize = 2;
|
|
16
|
+ testMap.put(100, "T-Shirt");
|
|
17
|
+ testMap.put(100, "T-Shirt");
|
|
18
|
+
|
|
19
|
+ Assert.assertEquals(expectedSize, testMap.getMyEntries().getSize());
|
|
20
|
+ }
|
|
21
|
+
|
|
22
|
+ @Test
|
|
23
|
+ public void testGetValue() {
|
|
24
|
+ testMap.put(100, "T-Shirt");
|
|
25
|
+ String expectedValue = "T-Shirt";
|
|
26
|
+
|
|
27
|
+ Assert.assertEquals(expectedValue, testMap.get(100));
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ @Test
|
|
31
|
+ public void testKeySet() {
|
|
32
|
+ // adds a new entry to the map
|
|
33
|
+ testMap.put(100, "T-Shirt");
|
|
34
|
+ testMap.put(100, "T-Shirt");
|
|
35
|
+ testMap.put(100, "T-Shirt");
|
|
36
|
+
|
|
37
|
+ testMap.getMyEntries().getMyArrayList();
|
|
38
|
+
|
|
39
|
+ MyArrayList<Integer> keys = testMap.keySet();
|
|
40
|
+ for (int i = 0; i < testMap.getMyEntries().getSize(); i++) {
|
|
41
|
+ System.out.println(keys.get(i));
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+ Assert.assertEquals(testMap.getMyEntries().getSize(), keys.getSize());
|
|
45
|
+
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ @Test
|
|
49
|
+ public void testValues() {
|
|
50
|
+
|
|
51
|
+ testMap.put(100, "T-Shirt M");
|
|
52
|
+ testMap.put(200, "T-Shirt XL");
|
|
53
|
+ testMap.put(300, "T-Shirt S");
|
|
54
|
+ testMap.put(400, "T-Shirt SM");
|
|
55
|
+ testMap.put(500, "T-Shirt LL");
|
|
56
|
+ testMap.put(600, "T-Shirt OO");
|
|
57
|
+
|
|
58
|
+ MyArrayList<String> values = testMap.valueSet();
|
|
59
|
+ for (int i = 0; i < testMap.getMyEntries().getSize(); i++) {
|
|
60
|
+ System.out.println(values.get(i));
|
|
61
|
+ }
|
|
62
|
+
|
|
63
|
+ Assert.assertEquals(testMap.getMyEntries().getSize(), values.getSize());
|
|
64
|
+ }
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+}
|
|
68
|
+
|