From 5bd6b18b4ac1ba5620873c27ca8bd72b946699c3 Mon Sep 17 00:00:00 2001 From: Nathaniel Holden <44616042+kubikowski@users.noreply.github.com> Date: Sun, 13 Nov 2022 10:22:02 -0700 Subject: [PATCH] =?UTF-8?q?added=20more=20=E2=88=85=20and=20U=20sets=20uni?= =?UTF-8?q?t=20tests=20(#74)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comparisons/disjoint.function.test.ts | 8 ++++++++ .../comparisons/equivalence.function.test.ts | 8 ++++++++ .../pairwise-disjoint.function.test.ts | 8 ++++++++ .../proper-subset.function.test.ts | 8 ++++++++ .../proper-superset.function.test.ts | 8 ++++++++ test/unit/comparisons/subset.function.test.ts | 8 ++++++++ .../comparisons/superset.function.test.ts | 8 ++++++++ .../operations/difference.function.test.ts | 19 +++++++++++++++---- .../operations/intersection.function.test.ts | 16 +++++++++++++--- test/unit/operations/union.function.test.ts | 16 +++++++++++++--- test/unit/operations/xor.function.test.ts | 16 +++++++++++++--- 11 files changed, 110 insertions(+), 13 deletions(-) diff --git a/test/unit/comparisons/disjoint.function.test.ts b/test/unit/comparisons/disjoint.function.test.ts index 7a44e09..4847744 100644 --- a/test/unit/comparisons/disjoint.function.test.ts +++ b/test/unit/comparisons/disjoint.function.test.ts @@ -58,10 +58,18 @@ function disjointTests(testSets: TestSets): 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); }); diff --git a/test/unit/comparisons/equivalence.function.test.ts b/test/unit/comparisons/equivalence.function.test.ts index 8eb7c4d..189ad4e 100644 --- a/test/unit/comparisons/equivalence.function.test.ts +++ b/test/unit/comparisons/equivalence.function.test.ts @@ -58,10 +58,18 @@ function equivalenceTests(testSets: TestSets): 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); }); diff --git a/test/unit/comparisons/pairwise-disjoint.function.test.ts b/test/unit/comparisons/pairwise-disjoint.function.test.ts index 716269c..2e705f2 100644 --- a/test/unit/comparisons/pairwise-disjoint.function.test.ts +++ b/test/unit/comparisons/pairwise-disjoint.function.test.ts @@ -58,10 +58,18 @@ function pairwiseDisjointTests(testSets: TestSets): 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); }); diff --git a/test/unit/comparisons/proper-subset.function.test.ts b/test/unit/comparisons/proper-subset.function.test.ts index bd9552f..cf074f8 100644 --- a/test/unit/comparisons/proper-subset.function.test.ts +++ b/test/unit/comparisons/proper-subset.function.test.ts @@ -58,10 +58,18 @@ function properSubsetTests(testSets: TestSets): 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); }); diff --git a/test/unit/comparisons/proper-superset.function.test.ts b/test/unit/comparisons/proper-superset.function.test.ts index 670f909..26c90db 100644 --- a/test/unit/comparisons/proper-superset.function.test.ts +++ b/test/unit/comparisons/proper-superset.function.test.ts @@ -58,10 +58,18 @@ function properSupersetTests(testSets: TestSets): 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); }); diff --git a/test/unit/comparisons/subset.function.test.ts b/test/unit/comparisons/subset.function.test.ts index 3408728..a872183 100644 --- a/test/unit/comparisons/subset.function.test.ts +++ b/test/unit/comparisons/subset.function.test.ts @@ -58,10 +58,18 @@ function subsetTests(testSets: TestSets): 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); }); diff --git a/test/unit/comparisons/superset.function.test.ts b/test/unit/comparisons/superset.function.test.ts index dfcd97c..988f88e 100644 --- a/test/unit/comparisons/superset.function.test.ts +++ b/test/unit/comparisons/superset.function.test.ts @@ -58,10 +58,18 @@ function supersetTests(testSets: TestSets): 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); }); diff --git a/test/unit/operations/difference.function.test.ts b/test/unit/operations/difference.function.test.ts index 66224b0..1b6023d 100644 --- a/test/unit/operations/difference.function.test.ts +++ b/test/unit/operations/difference.function.test.ts @@ -8,9 +8,10 @@ describe('difference', () => { }); function differenceTests(testSets: TestSets): 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([ c, e ]); const differenceABC = new Set([ e ]); + const differenceUA = new Set([ d, f, g, h, i, j ]); it('no sets difference returns empty set', () => { const result = difference(); @@ -67,17 +68,27 @@ function differenceTests(testSets: TestSets): 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); }); diff --git a/test/unit/operations/intersection.function.test.ts b/test/unit/operations/intersection.function.test.ts index 9091184..ace2947 100644 --- a/test/unit/operations/intersection.function.test.ts +++ b/test/unit/operations/intersection.function.test.ts @@ -67,17 +67,27 @@ function intersectionTests(testSets: TestSets): 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); }); diff --git a/test/unit/operations/union.function.test.ts b/test/unit/operations/union.function.test.ts index ed9e455..7bd6fca 100644 --- a/test/unit/operations/union.function.test.ts +++ b/test/unit/operations/union.function.test.ts @@ -69,17 +69,27 @@ function unionTests(testSets: TestSets): 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); }); diff --git a/test/unit/operations/xor.function.test.ts b/test/unit/operations/xor.function.test.ts index fabe73a..bcc5c70 100644 --- a/test/unit/operations/xor.function.test.ts +++ b/test/unit/operations/xor.function.test.ts @@ -71,17 +71,27 @@ function xorTests(testSets: TestSets): 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); });