Skip to content

Commit

Permalink
standardized the custom comparisons unit tests (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubikowski authored Nov 14, 2022
1 parent a0008ce commit 08c5bfa
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 107 deletions.
30 changes: 16 additions & 14 deletions test/unit/comparisons/disjoint.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ function disjointTests<T>(testSets: TestSets<T>): void {
expect(disjoint(setD, setE, setF)).toBe(true);
});

it('disjoint sets with decreasing cardinality are disjoint', () => {
expect(disjoint(setA, setD)).toBe(true);
});

it('disjoint sets with increasing cardinality are disjoint', () => {
expect(disjoint(setD, setA)).toBe(true);
});

it('many sets with some shared elements of the first are not disjoint', () => {
expect(disjoint(setA, setB, setC, setD, setE, setF)).toBe(false);
});
Expand All @@ -54,6 +62,10 @@ function disjointTests<T>(testSets: TestSets<T>): void {
expect(disjoint(setF, setE, setD, setC, setB, setA)).toBe(true);
});

it('the empty set is disjoint with itself', () => {
expect(disjoint(empty, empty)).toBe(true);
});

it('any non-empty set and the empty set are disjoint', () => {
expect(disjoint(setA, empty)).toBe(true);
});
Expand All @@ -70,21 +82,11 @@ function disjointTests<T>(testSets: TestSets<T>): void {
expect(disjoint(universal, setA)).toBe(false);
});

it('the empty set is disjoint with itself', () => {
expect(disjoint(empty, empty)).toBe(true);
});

/* custom disjoint tests */

it('two sets with no shared elements are disjoint', () => {
expect(disjoint(setA, setD)).toBe(true);
});

it('many sets with no shared elements are disjoint', () => {
expect(disjoint(setA, setD, setE, setF)).toBe(true);
it('the empty set is disjoint from every non-empty set', () => {
expect(disjoint(empty, setA, setB, setC, setD, setE, setF, universal)).toBe(true);
});

it('a set & many of another set with no shared elements are disjoint', () => {
expect(disjoint(setA, setD, setD, setD)).toBe(true);
it('the universal set is not disjoint from every non-universal set', () => {
expect(disjoint(universal, setF, setE, setD, setC, setB, setA, empty)).toBe(false);
});
}
24 changes: 17 additions & 7 deletions test/unit/comparisons/equivalence.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('equivalence', () => {
});

function equivalenceTests<T>(testSets: TestSets<T>): void {
const { empty, minimal, setA, setB, setC, setD, setE, setF, universal } = testSets;
const { empty, setA, setB, setC, setD, setE, setF, universal } = testSets;

it('no sets are equivalent', () => {
expect(equivalence()).toBe(true);
Expand Down Expand Up @@ -46,6 +46,14 @@ function equivalenceTests<T>(testSets: TestSets<T>): void {
expect(equivalence(setD, setE, setF)).toBe(false);
});

it('disjoint sets with decreasing cardinality are not equivalent', () => {
expect(equivalence(setA, setD)).toBe(false);
});

it('disjoint sets with increasing cardinality are not equivalent', () => {
expect(equivalence(setD, setA)).toBe(false);
});

it('many different sets are not equivalent', () => {
expect(equivalence(setA, setB, setC, setD, setE, setF)).toBe(false);
});
Expand All @@ -54,6 +62,10 @@ function equivalenceTests<T>(testSets: TestSets<T>): void {
expect(equivalence(setF, setE, setD, setC, setB, setA)).toBe(false);
});

it('the empty set is equivalent to itself', () => {
expect(equivalence(empty, empty)).toBe(true);
});

it('any non-empty set and the empty set are not equivalent', () => {
expect(equivalence(setA, empty)).toBe(false);
});
Expand All @@ -70,13 +82,11 @@ function equivalenceTests<T>(testSets: TestSets<T>): void {
expect(equivalence(universal, setA)).toBe(false);
});

it('the empty set is equivalent to itself', () => {
expect(equivalence(empty, empty)).toBe(true);
it('the empty set is not equivalent to every non-empty set', () => {
expect(equivalence(empty, setA, setB, setC, setD, setE, setF, universal)).toBe(false);
});

/* custom equivalence tests */

it('two sets with different cardinalities are not equivalent', () => {
expect(equivalence(setA, minimal)).toBe(false);
it('the universal set is not equivalent to every non-universal set', () => {
expect(equivalence(universal, setF, setE, setD, setC, setB, setA, empty)).toBe(false);
});
}
30 changes: 16 additions & 14 deletions test/unit/comparisons/pairwise-disjoint.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ function pairwiseDisjointTests<T>(testSets: TestSets<T>): void {
expect(pairwiseDisjoint(setD, setE, setF)).toBe(true);
});

it('disjoint sets with decreasing cardinality are pairwise disjoint', () => {
expect(pairwiseDisjoint(setA, setD)).toBe(true);
});

it('disjoint sets with increasing cardinality are pairwise disjoint', () => {
expect(pairwiseDisjoint(setD, setA)).toBe(true);
});

it('many sets with some shared elements are not pairwise disjoint', () => {
expect(pairwiseDisjoint(setA, setB, setC, setD, setE, setF)).toBe(false);
});
Expand All @@ -54,6 +62,10 @@ function pairwiseDisjointTests<T>(testSets: TestSets<T>): void {
expect(pairwiseDisjoint(setF, setE, setD, setC, setB, setA)).toBe(false);
});

it('the empty set is pairwise disjoint with itself', () => {
expect(pairwiseDisjoint(empty, empty)).toBe(true);
});

it('any non-empty set and the empty set are pairwise disjoint', () => {
expect(pairwiseDisjoint(setA, empty)).toBe(true);
});
Expand All @@ -70,21 +82,11 @@ function pairwiseDisjointTests<T>(testSets: TestSets<T>): void {
expect(pairwiseDisjoint(universal, setA)).toBe(false);
});

it('the empty set is pairwise disjoint with itself', () => {
expect(pairwiseDisjoint(empty, empty)).toBe(true);
});

/* custom pairwise disjoint tests */

it('two sets with no shared elements are pairwise disjoint', () => {
expect(pairwiseDisjoint(setA, setD)).toBe(true);
});

it('many sets with no shared elements are pairwise disjoint', () => {
expect(pairwiseDisjoint(setA, setD, setE, setF)).toBe(true);
it('the empty set is not pairwise disjoint to every non-empty set and the universal set', () => {
expect(pairwiseDisjoint(empty, setA, setB, setC, setD, setE, setF, universal)).toBe(false);
});

it('a set & many of another set with no shared elements are not pairwise disjoint', () => {
expect(pairwiseDisjoint(setA, setD, setD, setD)).toBe(false);
it('the universal set is not pairwise disjoint to every non-universal set', () => {
expect(pairwiseDisjoint(universal, setF, setE, setD, setC, setB, setA, empty)).toBe(false);
});
}
32 changes: 17 additions & 15 deletions test/unit/comparisons/proper-subset.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('proper subset', () => {
});

function properSubsetTests<T>(testSets: TestSets<T>): void {
const { empty, minimal, setA, setB, setC, setD, setE, setF, universal } = testSets;
const { empty, setA, setB, setC, setD, setE, setF, universal } = testSets;

it('no sets are proper subsets', () => {
expect(properSubset()).toBe(true);
Expand Down Expand Up @@ -46,6 +46,14 @@ function properSubsetTests<T>(testSets: TestSets<T>): void {
expect(properSubset(setD, setE, setF)).toBe(false);
});

it('disjoint sets with decreasing cardinality are not proper subsets', () => {
expect(properSubset(setA, setD)).toBe(false);
});

it('disjoint sets with increasing cardinality are not proper subsets', () => {
expect(properSubset(setD, setA)).toBe(false);
});

it('many sets with different elements are not proper subsets', () => {
expect(properSubset(setA, setB, setC, setD, setE, setF)).toBe(false);
});
Expand All @@ -54,6 +62,10 @@ function properSubsetTests<T>(testSets: TestSets<T>): void {
expect(properSubset(setF, setE, setD, setC, setB, setA)).toBe(false);
});

it('the empty set is not a proper subset of itself', () => {
expect(properSubset(empty, empty)).toBe(false);
});

it('any non-empty set is not a proper subset of the empty set', () => {
expect(properSubset(setA, empty)).toBe(false);
});
Expand All @@ -70,21 +82,11 @@ function properSubsetTests<T>(testSets: TestSets<T>): void {
expect(properSubset(universal, setA)).toBe(false);
});

it('the empty set is not a proper subset of itself', () => {
expect(properSubset(empty, empty)).toBe(false);
});

/* custom proper subset tests */

it('following sets with lower cardinalities are not proper subsets', () => {
expect(properSubset(setA, minimal)).toBe(false);
});

it('sets without element bijection are not proper subsets', () => {
expect(properSubset(setD, setA)).toBe(false);
it('the empty set is a proper subset of every non-empty set', () => {
expect(properSubset(empty, setA, setB, setC, setD, setE, setF, universal)).toBe(true);
});

it('the empty set is a proper subset of every non-empty set', () => {
expect(properSubset(empty, minimal, setA, setB, setC, universal)).toBe(true);
it('the universal set is not a proper subset of every non-universal set', () => {
expect(properSubset(universal, setF, setE, setD, setC, setB, setA, empty)).toBe(false);
});
}
30 changes: 16 additions & 14 deletions test/unit/comparisons/proper-superset.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('proper superset', () => {
});

function properSupersetTests<T>(testSets: TestSets<T>): void {
const { empty, minimal, setA, setB, setC, setD, setE, setF, universal } = testSets;
const { empty, setA, setB, setC, setD, setE, setF, universal } = testSets;

it('no sets are proper supersets', () => {
expect(properSuperset()).toBe(true);
Expand Down Expand Up @@ -46,6 +46,14 @@ function properSupersetTests<T>(testSets: TestSets<T>): void {
expect(properSuperset(setD, setE, setF)).toBe(false);
});

it('disjoint sets with decreasing cardinality are not proper supersets', () => {
expect(properSuperset(setA, setD)).toBe(false);
});

it('disjoint sets with increasing cardinality are not proper supersets', () => {
expect(properSuperset(setD, setA)).toBe(false);
});

it('many sets with different elements are not proper supersets', () => {
expect(properSuperset(setA, setB, setC, setD, setE, setF)).toBe(false);
});
Expand All @@ -54,6 +62,10 @@ function properSupersetTests<T>(testSets: TestSets<T>): void {
expect(properSuperset(setF, setE, setD, setC, setB, setA)).toBe(false);
});

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

it('any non-empty set is a proper superset of the empty set', () => {
expect(properSuperset(setA, empty)).toBe(true);
});
Expand All @@ -70,21 +82,11 @@ function properSupersetTests<T>(testSets: TestSets<T>): void {
expect(properSuperset(universal, setA)).toBe(true);
});

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

/* custom proper superset tests */

it('following sets with greater cardinalities are not proper supersets', () => {
expect(properSuperset(minimal, setA)).toBe(false);
});

it('sets without element bijection are not proper supersets', () => {
expect(properSuperset(setA, setD)).toBe(false);
it('the empty set is not a proper superset of every non-empty set', () => {
expect(properSuperset(empty, setA, setB, setC, setD, setE, setF, universal)).toBe(false);
});

it('the universal set is a proper superset of every non-universal set', () => {
expect(properSuperset(universal, setA, setB, setC, minimal, empty)).toBe(true);
expect(properSuperset(universal, setF, setE, setD, setC, setB, setA, empty)).toBe(true);
});
}
32 changes: 17 additions & 15 deletions test/unit/comparisons/subset.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('subset', () => {
});

function subsetTests<T>(testSets: TestSets<T>): void {
const { empty, minimal, setA, setB, setC, setD, setE, setF, universal } = testSets;
const { empty, setA, setB, setC, setD, setE, setF, universal } = testSets;

it('no sets are subsets', () => {
expect(subset()).toBe(true);
Expand Down Expand Up @@ -46,6 +46,14 @@ function subsetTests<T>(testSets: TestSets<T>): void {
expect(subset(setD, setE, setF)).toBe(false);
});

it('disjoint sets with decreasing cardinality are not subsets', () => {
expect(subset(setA, setD)).toBe(false);
});

it('disjoint sets with increasing cardinality are not subsets', () => {
expect(subset(setD, setA)).toBe(false);
});

it('many sets with different elements are not subsets', () => {
expect(subset(setA, setB, setC, setD, setE, setF)).toBe(false);
});
Expand All @@ -54,6 +62,10 @@ function subsetTests<T>(testSets: TestSets<T>): void {
expect(subset(setF, setE, setD, setC, setB, setA)).toBe(false);
});

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

it('any non-empty set is not a subset of the empty set', () => {
expect(subset(setA, empty)).toBe(false);
});
Expand All @@ -70,21 +82,11 @@ function subsetTests<T>(testSets: TestSets<T>): void {
expect(subset(universal, setA)).toBe(false);
});

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

/* custom subset tests */

it('following sets with lower cardinalities are not subsets', () => {
expect(subset(setA, minimal)).toBe(false);
});

it('sets without element bijection are not subsets', () => {
expect(subset(setD, setA)).toBe(false);
it('the empty set is a subset of every non-empty set', () => {
expect(subset(empty, setA, setB, setC, setD, setE, setF, universal)).toBe(true);
});

it('the empty set is a subset of every set', () => {
expect(subset(empty, minimal, setA, setB, setC, universal)).toBe(true);
it('the universal set is not a subset of every non-universal set', () => {
expect(subset(universal, setF, setE, setD, setC, setB, setA, empty)).toBe(false);
});
}
32 changes: 17 additions & 15 deletions test/unit/comparisons/superset.function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('superset', () => {
});

function supersetTests<T>(testSets: TestSets<T>): void {
const { empty, minimal, setA, setB, setC, setD, setE, setF, universal } = testSets;
const { empty, setA, setB, setC, setD, setE, setF, universal } = testSets;

it('no sets are superset', () => {
expect(superset()).toBe(true);
Expand Down Expand Up @@ -46,6 +46,14 @@ function supersetTests<T>(testSets: TestSets<T>): void {
expect(superset(setD, setE, setF)).toBe(false);
});

it('disjoint sets with decreasing cardinality are not supersets', () => {
expect(superset(setA, setD)).toBe(false);
});

it('disjoint sets with increasing cardinality are not supersets', () => {
expect(superset(setD, setA)).toBe(false);
});

it('many sets with different elements are not supersets', () => {
expect(superset(setA, setB, setC, setD, setE, setF)).toBe(false);
});
Expand All @@ -54,6 +62,10 @@ function supersetTests<T>(testSets: TestSets<T>): void {
expect(superset(setF, setE, setD, setC, setB, setA)).toBe(false);
});

it('the empty set is a superset of itself', () => {
expect(superset(empty, empty)).toBe(true);
});

it('any non-empty set is a superset of the empty set', () => {
expect(superset(setA, empty)).toBe(true);
});
Expand All @@ -70,21 +82,11 @@ function supersetTests<T>(testSets: TestSets<T>): void {
expect(superset(universal, setA)).toBe(true);
});

it('the empty set is a superset of itself', () => {
expect(superset(empty, empty)).toBe(true);
});

/* custom superset tests */

it('following sets with greater cardinalities are not supersets', () => {
expect(superset(minimal, setA)).toBe(false);
});

it('sets without element bijection are not supersets', () => {
expect(superset(setA, setD)).toBe(false);
it('the empty set is not a superset of every non-empty set', () => {
expect(superset(empty, setA, setB, setC, setD, setE, setF, universal)).toBe(false);
});

it('the universal set is a superset of every set', () => {
expect(superset(universal, setA, setB, setC, minimal, empty)).toBe(true);
it('the universal set is a superset of every non-universal set', () => {
expect(superset(universal, setF, setE, setD, setC, setB, setA, empty)).toBe(true);
});
}
Loading

0 comments on commit 08c5bfa

Please sign in to comment.