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

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,44 +17,44 @@ public class CustomSetTest {
17 17
     @Ignore("Remove to run test")
18 18
     @Test
19 19
     public void setsWithElementsAreNotEmpty() {
20
-        CustomSet<Integer> customSet = new CustomSet<>(Collections.singletonList(1));
20
+        CustomSet<Character> customSet = new CustomSet<>(Collections.singletonList('1'));
21 21
         assertFalse(customSet.isEmpty());
22 22
     }
23 23
 
24 24
     @Ignore("Remove to run test")
25 25
     @Test
26 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 31
     @Ignore("Remove to run test")
32 32
     @Test
33 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 38
     @Ignore("Remove to run test")
39 39
     @Test
40 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 45
     @Ignore("Remove to run test")
46 46
     @Test
47 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 50
         assertTrue(customSet.isSubset(secondCustomSet));
51 51
     }
52 52
 
53 53
     @Ignore("Remove to run test")
54 54
     @Test
55 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 58
         assertTrue(customSet.isSubset(secondCustomSet));
59 59
     }
60 60
 
@@ -85,16 +85,16 @@ public class CustomSetTest {
85 85
     @Ignore("Remove to run test")
86 86
     @Test
87 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 90
         assertFalse(customSet.isSubset(secondCustomSet));
91 91
     }
92 92
 
93 93
     @Ignore("Remove to run test")
94 94
     @Test
95 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 98
         assertTrue(customSet.isDisjoint(secondCustomSet));
99 99
     }
100 100
 
@@ -117,32 +117,32 @@ public class CustomSetTest {
117 117
     @Ignore("Remove to run test")
118 118
     @Test
119 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 122
         assertFalse(customSet.isDisjoint(secondCustomSet));
123 123
     }
124 124
 
125 125
     @Ignore("Remove to run test")
126 126
     @Test
127 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 130
         assertTrue(customSet.isDisjoint(secondCustomSet));
131 131
     }
132 132
 
133 133
     @Ignore("Remove to run test")
134 134
     @Test
135 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 138
         assertTrue(customSet.equals(secondCustomSet));
139 139
     }
140 140
 
141 141
     @Ignore("Remove to run test")
142 142
     @Test
143 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 146
         assertFalse(customSet.equals(secondCustomSet));
147 147
     }
148 148
 
@@ -157,25 +157,25 @@ public class CustomSetTest {
157 157
     @Ignore("Remove to run test")
158 158
     @Test
159 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 162
         assertTrue(customSet.equals(secondCustomSet));
163 163
     }
164 164
 
165 165
     @Ignore("Remove to run test")
166 166
     @Test
167 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 170
         assertFalse(customSet.equals(secondCustomSet));
171 171
     }
172 172
 
173 173
     @Ignore("Remove to run test")
174 174
     @Test
175 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 180
         actual.add(element);
181 181
 
@@ -187,9 +187,9 @@ public class CustomSetTest {
187 187
     @Ignore("Remove to run test")
188 188
     @Test
189 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 194
         actual.add(element);
195 195
 
@@ -224,8 +224,8 @@ public class CustomSetTest {
224 224
     @Ignore("Remove to run test")
225 225
     @Test
226 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 230
         assertNotNull(actual);
231 231
         assertTrue(actual.isEmpty());
@@ -234,7 +234,7 @@ public class CustomSetTest {
234 234
     @Ignore("Remove to run test")
235 235
     @Test
236 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 238
                 .getIntersection(new CustomSet<>(Collections.emptyList()));
239 239
 
240 240
         assertNotNull(actual);
@@ -255,9 +255,9 @@ public class CustomSetTest {
255 255
     @Ignore("Remove to run test")
256 256
     @Test
257 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 262
         assertNotNull(actual);
263 263
         assertFalse(actual.isEmpty());
@@ -267,7 +267,7 @@ public class CustomSetTest {
267 267
     @Ignore("Remove to run test")
268 268
     @Test
269 269
     public void differenceOfTwoEmptySetsIsAnEmptySet() {
270
-        CustomSet<Integer> actual = new CustomSet<Integer>(Collections.emptyList())
270
+        CustomSet<String> actual = new CustomSet<String>(Collections.emptyList())
271 271
                 .getDifference(new CustomSet<>(Collections.emptyList()));
272 272
 
273 273
         assertNotNull(actual);
@@ -277,8 +277,8 @@ public class CustomSetTest {
277 277
     @Ignore("Remove to run test")
278 278
     @Test
279 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 283
         assertNotNull(actual);
284 284
         assertTrue(actual.isEmpty());
@@ -287,8 +287,8 @@ public class CustomSetTest {
287 287
     @Ignore("Remove to run test")
288 288
     @Test
289 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 292
                 .getDifference(new CustomSet<>(Collections.emptyList()));
293 293
 
294 294
         assertNotNull(actual);
@@ -299,9 +299,9 @@ public class CustomSetTest {
299 299
     @Ignore("Remove to run test")
300 300
     @Test
301 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 306
         assertNotNull(actual);
307 307
         assertFalse(actual.isEmpty());
@@ -321,9 +321,9 @@ public class CustomSetTest {
321 321
     @Ignore("Remove to run test")
322 322
     @Test
323 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 328
         assertNotNull(actual);
329 329
         assertFalse(actual.isEmpty());
@@ -333,8 +333,8 @@ public class CustomSetTest {
333 333
     @Ignore("Remove to run test")
334 334
     @Test
335 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 338
                 .getUnion(new CustomSet<>(Collections.emptyList()));
339 339
 
340 340
         assertNotNull(actual);
@@ -345,9 +345,9 @@ public class CustomSetTest {
345 345
     @Ignore("Remove to run test")
346 346
     @Test
347 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 352
         assertNotNull(actual);
353 353
         assertFalse(actual.isEmpty());