From a220b5e52d1a21e65205c080d66ac6a4499c912f Mon Sep 17 00:00:00 2001 From: Nathaniel Holden <44616042+kubikowski@users.noreply.github.com> Date: Mon, 7 Nov 2022 14:41:59 -0700 Subject: [PATCH] added many sets unit tests (#65) --- test/comparisons/disjoint.function.test.ts | 12 ++++++++++-- test/comparisons/equivalence.function.test.ts | 10 +++++++++- test/comparisons/pairwise-disjoint.function.test.ts | 10 +++++++++- test/comparisons/proper-subset.function.test.ts | 10 +++++++++- test/comparisons/proper-superset.function.test.ts | 10 +++++++++- test/comparisons/subset.function.test.ts | 10 +++++++++- test/comparisons/superset.function.test.ts | 10 +++++++++- test/operations/difference.function.test.ts | 12 +++++++++++- test/operations/intersection.function.test.ts | 12 +++++++++++- test/operations/union.function.test.ts | 12 +++++++++++- test/operations/xor.function.test.ts | 12 +++++++++++- test/util/scale/timer.model.ts | 4 ++-- 12 files changed, 110 insertions(+), 14 deletions(-) diff --git a/test/comparisons/disjoint.function.test.ts b/test/comparisons/disjoint.function.test.ts index db24515..973acb2 100644 --- a/test/comparisons/disjoint.function.test.ts +++ b/test/comparisons/disjoint.function.test.ts @@ -22,10 +22,14 @@ function disjointTests(testSets: TestSets): void { expect(disjoint(setA, setA)).toBe(false); }); - it('many of the same set are not disjoint', () => { + it('three of the same set are not disjoint', () => { expect(disjoint(setA, setA, setA)).toBe(false); }); + it('many of the same set are not disjoint', () => { + expect(disjoint(setA, setA, setA, setA, setA, setA)).toBe(false); + }); + it('two sets with some shared elements are not disjoint', () => { expect(disjoint(setA, setB)).toBe(false); }); @@ -34,10 +38,14 @@ function disjointTests(testSets: TestSets): void { expect(disjoint(setA, setB, setC)).toBe(false); }); - it('many sets with some shared elements are not disjoint', () => { + it('many sets with some shared elements of the first are not disjoint', () => { expect(disjoint(setA, setB, setC, setD, setE, setF)).toBe(false); }); + it('many sets (reversed) with no shared elements of the first are disjoint', () => { + expect(disjoint(setF, setE, setD, setC, setB, setA)).toBe(true); + }); + it('any non-empty set and the empty set are disjoint', () => { expect(disjoint(setA, empty)).toBe(true); }); diff --git a/test/comparisons/equivalence.function.test.ts b/test/comparisons/equivalence.function.test.ts index 47d541c..6f333ed 100644 --- a/test/comparisons/equivalence.function.test.ts +++ b/test/comparisons/equivalence.function.test.ts @@ -22,10 +22,14 @@ function equivalenceTests(testSets: TestSets): void { expect(equivalence(setA, setA)).toBe(true); }); - it('many of the same set are equivalent', () => { + it('three of the same set are equivalent', () => { expect(equivalence(setA, setA, setA)).toBe(true); }); + it('many of the same set are equivalent', () => { + expect(equivalence(setA, setA, setA, setA, setA, setA)).toBe(true); + }); + it('two different sets are not equivalent', () => { expect(equivalence(setA, setB)).toBe(false); }); @@ -38,6 +42,10 @@ function equivalenceTests(testSets: TestSets): void { expect(equivalence(setA, setB, setC, setD, setE, setF)).toBe(false); }); + it('many different sets (reversed) are not equivalent', () => { + expect(equivalence(setF, setE, setD, setC, setB, setA)).toBe(false); + }); + it('any non-empty set and the empty set are not equivalent', () => { expect(equivalence(setA, empty)).toBe(false); }); diff --git a/test/comparisons/pairwise-disjoint.function.test.ts b/test/comparisons/pairwise-disjoint.function.test.ts index 461e0b0..8fce711 100644 --- a/test/comparisons/pairwise-disjoint.function.test.ts +++ b/test/comparisons/pairwise-disjoint.function.test.ts @@ -22,10 +22,14 @@ function pairwiseDisjointTests(testSets: TestSets): void { expect(pairwiseDisjoint(setA, setA)).toBe(false); }); - it('many of the same set are not pairwise disjoint', () => { + it('three of the same set are not pairwise disjoint', () => { expect(pairwiseDisjoint(setA, setA, setA)).toBe(false); }); + it('many of the same set are not pairwise disjoint', () => { + expect(pairwiseDisjoint(setA, setA, setA, setA, setA, setA)).toBe(false); + }); + it('two sets with some shared elements are not pairwise disjoint', () => { expect(pairwiseDisjoint(setA, setB)).toBe(false); }); @@ -38,6 +42,10 @@ function pairwiseDisjointTests(testSets: TestSets): void { expect(pairwiseDisjoint(setA, setB, setC, setD, setE, setF)).toBe(false); }); + it('many sets (reversed) with some shared elements are not pairwise disjoint', () => { + expect(pairwiseDisjoint(setF, setE, setD, setC, setB, setA)).toBe(false); + }); + it('any non-empty set and the empty set are pairwise disjoint', () => { expect(pairwiseDisjoint(setA, empty)).toBe(true); }); diff --git a/test/comparisons/proper-subset.function.test.ts b/test/comparisons/proper-subset.function.test.ts index ca88bc4..04f7fd2 100644 --- a/test/comparisons/proper-subset.function.test.ts +++ b/test/comparisons/proper-subset.function.test.ts @@ -22,10 +22,14 @@ function properSubsetTests(testSets: TestSets): void { expect(properSubset(setA, setA)).toBe(false); }); - it('many of the same set are not proper subsets', () => { + it('three of the same set are not proper subsets', () => { expect(properSubset(setA, setA, setA)).toBe(false); }); + it('many of the same set are not proper subsets', () => { + expect(properSubset(setA, setA, setA, setA, setA, setA)).toBe(false); + }); + it('two sets with different elements are not proper subsets', () => { expect(properSubset(setA, setB)).toBe(false); }); @@ -38,6 +42,10 @@ function properSubsetTests(testSets: TestSets): void { expect(properSubset(setA, setB, setC, setD, setE, setF)).toBe(false); }); + it('many sets (reversed) with different elements are not proper subsets', () => { + expect(properSubset(setF, setE, setD, setC, setB, setA)).toBe(false); + }); + it('any non-empty set is not a proper subset of the empty set', () => { expect(properSubset(setA, empty)).toBe(false); }); diff --git a/test/comparisons/proper-superset.function.test.ts b/test/comparisons/proper-superset.function.test.ts index 3d03307..fd4d232 100644 --- a/test/comparisons/proper-superset.function.test.ts +++ b/test/comparisons/proper-superset.function.test.ts @@ -22,10 +22,14 @@ function properSupersetTests(testSets: TestSets): void { expect(properSuperset(setA, setA)).toBe(false); }); - it('many of the same set are not proper supersets', () => { + it('three of the same set are not proper supersets', () => { expect(properSuperset(setA, setA, setA)).toBe(false); }); + it('many of the same set are not proper supersets', () => { + expect(properSuperset(setA, setA, setA, setA, setA, setA)).toBe(false); + }); + it('two sets with different elements are not proper supersets', () => { expect(properSuperset(setA, setB)).toBe(false); }); @@ -38,6 +42,10 @@ function properSupersetTests(testSets: TestSets): void { expect(properSuperset(setA, setB, setC, setD, setE, setF)).toBe(false); }); + it('many sets (reversed) with different elements are not proper supersets', () => { + expect(properSuperset(setF, setE, setD, setC, setB, setA)).toBe(false); + }); + it('any non-empty set is a proper superset of the empty set', () => { expect(properSuperset(setA, empty)).toBe(true); }); diff --git a/test/comparisons/subset.function.test.ts b/test/comparisons/subset.function.test.ts index 879721f..1917906 100644 --- a/test/comparisons/subset.function.test.ts +++ b/test/comparisons/subset.function.test.ts @@ -22,10 +22,14 @@ function subsetTests(testSets: TestSets): void { expect(subset(setA, setA)).toBe(true); }); - it('many of the same set are subsets', () => { + it('three of the same set are subsets', () => { expect(subset(setA, setA, setA)).toBe(true); }); + it('many of the same set are subsets', () => { + expect(subset(setA, setA, setA, setA, setA, setA)).toBe(true); + }); + it('two sets with different elements are not subsets', () => { expect(subset(setA, setB)).toBe(false); }); @@ -38,6 +42,10 @@ function subsetTests(testSets: TestSets): void { expect(subset(setA, setB, setC, setD, setE, setF)).toBe(false); }); + it('many sets (reversed) with different elements are not subsets', () => { + expect(subset(setF, setE, setD, setC, setB, setA)).toBe(false); + }); + it('any non-empty set is not a subset of the empty set', () => { expect(subset(setA, empty)).toBe(false); }); diff --git a/test/comparisons/superset.function.test.ts b/test/comparisons/superset.function.test.ts index 6eb3573..e902760 100644 --- a/test/comparisons/superset.function.test.ts +++ b/test/comparisons/superset.function.test.ts @@ -22,10 +22,14 @@ function supersetTests(testSets: TestSets): void { expect(superset(setA, setA)).toBe(true); }); - it('many of the same set are supersets', () => { + it('three of the same set are supersets', () => { expect(superset(setA, setA, setA)).toBe(true); }); + it('many of the same set are supersets', () => { + expect(superset(setA, setA, setA, setA, setA, setA)).toBe(true); + }); + it('two sets with different elements are not supersets', () => { expect(superset(setA, setB)).toBe(false); }); @@ -38,6 +42,10 @@ function supersetTests(testSets: TestSets): void { expect(superset(setA, setB, setC, setD, setE, setF)).toBe(false); }); + it('many sets (reversed) with different elements are not supersets', () => { + expect(superset(setF, setE, setD, setC, setB, setA)).toBe(false); + }); + it('any non-empty set is a superset of the empty set', () => { expect(superset(setA, empty)).toBe(true); }); diff --git a/test/operations/difference.function.test.ts b/test/operations/difference.function.test.ts index 2494ed3..7f39ef7 100644 --- a/test/operations/difference.function.test.ts +++ b/test/operations/difference.function.test.ts @@ -27,11 +27,16 @@ function differenceTests(testSets: TestSets): void { expect(equivalence(result, empty)).toBe(true); }); - it('many of the same set has no difference overlap', () => { + it('three of the same set has no difference overlap', () => { const result = difference(setA, setA, setA); expect(equivalence(result, empty)).toBe(true); }); + it('many of the same set has no difference overlap', () => { + const result = difference(setA, setA, setA, setA, setA, setA); + expect(equivalence(result, empty)).toBe(true); + }); + it('two sets\' difference is a subset of the first', () => { const result = difference(setA, setB); expect(equivalence(result, differenceAB)).toBe(true); @@ -47,6 +52,11 @@ function differenceTests(testSets: TestSets): void { expect(equivalence(result, differenceABC)).toBe(true); }); + it('many sets\' (reversed) difference is a subset of the first', () => { + const result = difference(setF, setE, setD, setC, setB, setA); + expect(equivalence(result, setF)).toBe(true); + }); + it('any sets\' difference with the empty set is itself', () => { const result = difference(setA, empty); expect(equivalence(result, setA)).toBe(true); diff --git a/test/operations/intersection.function.test.ts b/test/operations/intersection.function.test.ts index 3838943..7f8a756 100644 --- a/test/operations/intersection.function.test.ts +++ b/test/operations/intersection.function.test.ts @@ -27,11 +27,16 @@ function intersectionTests(testSets: TestSets): void { expect(equivalence(result, setA)).toBe(true); }); - it('many of the same set intersection returns self', () => { + it('three of the same set intersection returns self', () => { const result = intersection(setA, setA, setA); expect(equivalence(result, setA)).toBe(true); }); + it('many of the same set intersection returns self', () => { + const result = intersection(setA, setA, setA, setA, setA, setA); + expect(equivalence(result, setA)).toBe(true); + }); + it('two sets\' intersection is a subset of the first', () => { const result = intersection(setA, setB); expect(equivalence(result, intersectionAB)).toBe(true); @@ -47,6 +52,11 @@ function intersectionTests(testSets: TestSets): void { expect(equivalence(result, empty)).toBe(true); }); + it('many sets\' (reversed) intersection is a subset of the first', () => { + const result = intersection(setF, setE, setD, setC, setB, setA); + expect(equivalence(result, empty)).toBe(true); + }); + it('any sets\' intersection with the empty set is the empty set', () => { const result = intersection(setA, empty); expect(equivalence(result, empty)).toBe(true); diff --git a/test/operations/union.function.test.ts b/test/operations/union.function.test.ts index 7dccbcb..90846e5 100644 --- a/test/operations/union.function.test.ts +++ b/test/operations/union.function.test.ts @@ -27,11 +27,16 @@ function unionTests(testSets: TestSets): void { expect(equivalence(result, setA)).toBe(true); }); - it('many of the same set union returns self', () => { + it('three of the same set union returns self', () => { const result = union(setA, setA, setA); expect(equivalence(result, setA)).toBe(true); }); + it('many of the same set union returns self', () => { + const result = union(setA, setA, setA, setA, setA, setA); + expect(equivalence(result, setA)).toBe(true); + }); + it('two sets\' union contains all elements from both sets', () => { const result = union(setA, setB); expect(equivalence(result, unionAB)).toBe(true); @@ -47,6 +52,11 @@ function unionTests(testSets: TestSets): void { expect(equivalence(result, universal)).toBe(true); }); + it('many sets\' (reversed) union contains all elements from all sets', () => { + const result = union(setF, setE, setD, setC, setB, setA); + expect(equivalence(result, universal)).toBe(true); + }); + it('any sets\' union with the empty set is itself', () => { const result = union(setA, empty); expect(equivalence(result, setA)).toBe(true); diff --git a/test/operations/xor.function.test.ts b/test/operations/xor.function.test.ts index 51dc35f..e7726b0 100644 --- a/test/operations/xor.function.test.ts +++ b/test/operations/xor.function.test.ts @@ -29,11 +29,16 @@ function xorTests(testSets: TestSets): void { expect(equivalence(result, empty)).toBe(true); }); - it('many of the same set xor returns the empty set', () => { + it('three of the same set xor returns the empty set', () => { const result = xor(setA, setA, setA); expect(equivalence(result, empty)).toBe(true); }); + it('many of the same set xor returns the empty set', () => { + const result = xor(setA, setA, setA, setA, setA, setA); + expect(equivalence(result, empty)).toBe(true); + }); + it('two different sets xor returns unique elements', () => { const result = xor(setA, setB); expect(equivalence(result, xorAB)).toBe(true); @@ -49,6 +54,11 @@ function xorTests(testSets: TestSets): void { expect(equivalence(result, xorABCDEF)).toBe(true); }); + it('many different sets (reversed) xor returns unique elements', () => { + const result = xor(setF, setE, setD, setC, setB, setA); + expect(equivalence(result, xorABCDEF)).toBe(true); + }); + it('any non-empty sets\' xor with the empty set is itself', () => { const result = xor(setA, empty); expect(equivalence(result, setA)).toBe(true); diff --git a/test/util/scale/timer.model.ts b/test/util/scale/timer.model.ts index ef5bbc8..2e7c216 100644 --- a/test/util/scale/timer.model.ts +++ b/test/util/scale/timer.model.ts @@ -31,7 +31,7 @@ export abstract class Timer { public static log(methodName: string): void { const logs = Timer.getLogs(methodName); - process.stdout.write(logs); + process.stdout.write(`${ logs }\n`); } public static logAll(): void { @@ -39,7 +39,7 @@ export abstract class Timer { .map(Timer.getLogs) .join(''); - process.stdout.write(logs); + process.stdout.write(`\n${ logs }\n`); } private static getLogs(methodName: string): string {