Finished
1
2const { CustomSet } = require('./main.js');
3
4describe('CustomSet', () => {
5 describe('empty: returns true if the set contains no elements', () => {
6 test('sets with no elements are empty', () => {
7 const actual = new CustomSet().empty();
8 expect(actual).toBe(true);
9 });
10
11 test('sets with elements are not empty', () => {
12 const actual = new CustomSet([1]).empty();
13 expect(actual).toBe(false);
14 });
15 });
16
17 describe('contains: sets can report if they contain an element', () => {
18 test('nothing is contained in an empty set', () => {
19 const actual = new CustomSet().contains(1);
20 expect(actual).toBe(false);
21 });
22
23 test('when the element is in the set', () => {
24 const actual = new CustomSet([1, 2, 3]).contains(1);
25 expect(actual).toBe(true);
26 });
27
28 test('when the element is not in the set', () => {
29 const actual = new CustomSet([1, 2, 3]).contains(4);
30 expect(actual).toBe(false);
31 });
32 });
33
34 describe('subset: a set is a subset if all of its elements are contained in the other set', () => {
35 test('empty set is a subset of another empty set', () => {
36 const actual = new CustomSet().subset(new CustomSet());
37 expect(actual).toBe(true);
38 });
39
40 test('empty set is a subset of non-empty set', () => {
41 const actual = new CustomSet().subset(new CustomSet([1]));
42 expect(actual).toBe(true);
43 });
44
45 test('non-empty set is not a subset of empty set', () => {
46 const actual = new CustomSet([1]).subset(new CustomSet());
47 expect(actual).toBe(false);
48 });
49
50 test('set is a subset of set with exact same elements', () => {
51 const actual = new CustomSet([1, 2, 3]).subset(new CustomSet([1, 2, 3]));
52 expect(actual).toBe(true);
53 });
54
55 test('set is a subset of larger set with same elements', () => {
56 const actual = new CustomSet([1, 2, 3]).subset(
57 new CustomSet([4, 1, 2, 3]),
58 );
59 expect(actual).toBe(true);
60 });
61
62 test('set is not a subset of set that does not contain its elements', () => {
63 const actual = new CustomSet([1, 2, 3]).subset(new CustomSet([4, 1, 3]));
64 expect(actual).toBe(false);
65 });
66 });
67
68 describe('disjoint: sets are disjoint if they share no elements', () => {
69 test('the empty set is disjoint with itself', () => {
70 const actual = new CustomSet().disjoint(new CustomSet([]));
71 expect(actual).toBe(true);
72 });
73
74 test('empty set is disjoint with non-empty set', () => {
75 const actual = new CustomSet().disjoint(new CustomSet([1]));
76 expect(actual).toBe(true);
77 });
78
79 test('non-empty set is disjoint with empty set', () => {
80 const actual = new CustomSet([1]).disjoint(new CustomSet([]));
81 expect(actual).toBe(true);
82 });
83
84 test('sets are not disjoint if they share an element', () => {
85 const actual = new CustomSet([1, 2]).disjoint(new CustomSet([2, 3]));
86 expect(actual).toBe(false);
87 });
88
89 test('sets are disjoint if they share no elements', () => {
90 const actual = new CustomSet([1, 2]).disjoint(new CustomSet([3, 4]));
91 expect(actual).toBe(true);
92 });
93 });
94
95 describe('eql: sets with the same elements are equal', () => {
96 test('empty sets are equal', () => {
97 const actual = new CustomSet().eql(new CustomSet());
98 expect(actual).toBe(true);
99 });
100
101 test('empty set is not equal to non-empty set', () => {
102 const actual = new CustomSet().eql(new CustomSet([1, 2, 3]));
103 expect(actual).toBe(false);
104 });
105
106 test('non-empty set is not equal to empty set', () => {
107 const actual = new CustomSet([1, 2, 3]).eql(new CustomSet());
108 expect(actual).toBe(false);
109 });
110
111 test('sets with the same elements are equal', () => {
112 const actual = new CustomSet([1, 2]).eql(new CustomSet([2, 1]));
113 expect(actual).toBe(true);
114 });
115
116 test('sets with different elements are not equal', () => {
117 const actual = new CustomSet([1, 2, 3]).eql(new CustomSet([1, 2, 4]));
118 expect(actual).toBe(false);
119 });
120
121 test('set is not equal to larger set with same elements', () => {
122 const actual = new CustomSet([1, 2, 3]).eql(new CustomSet([1, 2, 3, 4]));
123 expect(actual).toBe(false);
124 });
125
126 test('set is equal to a set constructed from an array with duplicates', () => {
127 const actual = new CustomSet([1]).eql(new CustomSet([1, 1]));
128 expect(actual).toBe(true);
129 });
130 });
131
132 describe('add: unique elements can be added to a set', () => {
133 test('add to empty set', () => {
134 const actual = new CustomSet().add(3);
135 const expected = new CustomSet([3]);
136 expect(actual.eql(expected)).toBe(true);
137 });
138
139 test('add to non-empty set', () => {
140 const actual = new CustomSet([1, 2, 4]).add(3);
141 const expected = new CustomSet([1, 2, 3, 4]);
142 expect(actual.eql(expected)).toBe(true);
143 });
144
145 test('adding an existing element does not change the set', () => {
146 const actual = new CustomSet([1, 2, 3]).add(3);
147 const expected = new CustomSet([1, 2, 3]);
148 expect(actual.eql(expected)).toBe(true);
149 });
150 });
151
152 describe('intersection: returns a set of all shared elements', () => {
153 test('intersection of two empty sets is an empty set', () => {
154 const actual = new CustomSet().intersection(new CustomSet());
155 const expected = new CustomSet();
156 expect(actual.eql(expected)).toBe(true);
157 });
158
159 test('intersection of an empty set and non-empty set is an empty set', () => {
160 const actual = new CustomSet().intersection(new CustomSet([3, 2, 5]));
161 const expected = new CustomSet([]);
162 expect(actual.eql(expected)).toBe(true);
163 });
164
165 test('intersection of a non-empty set and an empty set is an empty set', () => {
166 const actual = new CustomSet([1, 2, 3, 4]).intersection(
167 new CustomSet([]),
168 );
169 const expected = new CustomSet([]);
170 expect(actual.eql(expected)).toBe(true);
171 });
172
173 test('intersection of two sets with no shared elements is an empty set', () => {
174 const actual = new CustomSet([1, 2, 3]).intersection(
175 new CustomSet([4, 5, 6]),
176 );
177 const expected = new CustomSet([]);
178 expect(actual.eql(expected)).toBe(true);
179 });
180
181 test('intersection of two sets with shared elements is a set of the shared elements', () => {
182 const actual = new CustomSet([1, 2, 3, 4]).intersection(
183 new CustomSet([3, 2, 5]),
184 );
185 const expected = new CustomSet([2, 3]);
186 expect(actual.eql(expected)).toBe(true);
187 });
188 });
189
190 describe('difference of a set is a set of all elements that are only in the first set', () => {
191 test('difference of two empty sets is an empty set', () => {
192 const actual = new CustomSet().difference(new CustomSet());
193 const expected = new CustomSet();
194 expect(actual.eql(expected)).toBe(true);
195 });
196
197 test('difference of empty set and non-empty set is an empty set', () => {
198 const actual = new CustomSet().difference(new CustomSet([3, 2, 5]));
199 const expected = new CustomSet();
200 expect(actual.eql(expected)).toBe(true);
201 });
202
203 test('difference of a non-empty set and an empty set is the non-empty set', () => {
204 const actual = new CustomSet([1, 2, 3, 4]).difference(new CustomSet());
205 const expected = new CustomSet([1, 2, 3, 4]);
206 expect(actual.eql(expected)).toBe(true);
207 });
208
209 test('difference of two non-empty sets is a set of elements that are only in the first set', () => {
210 const actual = new CustomSet([3, 2, 1]).difference(new CustomSet([2, 4]));
211 const expected = new CustomSet([1, 3]);
212 expect(actual.eql(expected)).toBe(true);
213 });
214
215 test('difference removes all duplicates in the first set', () => {
216 const actual = new CustomSet([1, 1]).difference(new CustomSet([1]));
217 const expected = new CustomSet([]);
218 expect(actual.eql(expected)).toBe(true);
219 });
220 });
221
222 describe('union: returns a set of all elements in either set', () => {
223 test('union of empty sets is an empty set', () => {
224 const actual = new CustomSet().union(new CustomSet());
225 const expected = new CustomSet();
226 expect(actual.eql(expected)).toBe(true);
227 });
228
229 test('union of an empty set and non-empty set is the non-empty set', () => {
230 const actual = new CustomSet().union(new CustomSet([2]));
231 const expected = new CustomSet([2]);
232 expect(actual.eql(expected)).toBe(true);
233 });
234
235 test('union of a non-empty set and empty set is the non-empty set', () => {
236 const actual = new CustomSet([1, 3]).union(new CustomSet());
237 const expected = new CustomSet([1, 3]);
238 expect(actual.eql(expected)).toBe(true);
239 });
240
241 test('union of non-empty sets contains all unique elements', () => {
242 const actual = new CustomSet([1, 3]).union(new CustomSet([2, 3]));
243 const expected = new CustomSet([1, 2, 3]);
244 expect(actual.eql(expected)).toBe(true);
245 });
246 });
247});
Test NameStatus
sets with no elements are empty
Pass
sets with elements are not empty
Pass
nothing is contained in an empty set
Pass
when the element is in the set
Pass
when the element is not in the set
Pass
empty set is a subset of another empty set
Pass
empty set is a subset of non-empty set
Pass
non-empty set is not a subset of empty set
Pass
set is a subset of set with exact same elements
Pass
set is a subset of larger set with same elements
Pass
set is not a subset of set that does not contain its elements
Pass
the empty set is disjoint with itself
Pass
empty set is disjoint with non-empty set
Pass
non-empty set is disjoint with empty set
Pass
sets are not disjoint if they share an element
Pass
sets are disjoint if they share no elements
Pass
empty sets are equal
Pass
empty set is not equal to non-empty set
Pass
non-empty set is not equal to empty set
Pass
sets with the same elements are equal
Pass
sets with different elements are not equal
Pass
set is not equal to larger set with same elements
Pass
set is equal to a set constructed from an array with duplicates
Pass
add to empty set
Pass
add to non-empty set
Pass
adding an existing element does not change the set
Pass
intersection of two empty sets is an empty set
Pass
intersection of an empty set and non-empty set is an empty set
Pass
intersection of a non-empty set and an empty set is an empty set
Pass
intersection of two sets with no shared elements is an empty set
Pass
intersection of two sets with shared elements is a set of the shared elements
Pass
difference of two empty sets is an empty set
Pass
difference of empty set and non-empty set is an empty set
Pass
difference of a non-empty set and an empty set is the non-empty set
Pass
difference of two non-empty sets is a set of elements that are only in the first set
Pass
difference removes all duplicates in the first set
Pass
union of empty sets is an empty set
Pass
union of an empty set and non-empty set is the non-empty set
Pass
union of a non-empty set and empty set is the non-empty set
Pass
union of non-empty sets contains all unique elements
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.