Просмотр исходного кода

custom-set: pattern for generics in tests

Frida Tveit 9 лет назад
Родитель
Сommit
f37c602ca7
1 измененных файлов: 55 добавлений и 55 удалений
  1. 55
    55
      exercises/custom-set/src/test/java/CustomSetTest.java

+ 55
- 55
exercises/custom-set/src/test/java/CustomSetTest.java Просмотреть файл

17
     @Ignore("Remove to run test")
17
     @Ignore("Remove to run test")
18
     @Test
18
     @Test
19
     public void setsWithElementsAreNotEmpty() {
19
     public void setsWithElementsAreNotEmpty() {
20
-        CustomSet<Integer> customSet = new CustomSet<>(Collections.singletonList(1));
20
+        CustomSet<Character> customSet = new CustomSet<>(Collections.singletonList('1'));
21
         assertFalse(customSet.isEmpty());
21
         assertFalse(customSet.isEmpty());
22
     }
22
     }
23
 
23
 
24
     @Ignore("Remove to run test")
24
     @Ignore("Remove to run test")
25
     @Test
25
     @Test
26
     public void nothingIsContainedInAnEmptySet() {
26
     public void nothingIsContainedInAnEmptySet() {
27
-        CustomSet<Character> customSet = new CustomSet<>(Collections.emptyList());
28
-        assertFalse(customSet.contains('1'));
27
+        CustomSet<String> customSet = new CustomSet<>(Collections.emptyList());
28
+        assertFalse(customSet.contains("1"));
29
     }
29
     }
30
 
30
 
31
     @Ignore("Remove to run test")
31
     @Ignore("Remove to run test")
32
     @Test
32
     @Test
33
     public void whenTheElementIsInTheSet() {
33
     public void whenTheElementIsInTheSet() {
34
-        CustomSet<String> customSet = new CustomSet<>(Arrays.asList("1", "2", "3"));
35
-        assertTrue(customSet.contains("1"));
34
+        CustomSet<Integer> customSet = new CustomSet<>(Arrays.asList(1, 2, 3));
35
+        assertTrue(customSet.contains(1));
36
     }
36
     }
37
 
37
 
38
     @Ignore("Remove to run test")
38
     @Ignore("Remove to run test")
39
     @Test
39
     @Test
40
     public void whenTheElementIsNotInTheSet() {
40
     public void whenTheElementIsNotInTheSet() {
41
-        CustomSet<Integer> customSet = new CustomSet<>(Arrays.asList(1, 2, 3));
42
-        assertFalse(customSet.contains(4));
41
+        CustomSet<Character> customSet = new CustomSet<>(Arrays.asList('1', '2', '3'));
42
+        assertFalse(customSet.contains('4'));
43
     }
43
     }
44
 
44
 
45
     @Ignore("Remove to run test")
45
     @Ignore("Remove to run test")
46
     @Test
46
     @Test
47
     public void emptySetIsASubsetOfAnotherEmptySet() {
47
     public void emptySetIsASubsetOfAnotherEmptySet() {
48
-        CustomSet<Integer> customSet = new CustomSet<>(Collections.emptyList());
49
-        CustomSet<Integer> secondCustomSet = new CustomSet<>(Collections.emptyList());
48
+        CustomSet<String> customSet = new CustomSet<>(Collections.emptyList());
49
+        CustomSet<String> secondCustomSet = new CustomSet<>(Collections.emptyList());
50
         assertTrue(customSet.isSubset(secondCustomSet));
50
         assertTrue(customSet.isSubset(secondCustomSet));
51
     }
51
     }
52
 
52
 
53
     @Ignore("Remove to run test")
53
     @Ignore("Remove to run test")
54
     @Test
54
     @Test
55
     public void emptySetIsASubsetOfNonEmptySet() {
55
     public void emptySetIsASubsetOfNonEmptySet() {
56
-        CustomSet<Character> customSet = new CustomSet<>(Collections.singletonList('1'));
57
-        CustomSet<Character> secondCustomSet = new CustomSet<>(Collections.emptyList());
56
+        CustomSet<Integer> customSet = new CustomSet<>(Collections.singletonList(1));
57
+        CustomSet<Integer> secondCustomSet = new CustomSet<>(Collections.emptyList());
58
         assertTrue(customSet.isSubset(secondCustomSet));
58
         assertTrue(customSet.isSubset(secondCustomSet));
59
     }
59
     }
60
 
60
 
85
     @Ignore("Remove to run test")
85
     @Ignore("Remove to run test")
86
     @Test
86
     @Test
87
     public void setIsNotASubsetOfSetThatDoesNotContainItsElements() {
87
     public void setIsNotASubsetOfSetThatDoesNotContainItsElements() {
88
-        CustomSet<Integer> customSet = new CustomSet<>(Arrays.asList(4, 1, 3));
89
-        CustomSet<Integer> secondCustomSet = new CustomSet<>(Arrays.asList(1, 2, 3));
88
+        CustomSet<Character> customSet = new CustomSet<>(Arrays.asList('4', '1', '3'));
89
+        CustomSet<Character> secondCustomSet = new CustomSet<>(Arrays.asList('1', '2', '3'));
90
         assertFalse(customSet.isSubset(secondCustomSet));
90
         assertFalse(customSet.isSubset(secondCustomSet));
91
     }
91
     }
92
 
92
 
93
     @Ignore("Remove to run test")
93
     @Ignore("Remove to run test")
94
     @Test
94
     @Test
95
     public void theEmptySetIsDisjointWithItself() {
95
     public void theEmptySetIsDisjointWithItself() {
96
-        CustomSet<Integer> customSet = new CustomSet<>(Collections.emptyList());
97
-        CustomSet<Integer> secondCustomSet = new CustomSet<>(Collections.emptyList());
96
+        CustomSet<String> customSet = new CustomSet<>(Collections.emptyList());
97
+        CustomSet<String> secondCustomSet = new CustomSet<>(Collections.emptyList());
98
         assertTrue(customSet.isDisjoint(secondCustomSet));
98
         assertTrue(customSet.isDisjoint(secondCustomSet));
99
     }
99
     }
100
 
100
 
117
     @Ignore("Remove to run test")
117
     @Ignore("Remove to run test")
118
     @Test
118
     @Test
119
     public void setsAreNotDisjointIfTheyShareAnElement() {
119
     public void setsAreNotDisjointIfTheyShareAnElement() {
120
-        CustomSet<Character> customSet = new CustomSet<>(Arrays.asList('1', '2'));
121
-        CustomSet<Character> secondCustomSet = new CustomSet<>(Arrays.asList('2', '3'));
120
+        CustomSet<String> customSet = new CustomSet<>(Arrays.asList("1", "2"));
121
+        CustomSet<String> secondCustomSet = new CustomSet<>(Arrays.asList("2", "3"));
122
         assertFalse(customSet.isDisjoint(secondCustomSet));
122
         assertFalse(customSet.isDisjoint(secondCustomSet));
123
     }
123
     }
124
 
124
 
125
     @Ignore("Remove to run test")
125
     @Ignore("Remove to run test")
126
     @Test
126
     @Test
127
     public void setsAreDisjointIfTheyShareNoElements() {
127
     public void setsAreDisjointIfTheyShareNoElements() {
128
-        CustomSet<String> customSet = new CustomSet<>(Arrays.asList("1", "2"));
129
-        CustomSet<String> secondCustomSet = new CustomSet<>(Arrays.asList("3", "4"));
128
+        CustomSet<Integer> customSet = new CustomSet<>(Arrays.asList(1, 2));
129
+        CustomSet<Integer> secondCustomSet = new CustomSet<>(Arrays.asList(3, 4));
130
         assertTrue(customSet.isDisjoint(secondCustomSet));
130
         assertTrue(customSet.isDisjoint(secondCustomSet));
131
     }
131
     }
132
 
132
 
133
     @Ignore("Remove to run test")
133
     @Ignore("Remove to run test")
134
     @Test
134
     @Test
135
     public void emptySetsAreEqual() {
135
     public void emptySetsAreEqual() {
136
-        CustomSet<String> customSet = new CustomSet<>(Collections.emptyList());
137
-        CustomSet<String> secondCustomSet = new CustomSet<>(Collections.emptyList());
136
+        CustomSet<Character> customSet = new CustomSet<>(Collections.emptyList());
137
+        CustomSet<Character> secondCustomSet = new CustomSet<>(Collections.emptyList());
138
         assertTrue(customSet.equals(secondCustomSet));
138
         assertTrue(customSet.equals(secondCustomSet));
139
     }
139
     }
140
 
140
 
141
     @Ignore("Remove to run test")
141
     @Ignore("Remove to run test")
142
     @Test
142
     @Test
143
     public void emptySetIsNotEqualToNonEmptySet() {
143
     public void emptySetIsNotEqualToNonEmptySet() {
144
-        CustomSet<Integer> customSet = new CustomSet<>(Collections.emptyList());
145
-        CustomSet<Integer> secondCustomSet = new CustomSet<>(Arrays.asList(1, 2, 3));
144
+        CustomSet<String> customSet = new CustomSet<>(Collections.emptyList());
145
+        CustomSet<String> secondCustomSet = new CustomSet<>(Arrays.asList("1", "2", "3"));
146
         assertFalse(customSet.equals(secondCustomSet));
146
         assertFalse(customSet.equals(secondCustomSet));
147
     }
147
     }
148
 
148
 
157
     @Ignore("Remove to run test")
157
     @Ignore("Remove to run test")
158
     @Test
158
     @Test
159
     public void setsWithTheSameElementsAreEqual() {
159
     public void setsWithTheSameElementsAreEqual() {
160
-        CustomSet<Integer> customSet = new CustomSet<>(Arrays.asList(1, 2));
161
-        CustomSet<Integer> secondCustomSet = new CustomSet<>(Arrays.asList(2, 1));
160
+        CustomSet<Character> customSet = new CustomSet<>(Arrays.asList('1', '2'));
161
+        CustomSet<Character> secondCustomSet = new CustomSet<>(Arrays.asList('2', '1'));
162
         assertTrue(customSet.equals(secondCustomSet));
162
         assertTrue(customSet.equals(secondCustomSet));
163
     }
163
     }
164
 
164
 
165
     @Ignore("Remove to run test")
165
     @Ignore("Remove to run test")
166
     @Test
166
     @Test
167
     public void setsWithDifferentElementsAreNotEqual() {
167
     public void setsWithDifferentElementsAreNotEqual() {
168
-        CustomSet<Integer> customSet = new CustomSet<>(Arrays.asList(1, 2, 3));
169
-        CustomSet<Integer> secondCustomSet = new CustomSet<>(Arrays.asList(2, 1, 4));
168
+        CustomSet<String> customSet = new CustomSet<>(Arrays.asList("1", "2", "3"));
169
+        CustomSet<String> secondCustomSet = new CustomSet<>(Arrays.asList("1", "2", "4"));
170
         assertFalse(customSet.equals(secondCustomSet));
170
         assertFalse(customSet.equals(secondCustomSet));
171
     }
171
     }
172
 
172
 
173
     @Ignore("Remove to run test")
173
     @Ignore("Remove to run test")
174
     @Test
174
     @Test
175
     public void addToEmptySet() {
175
     public void addToEmptySet() {
176
-        char element = '3';
177
-        CustomSet<Character> expected = new CustomSet<>(Collections.unmodifiableList(Collections.singletonList(element)));
178
-        CustomSet<Character> actual = new CustomSet<>(Collections.emptyList());
176
+        int element = 3;
177
+        CustomSet<Integer> expected = new CustomSet<>(Collections.unmodifiableList(Collections.singletonList(element)));
178
+        CustomSet<Integer> actual = new CustomSet<>(Collections.emptyList());
179
 
179
 
180
         actual.add(element);
180
         actual.add(element);
181
 
181
 
187
     @Ignore("Remove to run test")
187
     @Ignore("Remove to run test")
188
     @Test
188
     @Test
189
     public void addToNonEmptySet() {
189
     public void addToNonEmptySet() {
190
-        int element = 3;
191
-        CustomSet<Integer> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList(1, 2, 3, 4)));
192
-        CustomSet<Integer> actual = new CustomSet<>(Arrays.asList(1, 2, 4));
190
+        char element = '3';
191
+        CustomSet<Character> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList('1', '2', '3', '4')));
192
+        CustomSet<Character> actual = new CustomSet<>(Arrays.asList('1', '2', '4'));
193
 
193
 
194
         actual.add(element);
194
         actual.add(element);
195
 
195
 
224
     @Ignore("Remove to run test")
224
     @Ignore("Remove to run test")
225
     @Test
225
     @Test
226
     public void intersectionOfAnEmptySetAndNonEmptySetIsAnEmptySet() {
226
     public void intersectionOfAnEmptySetAndNonEmptySetIsAnEmptySet() {
227
-        CustomSet<Integer> actual = new CustomSet<Integer>(Collections.emptyList())
228
-                .getIntersection(new CustomSet<>(Arrays.asList(3, 2, 5)));
227
+        CustomSet<Character> actual = new CustomSet<Character>(Collections.emptyList())
228
+                .getIntersection(new CustomSet<>(Arrays.asList('3', '2', '5')));
229
 
229
 
230
         assertNotNull(actual);
230
         assertNotNull(actual);
231
         assertTrue(actual.isEmpty());
231
         assertTrue(actual.isEmpty());
234
     @Ignore("Remove to run test")
234
     @Ignore("Remove to run test")
235
     @Test
235
     @Test
236
     public void intersectionOfANonEmptySetAndAnEmptySetIsAnEmptySet() {
236
     public void intersectionOfANonEmptySetAndAnEmptySetIsAnEmptySet() {
237
-        CustomSet<Character> actual = new CustomSet<>(Arrays.asList('1', '2', '3', '4'))
237
+        CustomSet<String> actual = new CustomSet<>(Arrays.asList("1", "2", "3", "4"))
238
                 .getIntersection(new CustomSet<>(Collections.emptyList()));
238
                 .getIntersection(new CustomSet<>(Collections.emptyList()));
239
 
239
 
240
         assertNotNull(actual);
240
         assertNotNull(actual);
255
     @Ignore("Remove to run test")
255
     @Ignore("Remove to run test")
256
     @Test
256
     @Test
257
     public void intersectionOfTwoSetsWithSharedElementsIsASetOfTheSharedElements() {
257
     public void intersectionOfTwoSetsWithSharedElementsIsASetOfTheSharedElements() {
258
-        CustomSet<Integer> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList(2, 3)));
259
-        CustomSet<Integer> actual = new CustomSet<>(Arrays.asList(1, 2, 3, 4))
260
-                .getIntersection(new CustomSet<>(Arrays.asList(3, 2, 5)));
258
+        CustomSet<Character> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList('2', '3')));
259
+        CustomSet<Character> actual = new CustomSet<>(Arrays.asList('1', '2', '3', '4'))
260
+                .getIntersection(new CustomSet<>(Arrays.asList('3', '2', '5')));
261
 
261
 
262
         assertNotNull(actual);
262
         assertNotNull(actual);
263
         assertFalse(actual.isEmpty());
263
         assertFalse(actual.isEmpty());
267
     @Ignore("Remove to run test")
267
     @Ignore("Remove to run test")
268
     @Test
268
     @Test
269
     public void differenceOfTwoEmptySetsIsAnEmptySet() {
269
     public void differenceOfTwoEmptySetsIsAnEmptySet() {
270
-        CustomSet<Integer> actual = new CustomSet<Integer>(Collections.emptyList())
270
+        CustomSet<String> actual = new CustomSet<String>(Collections.emptyList())
271
                 .getDifference(new CustomSet<>(Collections.emptyList()));
271
                 .getDifference(new CustomSet<>(Collections.emptyList()));
272
 
272
 
273
         assertNotNull(actual);
273
         assertNotNull(actual);
277
     @Ignore("Remove to run test")
277
     @Ignore("Remove to run test")
278
     @Test
278
     @Test
279
     public void differenceOfAnEmptySetAndNonEmptySetIsAnEmptySet() {
279
     public void differenceOfAnEmptySetAndNonEmptySetIsAnEmptySet() {
280
-        CustomSet<String> actual = new CustomSet<String>(Collections.emptyList())
281
-                .getDifference(new CustomSet<>(Arrays.asList("3", "2", "5")));
280
+        CustomSet<Integer> actual = new CustomSet<Integer>(Collections.emptyList())
281
+                .getDifference(new CustomSet<>(Arrays.asList(3, 2, 5)));
282
 
282
 
283
         assertNotNull(actual);
283
         assertNotNull(actual);
284
         assertTrue(actual.isEmpty());
284
         assertTrue(actual.isEmpty());
287
     @Ignore("Remove to run test")
287
     @Ignore("Remove to run test")
288
     @Test
288
     @Test
289
     public void differenceOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() {
289
     public void differenceOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() {
290
-        CustomSet<Integer> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList(1, 2, 3, 4)));
291
-        CustomSet<Integer> actual = new CustomSet<>(Arrays.asList(1, 2, 3, 4))
290
+        CustomSet<Character> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList('1', '2', '3', '4')));
291
+        CustomSet<Character> actual = new CustomSet<>(Arrays.asList('1', '2', '3', '4'))
292
                 .getDifference(new CustomSet<>(Collections.emptyList()));
292
                 .getDifference(new CustomSet<>(Collections.emptyList()));
293
 
293
 
294
         assertNotNull(actual);
294
         assertNotNull(actual);
299
     @Ignore("Remove to run test")
299
     @Ignore("Remove to run test")
300
     @Test
300
     @Test
301
     public void differenceOfTwoNonEmptySetsIsASetOfElementsThatAreOnlyInTheFirstSet() {
301
     public void differenceOfTwoNonEmptySetsIsASetOfElementsThatAreOnlyInTheFirstSet() {
302
-        CustomSet<Integer> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList(1, 3)));
303
-        CustomSet<Integer> actual = new CustomSet<>(Arrays.asList(3, 2, 1))
304
-                .getDifference(new CustomSet<>(Arrays.asList(2, 4)));
302
+        CustomSet<String> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList("1", "3")));
303
+        CustomSet<String> actual = new CustomSet<>(Arrays.asList("3", "2", "1"))
304
+                .getDifference(new CustomSet<>(Arrays.asList("2", "4")));
305
 
305
 
306
         assertNotNull(actual);
306
         assertNotNull(actual);
307
         assertFalse(actual.isEmpty());
307
         assertFalse(actual.isEmpty());
321
     @Ignore("Remove to run test")
321
     @Ignore("Remove to run test")
322
     @Test
322
     @Test
323
     public void unionOfAnEmptySetAndNonEmptySetIsTheNonEmptySet() {
323
     public void unionOfAnEmptySetAndNonEmptySetIsTheNonEmptySet() {
324
-        CustomSet<Integer> expected = new CustomSet<>(Collections.unmodifiableList(Collections.singletonList(2)));
325
-        CustomSet<Integer> actual = new CustomSet<Integer>(Collections.emptyList())
326
-                .getUnion(new CustomSet<>(Collections.singletonList(2)));
324
+        CustomSet<Character> expected = new CustomSet<>(Collections.unmodifiableList(Collections.singletonList('2')));
325
+        CustomSet<Character> actual = new CustomSet<Character>(Collections.emptyList())
326
+                .getUnion(new CustomSet<>(Collections.singletonList('2')));
327
 
327
 
328
         assertNotNull(actual);
328
         assertNotNull(actual);
329
         assertFalse(actual.isEmpty());
329
         assertFalse(actual.isEmpty());
333
     @Ignore("Remove to run test")
333
     @Ignore("Remove to run test")
334
     @Test
334
     @Test
335
     public void unionOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() {
335
     public void unionOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() {
336
-        CustomSet<Integer> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList(1, 3)));
337
-        CustomSet<Integer> actual = new CustomSet<>(Arrays.asList(1, 3))
336
+        CustomSet<String> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList("1", "3")));
337
+        CustomSet<String> actual = new CustomSet<>(Arrays.asList("1", "3"))
338
                 .getUnion(new CustomSet<>(Collections.emptyList()));
338
                 .getUnion(new CustomSet<>(Collections.emptyList()));
339
 
339
 
340
         assertNotNull(actual);
340
         assertNotNull(actual);
345
     @Ignore("Remove to run test")
345
     @Ignore("Remove to run test")
346
     @Test
346
     @Test
347
     public void unionOfTwoNonEmptySetsContainsAllUniqueElements() {
347
     public void unionOfTwoNonEmptySetsContainsAllUniqueElements() {
348
-        CustomSet<Character> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList('3', '2', '1')));
349
-        CustomSet<Character> actual = new CustomSet<>(Arrays.asList('1', '3'))
350
-                .getUnion(new CustomSet<>(Arrays.asList('2', '3')));
348
+        CustomSet<Integer> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList(3, 2, 1)));
349
+        CustomSet<Integer> actual = new CustomSet<>(Arrays.asList(1, 3))
350
+                .getUnion(new CustomSet<>(Arrays.asList(2, 3)));
351
 
351
 
352
         assertNotNull(actual);
352
         assertNotNull(actual);
353
         assertFalse(actual.isEmpty());
353
         assertFalse(actual.isEmpty());