Skip to content

Commit

Permalink
added unit tests (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubikowski authored Oct 31, 2022
1 parent 3de18d9 commit ecabf5f
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 38 deletions.
18 changes: 13 additions & 5 deletions test/comparisons/disjoint.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from '@jest/globals';
import { disjoint } from '../../src';
import { empty, setA, setB, setC, setD } from '../constants/testing-constants';
import { empty, setA, setB, setC, setD, setE, setF, universal } from '../constants/testing-constants';

describe('disjoint', () => {
it('no sets are disjoint', () => {
Expand All @@ -27,16 +27,24 @@ describe('disjoint', () => {
expect(disjoint(setA, setB, setC)).toBe(false);
});

it('many sets with some shared values are not disjoint', () => {
expect(disjoint(setA, setB, setC, setD, setE, setF)).toBe(false);
});

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

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

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

/* custom disjoint tests */

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

it('two sets with no shared values are disjoint', () => {
expect(disjoint(setA, setD)).toBe(true);
});
Expand Down
14 changes: 13 additions & 1 deletion test/comparisons/equivalence.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from '@jest/globals';
import { equivalence } from '../../src';
import { empty, minimal, setA, setB, setC } from '../constants/testing-constants';
import { empty, minimal, setA, setB, setC, setD, setE, setF, universal } from '../constants/testing-constants';

describe('equivalence', () => {
it('no sets are equivalent', () => {
Expand All @@ -27,6 +27,18 @@ describe('equivalence', () => {
expect(equivalence(setA, setB, setC)).toBe(false);
});

it('many different sets are not equivalent', () => {
expect(equivalence(setA, setB, setC, setD, setE, setF)).toBe(false);
});

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

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

it('the empty set is equivalent to itself', () => {
expect(equivalence(empty, empty)).toBe(true);
});
Expand Down
18 changes: 13 additions & 5 deletions test/comparisons/proper-subset.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from '@jest/globals';
import { properSubset } from '../../src';
import { empty, minimal, setA, setB, setC, setD, universal } from '../constants/testing-constants';
import { empty, minimal, setA, setB, setC, setD, setE, setF, universal } from '../constants/testing-constants';

describe('proper subset', () => {
it('no sets are proper subsets', () => {
Expand All @@ -27,6 +27,18 @@ describe('proper subset', () => {
expect(properSubset(setA, setB, setC)).toBe(false);
});

it('many sets with different values are not proper subsets', () => {
expect(properSubset(setA, setB, setC, setD, setE, setF)).toBe(false);
});

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

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

it('the empty set is not a proper subset of itself', () => {
expect(properSubset(empty, empty)).toBe(false);
});
Expand All @@ -41,10 +53,6 @@ describe('proper subset', () => {
expect(properSubset(setD, setA)).toBe(false);
});

it('any non-universal set is a proper subset of the universal set', () => {
expect(properSubset(setA, 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);
});
Expand Down
18 changes: 13 additions & 5 deletions test/comparisons/proper-superset.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from '@jest/globals';
import { properSuperset } from '../../src';
import { empty, minimal, setA, setB, setC, setD, universal } from '../constants/testing-constants';
import { empty, minimal, setA, setB, setC, setD, setE, setF, universal } from '../constants/testing-constants';

describe('proper superset', () => {
it('no sets are proper supersets', () => {
Expand All @@ -27,6 +27,18 @@ describe('proper superset', () => {
expect(properSuperset(setA, setB, setC)).toBe(false);
});

it('many sets with different values are not proper supersets', () => {
expect(properSuperset(setA, setB, setC, setD, setE, setF)).toBe(false);
});

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

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

it('the empty set is not a proper superset of itself', () => {
expect(properSuperset(empty, empty)).toBe(false);
});
Expand All @@ -41,10 +53,6 @@ describe('proper superset', () => {
expect(properSuperset(setA, setD)).toBe(false);
});

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

it('the universal set is a proper superset of every non-universal set', () => {
expect(properSuperset(universal, setA, setB, setC, minimal, empty)).toBe(true);
});
Expand Down
18 changes: 13 additions & 5 deletions test/comparisons/subset.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from '@jest/globals';
import { subset } from '../../src';
import { empty, minimal, setA, setB, setC, setD, universal } from '../constants/testing-constants';
import { empty, minimal, setA, setB, setC, setD, setE, setF, universal } from '../constants/testing-constants';

describe('subset', () => {
it('no sets are subsets', () => {
Expand All @@ -27,6 +27,18 @@ describe('subset', () => {
expect(subset(setA, setB, setC)).toBe(false);
});

it('many sets with different values are not subsets', () => {
expect(subset(setA, setB, setC, setD, setE, setF)).toBe(false);
});

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

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

it('the empty set is a subset of itself', () => {
expect(subset(empty, empty)).toBe(true);
});
Expand All @@ -41,10 +53,6 @@ describe('subset', () => {
expect(subset(setD, setA)).toBe(false);
});

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

it('the empty set is a subset of every set', () => {
expect(subset(empty, minimal, setA, setB, setC, universal)).toBe(true);
});
Expand Down
18 changes: 13 additions & 5 deletions test/comparisons/superset.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from '@jest/globals';
import { superset } from '../../src';
import { empty, minimal, setA, setB, setC, setD, universal } from '../constants/testing-constants';
import { empty, minimal, setA, setB, setC, setD, setE, setF, universal } from '../constants/testing-constants';

describe('superset', () => {
it('no sets are superset', () => {
Expand All @@ -27,6 +27,18 @@ describe('superset', () => {
expect(superset(setA, setB, setC)).toBe(false);
});

it('many sets with different values are not supersets', () => {
expect(superset(setA, setB, setC, setD, setE, setF)).toBe(false);
});

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

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

it('the empty set is a superset of itself', () => {
expect(superset(empty, empty)).toBe(true);
});
Expand All @@ -41,10 +53,6 @@ describe('superset', () => {
expect(superset(setA, setD)).toBe(false);
});

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

it('the universal set is a superset of every set', () => {
expect(superset(universal, setA, setB, setC, minimal, empty)).toBe(true);
});
Expand Down
4 changes: 2 additions & 2 deletions test/constants/sort-testing-constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from '@jest/globals';

/* unordered universal set, contains: 0, 1, 2, 3, 4, 5, 6, 7 */
export const unordered = new Set([ 4, 6, 1, 2, 5, 7, 0, 3 ]);
/* unordered universal set, contains: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 */
export const unordered = new Set([ 4, 9, 6, 1, 8, 2, 5, 7, 0, 3 ]);

/* (default) less than comparator function */
export function defaultComparator<T>(a: T, b: T): number {
Expand Down
10 changes: 8 additions & 2 deletions test/constants/testing-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* - 5: unique to setB
* - 6: unique to setC
* - 7: unique to setD
* - 8: unique to setE
* - 9: unique to setF
*/

/* contains: 0 */
Expand All @@ -21,8 +23,12 @@ export const setB = new Set<number>([ 0, 1, 3, 5 ]);
export const setC = new Set<number>([ 0, 2, 3, 6 ]);
/* contains: 7 */
export const setD = new Set<number>([ 7 ]);
/* contains: 7 */
export const setE = new Set<number>([ 8 ]);
/* contains: 7 */
export const setF = new Set<number>([ 9 ]);

/* the universal set: U, contains: 0, 1, 2, 3, 4, 5, 6, 7 */
export const universal = new Set<number>([ 0, 1, 2, 3, 4, 5, 6, 7 ]);
/* the universal set: U, contains: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 */
export const universal = new Set<number>([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]);
/* the empty set: ∅, contains: none */
export const empty = new Set<never>();
17 changes: 16 additions & 1 deletion test/operations/difference.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from '@jest/globals';
import { difference, equivalence } from '../../src';
import { empty, setA, setB, setC, universal } from '../constants/testing-constants';
import { empty, setA, setB, setC, setD, setE, setF, universal } from '../constants/testing-constants';

describe('difference', () => {
const differenceAB = new Set<number>([ 2, 4 ]);
Expand All @@ -21,6 +21,11 @@ describe('difference', () => {
expect(equivalence(result, empty)).toBe(true);
});

it('many of the same set has no difference overlap', () => {
const result = difference(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 @@ -31,6 +36,11 @@ describe('difference', () => {
expect(equivalence(result, differenceABC)).toBe(true);
});

it('many sets\' difference is a subset of the first', () => {
const result = difference(setA, setB, setC, setD, setE, setF);
expect(equivalence(result, differenceABC)).toBe(true);
});

it('any sets\' difference with the empty set is itself', () => {
const result = difference(setA, empty);
expect(equivalence(result, setA)).toBe(true);
Expand All @@ -40,4 +50,9 @@ describe('difference', () => {
const result = difference(setA, universal);
expect(equivalence(result, empty)).toBe(true);
});

it('the empty sets\' difference with itself is itself', () => {
const result = difference(empty, empty);
expect(equivalence(result, empty)).toBe(true);
});
});
17 changes: 16 additions & 1 deletion test/operations/intersection.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from '@jest/globals';
import { equivalence, intersection } from '../../src';
import { empty, setA, setB, setC, universal } from '../constants/testing-constants';
import { empty, setA, setB, setC, setD, setE, setF, universal } from '../constants/testing-constants';

describe('intersection', () => {
const intersectionAB = new Set<number>([ 0, 1 ]);
Expand All @@ -21,6 +21,11 @@ describe('intersection', () => {
expect(equivalence(result, setA)).toBe(true);
});

it('many of the same set intersection returns self', () => {
const result = intersection(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 @@ -31,6 +36,11 @@ describe('intersection', () => {
expect(equivalence(result, intersectionABC)).toBe(true);
});

it('many sets\' intersection is a subset of the first', () => {
const result = intersection(setA, setB, setC, setD, setE, setF);
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 All @@ -40,4 +50,9 @@ describe('intersection', () => {
const result = intersection(setA, universal);
expect(equivalence(result, setA)).toBe(true);
});

it('the empty sets\' intersection with itself is itself', () => {
const result = intersection(empty, empty);
expect(equivalence(result, empty)).toBe(true);
});
});
17 changes: 16 additions & 1 deletion test/operations/union.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from '@jest/globals';
import { equivalence, union } from '../../src';
import { empty, setA, setB, setC, universal } from '../constants/testing-constants';
import { empty, setA, setB, setC, setD, setE, setF, universal } from '../constants/testing-constants';

describe('union', () => {
const unionAB = new Set<number>([ 0, 1, 2, 3, 4, 5 ]);
Expand All @@ -21,6 +21,11 @@ describe('union', () => {
expect(equivalence(result, setA)).toBe(true);
});

it('many of the same set union returns self', () => {
const result = union(setA, setA, setA);
expect(equivalence(result, setA)).toBe(true);
});

it('two sets\' union contains all values from both sets', () => {
const result = union(setA, setB);
expect(equivalence(result, unionAB)).toBe(true);
Expand All @@ -31,6 +36,11 @@ describe('union', () => {
expect(equivalence(result, unionABC)).toBe(true);
});

it('many sets\' union contains all values from all sets', () => {
const result = union(setA, setB, setC, setD, setE, setF);
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 All @@ -40,4 +50,9 @@ describe('union', () => {
const result = union(setA, universal);
expect(equivalence(result, universal)).toBe(true);
});

it('the empty sets\' union with itself is itself', () => {
const result = union(empty, empty);
expect(equivalence(result, empty)).toBe(true);
});
});
Loading

0 comments on commit ecabf5f

Please sign in to comment.