Skip to content

Commit

Permalink
added more ∅ and U sets unit tests (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubikowski authored Nov 13, 2022
1 parent 349eaf0 commit 5bd6b18
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 13 deletions.
8 changes: 8 additions & 0 deletions test/unit/comparisons/disjoint.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ function disjointTests<T>(testSets: TestSets<T>): void {
expect(disjoint(setA, empty)).toBe(true);
});

it('the empty set and any non-empty set are disjoint', () => {
expect(disjoint(empty, setA)).toBe(true);
});

it('any non-empty set and the universal set are not disjoint', () => {
expect(disjoint(setA, universal)).toBe(false);
});

it('the universal set and any non-empty set are not disjoint', () => {
expect(disjoint(universal, setA)).toBe(false);
});

it('the empty set is disjoint with itself', () => {
expect(disjoint(empty, empty)).toBe(true);
});
Expand Down
8 changes: 8 additions & 0 deletions test/unit/comparisons/equivalence.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ function equivalenceTests<T>(testSets: TestSets<T>): void {
expect(equivalence(setA, empty)).toBe(false);
});

it('the empty set and any non-empty set are not equivalent', () => {
expect(equivalence(empty, setA)).toBe(false);
});

it('any non-universal set and the universal set are not equivalent', () => {
expect(equivalence(setA, universal)).toBe(false);
});

it('the universal set and any non-universal set are not equivalent', () => {
expect(equivalence(universal, setA)).toBe(false);
});

it('the empty set is equivalent to itself', () => {
expect(equivalence(empty, empty)).toBe(true);
});
Expand Down
8 changes: 8 additions & 0 deletions test/unit/comparisons/pairwise-disjoint.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ function pairwiseDisjointTests<T>(testSets: TestSets<T>): void {
expect(pairwiseDisjoint(setA, empty)).toBe(true);
});

it('the empty set and any non-empty set are pairwise disjoint', () => {
expect(pairwiseDisjoint(empty, setA)).toBe(true);
});

it('any non-empty set and the universal set are not pairwise disjoint', () => {
expect(pairwiseDisjoint(setA, universal)).toBe(false);
});

it('the universal set and any non-empty set are not pairwise disjoint', () => {
expect(pairwiseDisjoint(universal, setA)).toBe(false);
});

it('the empty set is pairwise disjoint with itself', () => {
expect(pairwiseDisjoint(empty, empty)).toBe(true);
});
Expand Down
8 changes: 8 additions & 0 deletions test/unit/comparisons/proper-subset.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ function properSubsetTests<T>(testSets: TestSets<T>): void {
expect(properSubset(setA, empty)).toBe(false);
});

it('the empty set is a proper subset of any non-empty set', () => {
expect(properSubset(empty, setA)).toBe(true);
});

it('any non-universal set is a proper subset of the universal set', () => {
expect(properSubset(setA, universal)).toBe(true);
});

it('the universal set is not a proper subset of any non-universal set', () => {
expect(properSubset(universal, setA)).toBe(false);
});

it('the empty set is not a proper subset of itself', () => {
expect(properSubset(empty, empty)).toBe(false);
});
Expand Down
8 changes: 8 additions & 0 deletions test/unit/comparisons/proper-superset.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ function properSupersetTests<T>(testSets: TestSets<T>): void {
expect(properSuperset(setA, empty)).toBe(true);
});

it('the empty set is not a proper superset of any non-empty set', () => {
expect(properSuperset(empty, setA)).toBe(false);
});

it('any non-universal set is not a proper superset of the universal set', () => {
expect(properSuperset(setA, universal)).toBe(false);
});

it('the universal set is a proper superset of any non-universal set', () => {
expect(properSuperset(universal, setA)).toBe(true);
});

it('the empty set is not a proper superset of itself', () => {
expect(properSuperset(empty, empty)).toBe(false);
});
Expand Down
8 changes: 8 additions & 0 deletions test/unit/comparisons/subset.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ function subsetTests<T>(testSets: TestSets<T>): void {
expect(subset(setA, empty)).toBe(false);
});

it('the empty set is a subset of any non-empty set', () => {
expect(subset(empty, setA)).toBe(true);
});

it('any non-universal set is a subset of the universal set', () => {
expect(subset(setA, universal)).toBe(true);
});

it('the universal set is not a subset of any non-universal set', () => {
expect(subset(universal, setA)).toBe(false);
});

it('the empty set is a subset of itself', () => {
expect(subset(empty, empty)).toBe(true);
});
Expand Down
8 changes: 8 additions & 0 deletions test/unit/comparisons/superset.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,18 @@ function supersetTests<T>(testSets: TestSets<T>): void {
expect(superset(setA, empty)).toBe(true);
});

it('the empty set is not a superset of any non-empty set', () => {
expect(superset(empty, setA)).toBe(false);
});

it('any non-universal set is not a superset of the universal set', () => {
expect(superset(setA, universal)).toBe(false);
});

it('the universal set is a superset of any non-universal set', () => {
expect(superset(universal, setA)).toBe(true);
});

it('the empty set is a superset of itself', () => {
expect(superset(empty, empty)).toBe(true);
});
Expand Down
19 changes: 15 additions & 4 deletions test/unit/operations/difference.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ describe('difference', () => {
});

function differenceTests<T>(testSets: TestSets<T>): void {
const { c, e, empty, setA, setB, setC, setD, setE, setF, universal } = testSets;
const { c, d, e, empty, f, g, h, i, j, setA, setB, setC, setD, setE, setF, universal } = testSets;
const differenceAB = new Set<T>([ c, e ]);
const differenceABC = new Set<T>([ e ]);
const differenceUA = new Set<T>([ d, f, g, h, i, j ]);

it('no sets difference returns empty set', () => {
const result = difference();
Expand Down Expand Up @@ -67,17 +68,27 @@ function differenceTests<T>(testSets: TestSets<T>): void {
expect(equivalence(result, setF)).toBe(true);
});

it('any sets\' difference with the empty set is itself', () => {
it('any non-empty set\'s difference with the empty set is itself', () => {
const result = difference(setA, empty);
expect(equivalence(result, setA)).toBe(true);
});

it('any sets\' difference with the universal set is the empty set', () => {
it('the empty set\'s difference with any non-empty set is the empty set', () => {
const result = difference(empty, setA);
expect(equivalence(result, empty)).toBe(true);
});

it('any set\'s difference with the universal set is the empty set', () => {
const result = difference(setA, universal);
expect(equivalence(result, empty)).toBe(true);
});

it('the empty sets\' difference with itself is itself', () => {
it('the universal set\'s difference with any non-universal set contains all elements not in that set', () => {
const result = difference(universal, setA);
expect(equivalence(result, differenceUA)).toBe(true);
});

it('the empty set\'s difference with itself is itself', () => {
const result = difference(empty, empty);
expect(equivalence(result, empty)).toBe(true);
});
Expand Down
16 changes: 13 additions & 3 deletions test/unit/operations/intersection.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,27 @@ function intersectionTests<T>(testSets: TestSets<T>): void {
expect(equivalence(result, empty)).toBe(true);
});

it('any sets\' intersection with the empty set is the empty set', () => {
it('any non-empty set\'s intersection with the empty set is the empty set', () => {
const result = intersection(setA, empty);
expect(equivalence(result, empty)).toBe(true);
});

it('any sets\' intersection with the universal set is itself', () => {
it('the empty set\'s intersection with any non-empty sets is the empty set', () => {
const result = intersection(empty, setA);
expect(equivalence(result, empty)).toBe(true);
});

it('any non-universal set\'s intersection with the universal set is itself', () => {
const result = intersection(setA, universal);
expect(equivalence(result, setA)).toBe(true);
});

it('the empty sets\' intersection with itself is itself', () => {
it('the universal set\'s intersection with any non-universal set is that set', () => {
const result = intersection(universal, setA);
expect(equivalence(result, setA)).toBe(true);
});

it('the empty set\'s intersection with itself is itself', () => {
const result = intersection(empty, empty);
expect(equivalence(result, empty)).toBe(true);
});
Expand Down
16 changes: 13 additions & 3 deletions test/unit/operations/union.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,27 @@ function unionTests<T>(testSets: TestSets<T>): void {
expect(equivalence(result, universal)).toBe(true);
});

it('any sets\' union with the empty set is itself', () => {
it('any non-empty set\'s union with the empty set is itself', () => {
const result = union(setA, empty);
expect(equivalence(result, setA)).toBe(true);
});

it('any sets\' union with the universal set is the universal set', () => {
it('the empty set\'s union with any non-empty set is that set', () => {
const result = union(empty, setA);
expect(equivalence(result, setA)).toBe(true);
});

it('any non-universal set\'s union with the universal set is the universal set', () => {
const result = union(setA, universal);
expect(equivalence(result, universal)).toBe(true);
});

it('the empty sets\' union with itself is itself', () => {
it('the universal set\'s union with any non-universal set is the universal set', () => {
const result = union(universal, setA);
expect(equivalence(result, universal)).toBe(true);
});

it('the empty set\'s union with itself is itself', () => {
const result = union(empty, empty);
expect(equivalence(result, empty)).toBe(true);
});
Expand Down
16 changes: 13 additions & 3 deletions test/unit/operations/xor.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,27 @@ function xorTests<T>(testSets: TestSets<T>): void {
expect(equivalence(result, xorABCDEF)).toBe(true);
});

it('any non-empty sets\' xor with the empty set is itself', () => {
it('any non-empty set\'s xor with the empty set is itself', () => {
const result = xor(setA, empty);
expect(equivalence(result, setA)).toBe(true);
});

it('any non-universal sets\' xor with the universal set is the difference of the universal set and itself', () => {
it('the empty set\'s xor with any non-empty set is that set', () => {
const result = xor(empty, setA);
expect(equivalence(result, setA)).toBe(true);
});

it('any non-universal set\'s xor with the universal set is the difference of the universal set and itself', () => {
const result = xor(setA, universal);
expect(equivalence(result, xorAU)).toBe(true);
});

it('the empty sets\' xor with itself is itself', () => {
it('the universal set\'s xor with any non-universal set is the difference of the universal set and that set', () => {
const result = xor(universal, setA);
expect(equivalence(result, xorAU)).toBe(true);
});

it('the empty set\'s xor with itself is itself', () => {
const result = xor(empty, empty);
expect(equivalence(result, empty)).toBe(true);
});
Expand Down

0 comments on commit 5bd6b18

Please sign in to comment.