|
@@ -175,56 +175,56 @@ public class MyHashMapTest {
|
175
|
175
|
}
|
176
|
176
|
|
177
|
177
|
// I commented this out because it takes a long time to run. Uncomment it when implement your put method, uncomment this test
|
178
|
|
-// @Test
|
179
|
|
-// public void testPutAndGet_WithManyItems(){
|
180
|
|
-// // Given
|
181
|
|
-// int numberOfEntries = 70000;
|
182
|
|
-//
|
183
|
|
-// for (int i = 0; i < numberOfEntries; i++) {
|
184
|
|
-// myMap.put(new User(i), new Cart(i));
|
185
|
|
-// }
|
186
|
|
-//
|
187
|
|
-//
|
188
|
|
-// for (int i = 0; i < numberOfEntries; i++) {
|
189
|
|
-// // When
|
190
|
|
-// Cart actualCart = myMap.get(new User(i));
|
191
|
|
-// Cart expectedCart = new Cart(i);
|
192
|
|
-//
|
193
|
|
-// // Then
|
194
|
|
-// Assert.assertEquals(actualCart, expectedCart);
|
195
|
|
-// }
|
196
|
|
-// }
|
197
|
|
-
|
198
|
|
-// @Test
|
199
|
|
-// public void testRemove(){
|
200
|
|
-// // Given
|
201
|
|
-// User user1 = new User("Lena");
|
202
|
|
-// Cart cart1 = new Cart(11);
|
203
|
|
-//
|
204
|
|
-// User user2 = new User("Jamal");
|
205
|
|
-// Cart cart2 = new Cart(21);
|
206
|
|
-//
|
207
|
|
-// User user3 = new User("Kelvin");
|
208
|
|
-// Cart cart3 = new Cart(31);
|
209
|
|
-//
|
210
|
|
-// // When
|
211
|
|
-// myMap.put(user1, cart1);
|
212
|
|
-// myMap.put(user2, cart2);
|
213
|
|
-// myMap.put(user3, cart3);
|
214
|
|
-//
|
215
|
|
-// // Then
|
216
|
|
-// Cart actualCart = myMap.remove(user2);
|
217
|
|
-//
|
218
|
|
-// Assert.assertEquals(cart2, actualCart);
|
219
|
|
-// Assert.assertNull(myMap.get(user2));
|
220
|
|
-// }
|
221
|
|
-//
|
222
|
|
-// @Test
|
223
|
|
-// public void testRemove_CartNotInTheMap(){
|
224
|
|
-// // Given
|
225
|
|
-// User user1 = new User("Lena");
|
226
|
|
-//
|
227
|
|
-// // When & Then
|
228
|
|
-// Assert.assertNull(myMap.remove(user1));
|
229
|
|
-// }
|
|
178
|
+ @Test
|
|
179
|
+ public void testPutAndGet_WithManyItems(){
|
|
180
|
+ // Given
|
|
181
|
+ int numberOfEntries = 70000;
|
|
182
|
+
|
|
183
|
+ for (int i = 0; i < numberOfEntries; i++) {
|
|
184
|
+ myMap.put(new User(i), new Cart(i));
|
|
185
|
+ }
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+ for (int i = 0; i < numberOfEntries; i++) {
|
|
189
|
+ // When
|
|
190
|
+ Cart actualCart = myMap.get(new User(i));
|
|
191
|
+ Cart expectedCart = new Cart(i);
|
|
192
|
+
|
|
193
|
+ // Then
|
|
194
|
+ Assert.assertEquals(actualCart, expectedCart);
|
|
195
|
+ }
|
|
196
|
+ }
|
|
197
|
+
|
|
198
|
+ @Test
|
|
199
|
+ public void testRemove(){
|
|
200
|
+ // Given
|
|
201
|
+ User user1 = new User("Lena");
|
|
202
|
+ Cart cart1 = new Cart(11);
|
|
203
|
+
|
|
204
|
+ User user2 = new User("Jamal");
|
|
205
|
+ Cart cart2 = new Cart(21);
|
|
206
|
+
|
|
207
|
+ User user3 = new User("Kelvin");
|
|
208
|
+ Cart cart3 = new Cart(31);
|
|
209
|
+
|
|
210
|
+ // When
|
|
211
|
+ myMap.put(user1, cart1);
|
|
212
|
+ myMap.put(user2, cart2);
|
|
213
|
+ myMap.put(user3, cart3);
|
|
214
|
+
|
|
215
|
+ // Then
|
|
216
|
+ Cart actualCart = myMap.remove(user2);
|
|
217
|
+
|
|
218
|
+ Assert.assertEquals(cart2, actualCart);
|
|
219
|
+ Assert.assertNull(myMap.get(user2));
|
|
220
|
+ }
|
|
221
|
+
|
|
222
|
+ @Test
|
|
223
|
+ public void testRemove_CartNotInTheMap(){
|
|
224
|
+ // Given
|
|
225
|
+ User user1 = new User("Lena");
|
|
226
|
+
|
|
227
|
+ // When & Then
|
|
228
|
+ Assert.assertNull(myMap.remove(user1));
|
|
229
|
+ }
|
230
|
230
|
}
|