Skip to content

Commit a15e186

Browse files
committed
custom-set, darts, diamond, difference-of-squares
1 parent 2dcd936 commit a15e186

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

exercises/practice/custom-set/src/test/java/CustomSetTest.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import org.junit.jupiter.api.Disabled;
2+
import org.junit.jupiter.api.DisplayName;
23
import org.junit.jupiter.api.Test;
34

45
import java.util.Arrays;
@@ -9,41 +10,47 @@
910
public class CustomSetTest {
1011

1112
@Test
13+
@DisplayName("Returns true if the set contains no elements")
1214
public void setsWithNoElementsAreEmpty() {
1315
CustomSet<Integer> customSet = new CustomSet<>(Collections.emptyList());
1416
assertThat(customSet.isEmpty()).isTrue();
1517
}
1618

1719
@Disabled("Remove to run test")
1820
@Test
21+
@DisplayName("sets with elements are not empty")
1922
public void setsWithElementsAreNotEmpty() {
2023
CustomSet<Character> customSet = new CustomSet<>(Collections.singletonList('1'));
2124
assertThat(customSet.isEmpty()).isFalse();
2225
}
2326

2427
@Disabled("Remove to run test")
2528
@Test
29+
@DisplayName("nothing is contained in an empty set")
2630
public void nothingIsContainedInAnEmptySet() {
2731
CustomSet<String> customSet = new CustomSet<>(Collections.emptyList());
2832
assertThat(customSet.contains("1")).isFalse();
2933
}
3034

3135
@Disabled("Remove to run test")
3236
@Test
37+
@DisplayName("when the element is in the set")
3338
public void whenTheElementIsInTheSet() {
3439
CustomSet<Integer> customSet = new CustomSet<>(Arrays.asList(1, 2, 3));
3540
assertThat(customSet.contains(1)).isTrue();
3641
}
3742

3843
@Disabled("Remove to run test")
3944
@Test
45+
@DisplayName("when the element is not in the set")
4046
public void whenTheElementIsNotInTheSet() {
4147
CustomSet<Character> customSet = new CustomSet<>(Arrays.asList('1', '2', '3'));
4248
assertThat(customSet.contains('4')).isFalse();
4349
}
4450

4551
@Disabled("Remove to run test")
4652
@Test
53+
@DisplayName("empty set is a subset of another empty set")
4754
public void emptySetIsASubsetOfAnotherEmptySet() {
4855
CustomSet<String> customSet = new CustomSet<>(Collections.emptyList());
4956
CustomSet<String> secondCustomSet = new CustomSet<>(Collections.emptyList());
@@ -52,6 +59,7 @@ public void emptySetIsASubsetOfAnotherEmptySet() {
5259

5360
@Disabled("Remove to run test")
5461
@Test
62+
@DisplayName("empty set is a subset of non-empty set")
5563
public void emptySetIsASubsetOfNonEmptySet() {
5664
CustomSet<Integer> customSet = new CustomSet<>(Collections.singletonList(1));
5765
CustomSet<Integer> secondCustomSet = new CustomSet<>(Collections.emptyList());
@@ -60,6 +68,7 @@ public void emptySetIsASubsetOfNonEmptySet() {
6068

6169
@Disabled("Remove to run test")
6270
@Test
71+
@DisplayName("non-empty set is not a subset of empty set")
6372
public void nonEmptySetIsNotASubsetOfEmptySet() {
6473
CustomSet<Character> customSet = new CustomSet<>(Collections.emptyList());
6574
CustomSet<Character> secondCustomSet = new CustomSet<>(Collections.singletonList('1'));
@@ -68,6 +77,7 @@ public void nonEmptySetIsNotASubsetOfEmptySet() {
6877

6978
@Disabled("Remove to run test")
7079
@Test
80+
@DisplayName("set is a subset of set with exact same elements")
7181
public void setIsASubsetOfSetWithExactSameElements() {
7282
CustomSet<String> customSet = new CustomSet<>(Arrays.asList("1", "2", "3"));
7383
CustomSet<String> secondCustomSet = new CustomSet<>(Arrays.asList("1", "2", "3"));
@@ -76,6 +86,7 @@ public void setIsASubsetOfSetWithExactSameElements() {
7686

7787
@Disabled("Remove to run test")
7888
@Test
89+
@DisplayName("set is a subset of larger set with same elements")
7990
public void setIsASubsetOfLargerSetWithSameElements() {
8091
CustomSet<Integer> customSet = new CustomSet<>(Arrays.asList(4, 1, 2, 3));
8192
CustomSet<Integer> secondCustomSet = new CustomSet<>(Arrays.asList(1, 2, 3));
@@ -84,6 +95,7 @@ public void setIsASubsetOfLargerSetWithSameElements() {
8495

8596
@Disabled("Remove to run test")
8697
@Test
98+
@DisplayName("set is not a subset of set that does not contain its elements")
8799
public void setIsNotASubsetOfSetThatDoesNotContainItsElements() {
88100
CustomSet<Character> customSet = new CustomSet<>(Arrays.asList('4', '1', '3'));
89101
CustomSet<Character> secondCustomSet = new CustomSet<>(Arrays.asList('1', '2', '3'));
@@ -92,6 +104,7 @@ public void setIsNotASubsetOfSetThatDoesNotContainItsElements() {
92104

93105
@Disabled("Remove to run test")
94106
@Test
107+
@DisplayName("the empty set is disjoint with itself")
95108
public void theEmptySetIsDisjointWithItself() {
96109
CustomSet<String> customSet = new CustomSet<>(Collections.emptyList());
97110
CustomSet<String> secondCustomSet = new CustomSet<>(Collections.emptyList());
@@ -100,6 +113,7 @@ public void theEmptySetIsDisjointWithItself() {
100113

101114
@Disabled("Remove to run test")
102115
@Test
116+
@DisplayName("empty set is disjoint with non-empty set")
103117
public void emptySetIsDisjointWithNonEmptySet() {
104118
CustomSet<Integer> customSet = new CustomSet<>(Collections.emptyList());
105119
CustomSet<Integer> secondCustomSet = new CustomSet<>(Collections.singletonList(1));
@@ -108,6 +122,7 @@ public void emptySetIsDisjointWithNonEmptySet() {
108122

109123
@Disabled("Remove to run test")
110124
@Test
125+
@DisplayName("non-empty set is disjoint with empty set")
111126
public void nonEmptySetIsDisjointWithEmptySet() {
112127
CustomSet<Character> customSet = new CustomSet<>(Collections.singletonList('1'));
113128
CustomSet<Character> secondCustomSet = new CustomSet<>(Collections.emptyList());
@@ -116,6 +131,7 @@ public void nonEmptySetIsDisjointWithEmptySet() {
116131

117132
@Disabled("Remove to run test")
118133
@Test
134+
@DisplayName("sets are not disjoint if they share an element")
119135
public void setsAreNotDisjointIfTheyShareAnElement() {
120136
CustomSet<String> customSet = new CustomSet<>(Arrays.asList("1", "2"));
121137
CustomSet<String> secondCustomSet = new CustomSet<>(Arrays.asList("2", "3"));
@@ -124,6 +140,7 @@ public void setsAreNotDisjointIfTheyShareAnElement() {
124140

125141
@Disabled("Remove to run test")
126142
@Test
143+
@DisplayName("sets are disjoint if they share no elements")
127144
public void setsAreDisjointIfTheyShareNoElements() {
128145
CustomSet<Integer> customSet = new CustomSet<>(Arrays.asList(1, 2));
129146
CustomSet<Integer> secondCustomSet = new CustomSet<>(Arrays.asList(3, 4));
@@ -132,6 +149,7 @@ public void setsAreDisjointIfTheyShareNoElements() {
132149

133150
@Disabled("Remove to run test")
134151
@Test
152+
@DisplayName("empty sets are equal")
135153
public void emptySetsAreEqual() {
136154
CustomSet<Character> customSet = new CustomSet<>(Collections.emptyList());
137155
CustomSet<Character> secondCustomSet = new CustomSet<>(Collections.emptyList());
@@ -140,6 +158,7 @@ public void emptySetsAreEqual() {
140158

141159
@Disabled("Remove to run test")
142160
@Test
161+
@DisplayName("empty set is not equal to non-empty set")
143162
public void emptySetIsNotEqualToNonEmptySet() {
144163
CustomSet<String> customSet = new CustomSet<>(Collections.emptyList());
145164
CustomSet<String> secondCustomSet = new CustomSet<>(Arrays.asList("1", "2", "3"));
@@ -148,6 +167,7 @@ public void emptySetIsNotEqualToNonEmptySet() {
148167

149168
@Disabled("Remove to run test")
150169
@Test
170+
@DisplayName("non-empty set is not equal to empty set")
151171
public void nonEmptySetIsNotEqualToEmptySet() {
152172
CustomSet<Integer> customSet = new CustomSet<>(Arrays.asList(1, 2, 3));
153173
CustomSet<Integer> secondCustomSet = new CustomSet<>(Collections.emptyList());
@@ -156,6 +176,7 @@ public void nonEmptySetIsNotEqualToEmptySet() {
156176

157177
@Disabled("Remove to run test")
158178
@Test
179+
@DisplayName("sets with the same elements are equal")
159180
public void setsWithTheSameElementsAreEqual() {
160181
CustomSet<Character> customSet = new CustomSet<>(Arrays.asList('1', '2'));
161182
CustomSet<Character> secondCustomSet = new CustomSet<>(Arrays.asList('2', '1'));
@@ -164,6 +185,7 @@ public void setsWithTheSameElementsAreEqual() {
164185

165186
@Disabled("Remove to run test")
166187
@Test
188+
@DisplayName("sets with different elements are not equal")
167189
public void setsWithDifferentElementsAreNotEqual() {
168190
CustomSet<String> customSet = new CustomSet<>(Arrays.asList("1", "2", "3"));
169191
CustomSet<String> secondCustomSet = new CustomSet<>(Arrays.asList("1", "2", "4"));
@@ -172,6 +194,7 @@ public void setsWithDifferentElementsAreNotEqual() {
172194

173195
@Disabled("Remove to run test")
174196
@Test
197+
@DisplayName("set is not equal to larger set with same elements")
175198
public void setIsNotEqualToLargerSetWithSameElements() {
176199
CustomSet<String> customSet = new CustomSet<>(Arrays.asList("1", "2", "3"));
177200
CustomSet<String> secondCustomSet = new CustomSet<>(Arrays.asList("1", "2", "3", "4"));
@@ -180,6 +203,7 @@ public void setIsNotEqualToLargerSetWithSameElements() {
180203

181204
@Disabled("Remove to run test")
182205
@Test
206+
@DisplayName("set is equal to a set constructed from an array with duplicates")
183207
public void secondSetWithDuplicatesIsEqualToFirstSet() {
184208
CustomSet<String> customSet = new CustomSet<>(Collections.singletonList("1"));
185209
CustomSet<String> secondCustomSet = new CustomSet<>(Arrays.asList("1", "1"));
@@ -188,6 +212,7 @@ public void secondSetWithDuplicatesIsEqualToFirstSet() {
188212

189213
@Disabled("Remove to run test")
190214
@Test
215+
@DisplayName("difference removes all duplicates in the first set")
191216
public void firstSetWithDuplicatesIsEqualToSecondSet() {
192217
CustomSet<String> customSet = new CustomSet<>(Arrays.asList("1", "1"));
193218
CustomSet<String> secondCustomSet = new CustomSet<>(Collections.singletonList("1"));
@@ -196,6 +221,7 @@ public void firstSetWithDuplicatesIsEqualToSecondSet() {
196221

197222
@Disabled("Remove to run test")
198223
@Test
224+
@DisplayName("add to empty set")
199225
public void addToEmptySet() {
200226
int element = 3;
201227
CustomSet<Integer> expected = new CustomSet<>(Collections.unmodifiableList(Collections.singletonList(element)));
@@ -211,6 +237,7 @@ public void addToEmptySet() {
211237

212238
@Disabled("Remove to run test")
213239
@Test
240+
@DisplayName("add to non-empty set")
214241
public void addToNonEmptySet() {
215242
char element = '3';
216243
CustomSet<Character> expected = new CustomSet<>(Collections.unmodifiableList(
@@ -226,6 +253,7 @@ public void addToNonEmptySet() {
226253

227254
@Disabled("Remove to run test")
228255
@Test
256+
@DisplayName("adding an existing element does not change the set")
229257
public void addingAnExistingElementDoesNotChangeTheSet() {
230258
String element = "3";
231259
CustomSet<String> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList("1", "2", "3")));
@@ -239,6 +267,7 @@ public void addingAnExistingElementDoesNotChangeTheSet() {
239267

240268
@Disabled("Remove to run test")
241269
@Test
270+
@DisplayName("intersection of two empty sets is an empty set")
242271
public void intersectionOfTwoEmptySetsIsAnEmptySet() {
243272
CustomSet<Integer> actual = new CustomSet<Integer>(Collections.emptyList())
244273
.getIntersection(new CustomSet<>(Collections.emptyList()));
@@ -249,6 +278,7 @@ public void intersectionOfTwoEmptySetsIsAnEmptySet() {
249278

250279
@Disabled("Remove to run test")
251280
@Test
281+
@DisplayName("intersection of an empty set and non-empty set is an empty set")
252282
public void intersectionOfAnEmptySetAndNonEmptySetIsAnEmptySet() {
253283
CustomSet<Character> actual = new CustomSet<Character>(Collections.emptyList())
254284
.getIntersection(new CustomSet<>(Arrays.asList('3', '2', '5')));
@@ -259,6 +289,7 @@ public void intersectionOfAnEmptySetAndNonEmptySetIsAnEmptySet() {
259289

260290
@Disabled("Remove to run test")
261291
@Test
292+
@DisplayName("intersection of a non-empty set and an empty set is an empty set")
262293
public void intersectionOfANonEmptySetAndAnEmptySetIsAnEmptySet() {
263294
CustomSet<String> actual = new CustomSet<>(Arrays.asList("1", "2", "3", "4"))
264295
.getIntersection(new CustomSet<>(Collections.emptyList()));
@@ -270,6 +301,7 @@ public void intersectionOfANonEmptySetAndAnEmptySetIsAnEmptySet() {
270301

271302
@Disabled("Remove to run test")
272303
@Test
304+
@DisplayName("intersection of two sets with no shared elements is an empty set")
273305
public void intersectionOfTwoSetsWithNoSharedElementsIsAnEmptySet() {
274306
CustomSet<Integer> actual = new CustomSet<>(Arrays.asList(1, 2, 3))
275307
.getIntersection(new CustomSet<>(Arrays.asList(4, 5, 6)));
@@ -280,6 +312,7 @@ public void intersectionOfTwoSetsWithNoSharedElementsIsAnEmptySet() {
280312

281313
@Disabled("Remove to run test")
282314
@Test
315+
@DisplayName("intersection of two sets with shared elements is a set of the shared elements")
283316
public void intersectionOfTwoSetsWithSharedElementsIsASetOfTheSharedElements() {
284317
CustomSet<Character> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList('2', '3')));
285318
CustomSet<Character> actual = new CustomSet<>(Arrays.asList('1', '2', '3', '4'))
@@ -292,6 +325,7 @@ public void intersectionOfTwoSetsWithSharedElementsIsASetOfTheSharedElements() {
292325

293326
@Disabled("Remove to run test")
294327
@Test
328+
@DisplayName("difference of two empty sets is an empty set")
295329
public void differenceOfTwoEmptySetsIsAnEmptySet() {
296330
CustomSet<String> actual = new CustomSet<String>(Collections.emptyList())
297331
.getDifference(new CustomSet<>(Collections.emptyList()));
@@ -302,6 +336,7 @@ public void differenceOfTwoEmptySetsIsAnEmptySet() {
302336

303337
@Disabled("Remove to run test")
304338
@Test
339+
@DisplayName("difference of empty set and non-empty set is an empty set")
305340
public void differenceOfAnEmptySetAndNonEmptySetIsAnEmptySet() {
306341
CustomSet<Integer> actual = new CustomSet<Integer>(Collections.emptyList())
307342
.getDifference(new CustomSet<>(Arrays.asList(3, 2, 5)));
@@ -312,6 +347,7 @@ public void differenceOfAnEmptySetAndNonEmptySetIsAnEmptySet() {
312347

313348
@Disabled("Remove to run test")
314349
@Test
350+
@DisplayName("difference of a non-empty set and an empty set is the non-empty set")
315351
public void differenceOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() {
316352
CustomSet<Character> expected = new CustomSet<>(Collections.unmodifiableList(
317353
Arrays.asList('1', '2', '3', '4')));
@@ -325,6 +361,7 @@ public void differenceOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() {
325361

326362
@Disabled("Remove to run test")
327363
@Test
364+
@DisplayName("difference of two non-empty sets is a set of elements that are only in the first set")
328365
public void differenceOfTwoNonEmptySetsIsASetOfElementsThatAreOnlyInTheFirstSet() {
329366
CustomSet<String> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList("1", "3")));
330367
CustomSet<String> actual = new CustomSet<>(Arrays.asList("3", "2", "1"))
@@ -338,6 +375,7 @@ public void differenceOfTwoNonEmptySetsIsASetOfElementsThatAreOnlyInTheFirstSet(
338375

339376
@Disabled("Remove to run test")
340377
@Test
378+
@DisplayName("union of empty sets is an empty set")
341379
public void unionOfTwoEmptySetsIsAnEmptySet() {
342380
CustomSet<Integer> actual = new CustomSet<Integer>(Collections.emptyList())
343381
.getUnion(new CustomSet<>(Collections.emptyList()));
@@ -348,6 +386,7 @@ public void unionOfTwoEmptySetsIsAnEmptySet() {
348386

349387
@Disabled("Remove to run test")
350388
@Test
389+
@DisplayName("union of an empty set and non-empty set is the non-empty set")
351390
public void unionOfAnEmptySetAndNonEmptySetIsTheNonEmptySet() {
352391
CustomSet<Character> expected = new CustomSet<>(Collections.unmodifiableList(Collections.singletonList('2')));
353392
CustomSet<Character> actual = new CustomSet<Character>(Collections.emptyList())
@@ -360,6 +399,7 @@ public void unionOfAnEmptySetAndNonEmptySetIsTheNonEmptySet() {
360399

361400
@Disabled("Remove to run test")
362401
@Test
402+
@DisplayName("union of a non-empty set and empty set is the non-empty set")
363403
public void unionOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() {
364404
CustomSet<String> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList("1", "3")));
365405
CustomSet<String> actual = new CustomSet<>(Arrays.asList("1", "3"))
@@ -372,6 +412,7 @@ public void unionOfANonEmptySetAndAnEmptySetIsTheNonEmptySet() {
372412

373413
@Disabled("Remove to run test")
374414
@Test
415+
@DisplayName("union of non-empty sets contains all unique elements")
375416
public void unionOfTwoNonEmptySetsContainsAllUniqueElements() {
376417
CustomSet<Integer> expected = new CustomSet<>(Collections.unmodifiableList(Arrays.asList(3, 2, 1)));
377418
CustomSet<Integer> actual = new CustomSet<>(Arrays.asList(1, 3))

0 commit comments

Comments
 (0)