Skip to content

Commit

Permalink
added many sets unit tests (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubikowski authored Nov 7, 2022
1 parent 9c255f9 commit a220b5e
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 14 deletions.
12 changes: 10 additions & 2 deletions test/comparisons/disjoint.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ function disjointTests<T>(testSets: TestSets<T>): 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);
});
Expand All @@ -34,10 +38,14 @@ function disjointTests<T>(testSets: TestSets<T>): 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);
});
Expand Down
10 changes: 9 additions & 1 deletion test/comparisons/equivalence.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ function equivalenceTests<T>(testSets: TestSets<T>): 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);
});
Expand All @@ -38,6 +42,10 @@ function equivalenceTests<T>(testSets: TestSets<T>): 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);
});
Expand Down
10 changes: 9 additions & 1 deletion test/comparisons/pairwise-disjoint.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ function pairwiseDisjointTests<T>(testSets: TestSets<T>): 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);
});
Expand All @@ -38,6 +42,10 @@ function pairwiseDisjointTests<T>(testSets: TestSets<T>): 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);
});
Expand Down
10 changes: 9 additions & 1 deletion test/comparisons/proper-subset.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ function properSubsetTests<T>(testSets: TestSets<T>): 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);
});
Expand All @@ -38,6 +42,10 @@ function properSubsetTests<T>(testSets: TestSets<T>): 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);
});
Expand Down
10 changes: 9 additions & 1 deletion test/comparisons/proper-superset.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ function properSupersetTests<T>(testSets: TestSets<T>): 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);
});
Expand All @@ -38,6 +42,10 @@ function properSupersetTests<T>(testSets: TestSets<T>): 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);
});
Expand Down
10 changes: 9 additions & 1 deletion test/comparisons/subset.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ function subsetTests<T>(testSets: TestSets<T>): 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);
});
Expand All @@ -38,6 +42,10 @@ function subsetTests<T>(testSets: TestSets<T>): 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);
});
Expand Down
10 changes: 9 additions & 1 deletion test/comparisons/superset.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ function supersetTests<T>(testSets: TestSets<T>): 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);
});
Expand All @@ -38,6 +42,10 @@ function supersetTests<T>(testSets: TestSets<T>): 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);
});
Expand Down
12 changes: 11 additions & 1 deletion test/operations/difference.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ function differenceTests<T>(testSets: TestSets<T>): 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);
Expand All @@ -47,6 +52,11 @@ function differenceTests<T>(testSets: TestSets<T>): 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);
Expand Down
12 changes: 11 additions & 1 deletion test/operations/intersection.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ function intersectionTests<T>(testSets: TestSets<T>): 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);
Expand All @@ -47,6 +52,11 @@ function intersectionTests<T>(testSets: TestSets<T>): 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);
Expand Down
12 changes: 11 additions & 1 deletion test/operations/union.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ function unionTests<T>(testSets: TestSets<T>): 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);
Expand All @@ -47,6 +52,11 @@ function unionTests<T>(testSets: TestSets<T>): 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);
Expand Down
12 changes: 11 additions & 1 deletion test/operations/xor.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ function xorTests<T>(testSets: TestSets<T>): 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);
Expand All @@ -49,6 +54,11 @@ function xorTests<T>(testSets: TestSets<T>): 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);
Expand Down
4 changes: 2 additions & 2 deletions test/util/scale/timer.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ 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 {
const logs = Array.from(Timer.timings.keys())
.map(Timer.getLogs)
.join('');

process.stdout.write(logs);
process.stdout.write(`\n${ logs }\n`);
}

private static getLogs(methodName: string): string {
Expand Down

0 comments on commit a220b5e

Please sign in to comment.