-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChainHashMapTest.java
99 lines (78 loc) · 2.61 KB
/
ChainHashMapTest.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
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;
class ChainHashMapTest {
@Test
void testSize() {
ChainHashMap<Integer, String> map = new ChainHashMap<Integer, String>();
int n = 10;
for(int i = 0; i < n; ++i) {
map.put(i, Integer.toString(i));
}
assertEquals(n, map.size());
}
@Test
void testGet() {
ChainHashMap<String, Integer> map = new ChainHashMap<String, Integer>();
int n = 10;
for(int i = 0; i < n; ++i) {
map.put(Integer.toString(i), i);
}
System.out.println(map);
assertEquals(5, map.get("5"));
assertEquals(2, map.get("2"));
}
@Test
void testRemove() {
ChainHashMap<String, Integer> map = new ChainHashMap<String, Integer>();
int n = 10;
for(int i = 0; i < n; ++i) {
map.put(Integer.toString(i), i);
}
System.out.println(map);
assertEquals(5, map.remove("5"));
assertEquals(n-1, map.size());
}
@Test
void testPut() {
ChainHashMap<String, Integer> map = new ChainHashMap<String, Integer>();
int n = 10;
for(int i = 0; i < n; ++i) {
map.put(Integer.toString(i), i);
}
assertEquals(n, map.size());
}
@Test
void testIsEmpty() {
ChainHashMap<String, Integer> map = new ChainHashMap<String, Integer>();
assertEquals(true, map.isEmpty());
int n = 10;
for(int i = 0; i < n; ++i) {
map.put(Integer.toString(i), i);
}
assertEquals(false, map.isEmpty());
}
@Test
void testKeySet() {
ChainHashMap<String, Integer> map = new ChainHashMap<String, Integer>();
map.put("one", 1);
map.put("two", 2);
map.put("three", 3);
ArrayList<String> buf = new ArrayList<>();
for(String s : map.keySet()) buf.add(s);
buf.sort(new DefaultComparator<String>());
assertEquals("[one, three, two]", buf.toString());
}
@Test
void testValues() {
ChainHashMap<String, Integer> map = new ChainHashMap<String, Integer>();
int n = 10;
for(int i = 0; i < n; ++i) {
map.put(Integer.toString(i), i);
}
ArrayList<Integer> buf = new ArrayList<>();
for(Integer s : map.values()) buf.add(s);
buf.sort(new DefaultComparator<Integer>());
assertEquals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]", buf.toString());
}
}