Skip to content

Commit

Permalink
added all builtins unit tests (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubikowski authored Nov 7, 2022
1 parent 6875ff4 commit cd90e3f
Show file tree
Hide file tree
Showing 24 changed files with 252 additions and 74 deletions.
8 changes: 2 additions & 6 deletions test/comparisons/disjoint.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { describe, expect, it } from '@jest/globals';
import { disjoint } from '../../src';
import { NumberTestSets } from '../util/test-sets/number-test-sets.model';
import { StringTestSets } from '../util/test-sets/string-test-sets.model';
import { SymbolTestSets } from '../util/test-sets/symbol-test-sets.model';
import { TestSets } from '../util/test-sets/test-sets.model';
import { testSuite } from '../util/test-suite.function';

describe('disjoint', () => {
describe('disjoint ⋅ number', () => disjointTests(new NumberTestSets()));
describe('disjoint ⋅ string', () => disjointTests(new StringTestSets()));
describe('disjoint ⋅ symbol', () => disjointTests(new SymbolTestSets()));
testSuite('disjoint', disjointTests);
});

function disjointTests<T>(testSets: TestSets<T>): void {
Expand Down
8 changes: 2 additions & 6 deletions test/comparisons/equivalence.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { describe, expect, it } from '@jest/globals';
import { equivalence } from '../../src';
import { NumberTestSets } from '../util/test-sets/number-test-sets.model';
import { StringTestSets } from '../util/test-sets/string-test-sets.model';
import { SymbolTestSets } from '../util/test-sets/symbol-test-sets.model';
import { TestSets } from '../util/test-sets/test-sets.model';
import { testSuite } from '../util/test-suite.function';

describe('equivalence', () => {
describe('equivalence ⋅ number', () => equivalenceTests(new NumberTestSets()));
describe('equivalence ⋅ string', () => equivalenceTests(new StringTestSets()));
describe('equivalence ⋅ symbol', () => equivalenceTests(new SymbolTestSets()));
testSuite('equivalence', equivalenceTests);
});

function equivalenceTests<T>(testSets: TestSets<T>): void {
Expand Down
8 changes: 2 additions & 6 deletions test/comparisons/pairwise-disjoint.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { describe, expect, it } from '@jest/globals';
import { pairwiseDisjoint } from '../../src';
import { NumberTestSets } from '../util/test-sets/number-test-sets.model';
import { StringTestSets } from '../util/test-sets/string-test-sets.model';
import { SymbolTestSets } from '../util/test-sets/symbol-test-sets.model';
import { TestSets } from '../util/test-sets/test-sets.model';
import { testSuite } from '../util/test-suite.function';

describe('pairwise disjoint', () => {
describe('pairwise disjoint ⋅ number', () => pairwiseDisjointTests(new NumberTestSets()));
describe('pairwise disjoint ⋅ string', () => pairwiseDisjointTests(new StringTestSets()));
describe('pairwise disjoint ⋅ symbol', () => pairwiseDisjointTests(new SymbolTestSets()));
testSuite('pairwise disjoint', pairwiseDisjointTests);
});

function pairwiseDisjointTests<T>(testSets: TestSets<T>): void {
Expand Down
8 changes: 2 additions & 6 deletions test/comparisons/proper-subset.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { describe, expect, it } from '@jest/globals';
import { properSubset } from '../../src';
import { NumberTestSets } from '../util/test-sets/number-test-sets.model';
import { StringTestSets } from '../util/test-sets/string-test-sets.model';
import { SymbolTestSets } from '../util/test-sets/symbol-test-sets.model';
import { TestSets } from '../util/test-sets/test-sets.model';
import { testSuite } from '../util/test-suite.function';

describe('proper subset', () => {
describe('proper subset ⋅ number', () => properSubsetTests(new NumberTestSets()));
describe('proper subset ⋅ string', () => properSubsetTests(new StringTestSets()));
describe('proper subset ⋅ symbol', () => properSubsetTests(new SymbolTestSets()));
testSuite('proper subset', properSubsetTests);
});

function properSubsetTests<T>(testSets: TestSets<T>): void {
Expand Down
8 changes: 2 additions & 6 deletions test/comparisons/proper-superset.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { describe, expect, it } from '@jest/globals';
import { properSuperset } from '../../src';
import { NumberTestSets } from '../util/test-sets/number-test-sets.model';
import { StringTestSets } from '../util/test-sets/string-test-sets.model';
import { SymbolTestSets } from '../util/test-sets/symbol-test-sets.model';
import { TestSets } from '../util/test-sets/test-sets.model';
import { testSuite } from '../util/test-suite.function';

describe('proper superset', () => {
describe('proper superset ⋅ number', () => properSupersetTests(new NumberTestSets()));
describe('proper superset ⋅ string', () => properSupersetTests(new StringTestSets()));
describe('proper superset ⋅ symbol', () => properSupersetTests(new SymbolTestSets()));
testSuite('proper superset', properSupersetTests);
});

function properSupersetTests<T>(testSets: TestSets<T>): void {
Expand Down
8 changes: 2 additions & 6 deletions test/comparisons/subset.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { describe, expect, it } from '@jest/globals';
import { subset } from '../../src';
import { NumberTestSets } from '../util/test-sets/number-test-sets.model';
import { StringTestSets } from '../util/test-sets/string-test-sets.model';
import { SymbolTestSets } from '../util/test-sets/symbol-test-sets.model';
import { TestSets } from '../util/test-sets/test-sets.model';
import { testSuite } from '../util/test-suite.function';

describe('subset', () => {
describe('subset ⋅ number', () => subsetTests(new NumberTestSets()));
describe('subset ⋅ string', () => subsetTests(new StringTestSets()));
describe('subset ⋅ symbol', () => subsetTests(new SymbolTestSets()));
testSuite('subset', subsetTests);
});

function subsetTests<T>(testSets: TestSets<T>): void {
Expand Down
8 changes: 2 additions & 6 deletions test/comparisons/superset.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { describe, expect, it } from '@jest/globals';
import { superset } from '../../src';
import { NumberTestSets } from '../util/test-sets/number-test-sets.model';
import { StringTestSets } from '../util/test-sets/string-test-sets.model';
import { SymbolTestSets } from '../util/test-sets/symbol-test-sets.model';
import { TestSets } from '../util/test-sets/test-sets.model';
import { testSuite } from '../util/test-suite.function';

describe('superset', () => {
describe('superset ⋅ number', () => supersetTests(new NumberTestSets()));
describe('superset ⋅ string', () => supersetTests(new StringTestSets()));
describe('superset ⋅ symbol', () => supersetTests(new SymbolTestSets()));
testSuite('superset', supersetTests);
});

function supersetTests<T>(testSets: TestSets<T>): void {
Expand Down
8 changes: 2 additions & 6 deletions test/operations/difference.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { describe, expect, it } from '@jest/globals';
import { difference, equivalence } from '../../src';
import { NumberTestSets } from '../util/test-sets/number-test-sets.model';
import { StringTestSets } from '../util/test-sets/string-test-sets.model';
import { SymbolTestSets } from '../util/test-sets/symbol-test-sets.model';
import { TestSets } from '../util/test-sets/test-sets.model';
import { testSuite } from '../util/test-suite.function';

describe('difference', () => {
describe('difference ⋅ number', () => differenceTests(new NumberTestSets()));
describe('difference ⋅ string', () => differenceTests(new StringTestSets()));
describe('difference ⋅ symbol', () => differenceTests(new SymbolTestSets()));
testSuite('difference', differenceTests);
});

function differenceTests<T>(testSets: TestSets<T>): void {
Expand Down
8 changes: 2 additions & 6 deletions test/operations/intersection.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { describe, expect, it } from '@jest/globals';
import { equivalence, intersection } from '../../src';
import { NumberTestSets } from '../util/test-sets/number-test-sets.model';
import { StringTestSets } from '../util/test-sets/string-test-sets.model';
import { SymbolTestSets } from '../util/test-sets/symbol-test-sets.model';
import { TestSets } from '../util/test-sets/test-sets.model';
import { testSuite } from '../util/test-suite.function';

describe('intersection', () => {
describe('intersection ⋅ number', () => intersectionTests(new NumberTestSets()));
describe('intersection ⋅ string', () => intersectionTests(new StringTestSets()));
describe('intersection ⋅ symbol', () => intersectionTests(new SymbolTestSets()));
testSuite('intersection', intersectionTests);
});

function intersectionTests<T>(testSets: TestSets<T>): void {
Expand Down
8 changes: 2 additions & 6 deletions test/operations/union.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { describe, expect, it } from '@jest/globals';
import { equivalence, union } from '../../src';
import { NumberTestSets } from '../util/test-sets/number-test-sets.model';
import { StringTestSets } from '../util/test-sets/string-test-sets.model';
import { SymbolTestSets } from '../util/test-sets/symbol-test-sets.model';
import { TestSets } from '../util/test-sets/test-sets.model';
import { testSuite } from '../util/test-suite.function';

describe('union', () => {
describe('union ⋅ number', () => unionTests(new NumberTestSets()));
describe('union ⋅ string', () => unionTests(new StringTestSets()));
describe('union ⋅ symbol', () => unionTests(new SymbolTestSets()));
testSuite('union', unionTests);
});

function unionTests<T>(testSets: TestSets<T>): void {
Expand Down
8 changes: 2 additions & 6 deletions test/operations/xor.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { describe, expect, it } from '@jest/globals';
import { equivalence, xor } from '../../src';
import { NumberTestSets } from '../util/test-sets/number-test-sets.model';
import { StringTestSets } from '../util/test-sets/string-test-sets.model';
import { SymbolTestSets } from '../util/test-sets/symbol-test-sets.model';
import { TestSets } from '../util/test-sets/test-sets.model';
import { testSuite } from '../util/test-suite.function';

describe('xor', () => {
describe('xor ⋅ number', () => xorTests(new NumberTestSets()));
describe('xor ⋅ string', () => xorTests(new StringTestSets()));
describe('xor ⋅ symbol', () => xorTests(new SymbolTestSets()));
testSuite('xor', xorTests);
});

function xorTests<T>(testSets: TestSets<T>): void {
Expand Down
12 changes: 4 additions & 8 deletions test/ordering/sort.function.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { describe, expect, it } from '@jest/globals';
import { equivalence, sort } from '../../src';
import { NumberTestSets } from '../util/test-sets/number-test-sets.model';
import { StringTestSets } from '../util/test-sets/string-test-sets.model';
import { SymbolTestSets } from '../util/test-sets/symbol-test-sets.model';
import { TestSets } from '../util/test-sets/test-sets.model';
import { testSuite } from '../util/test-suite.function';

describe('sort', () => {
describe('sort ⋅ number', () => sortTests(new NumberTestSets()));
describe('sort ⋅ string', () => sortTests(new StringTestSets()));
describe('sort ⋅ symbol', () => sortTests(new SymbolTestSets()));
testSuite('sort', sortTests);
});

function sortTests<T>(testSets: TestSets<T>): void {
Expand All @@ -20,7 +16,7 @@ function sortTests<T>(testSets: TestSets<T>): void {
expect(equivalence(result, empty)).toBe(true);
});

if (typeof a === 'number' || typeof a === 'string') {
if (testSets.canSortWithoutComparator) {
it('sorting a set returns an equivalent set', () => {
const result = sort(setA);
expect(equivalence(result, setA)).toBe(true);
Expand All @@ -39,7 +35,7 @@ function sortTests<T>(testSets: TestSets<T>): void {
expectSortedElements(result, ordered);
});

if (typeof a === 'number' || typeof a === 'string') {
if (testSets.willSortWithoutComparator) {
it('sorting an unordered set will order it', () => {
const ordered = Array.from(universal);
const result = sort(unordered);
Expand Down
9 changes: 9 additions & 0 deletions test/util/test-sets/array-test-sets.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { TestSets } from './test-sets.model';

type TestArray = [ number ];

export class ArrayTestSets extends TestSets<TestArray> {
public constructor() {
super([ 0 ], [ 1 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ], [ 6 ], [ 7 ], [ 8 ], [ 9 ]);
}
}
21 changes: 21 additions & 0 deletions test/util/test-sets/date-test-sets.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { TestSets } from './test-sets.model';

export class DateTestSets extends TestSets<Date> {

public override readonly willSortWithoutComparator = false;

public constructor() {
super(
new Date(0),
new Date(1),
new Date(2),
new Date(3),
new Date(4),
new Date(5),
new Date(6),
new Date(7),
new Date(8),
new Date(9),
);
}
}
20 changes: 20 additions & 0 deletions test/util/test-sets/enum-test-sets.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { TestSets } from './test-sets.model';

enum TestEnum { A, B, C, D, E, F, G, H, I, J }

export class EnumTestSets extends TestSets<TestEnum> {
public constructor() {
super(
TestEnum.A,
TestEnum.B,
TestEnum.C,
TestEnum.D,
TestEnum.E,
TestEnum.F,
TestEnum.G,
TestEnum.H,
TestEnum.I,
TestEnum.J,
);
}
}
18 changes: 18 additions & 0 deletions test/util/test-sets/error-test-sets.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { TestSets } from './test-sets.model';

export class ErrorTestSets extends TestSets<Error> {
public constructor() {
super(
new Error('a'),
new Error('b'),
new Error('c'),
new Error('d'),
new Error('e'),
new Error('f'),
new Error('g'),
new Error('h'),
new Error('i'),
new Error('j'),
);
}
}
20 changes: 20 additions & 0 deletions test/util/test-sets/function-test-sets.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { TestSets } from './test-sets.model';

type TestFunction = () => number;

export class FunctionTestSets extends TestSets<TestFunction> {
public constructor() {
super(
() => 0,
() => 1,
() => 2,
() => 3,
() => 4,
() => 5,
() => 6,
() => 7,
() => 8,
() => 9,
);
}
}
31 changes: 31 additions & 0 deletions test/util/test-sets/map-test-sets.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { TestSets } from './test-sets.model';

type TestMap = Map<'id', number>;

export class MapTestSets extends TestSets<TestMap> {

public override readonly willSortWithoutComparator = false;

public constructor() {
super(
new Map([[ 'id', 0 ]]),
new Map([[ 'id', 1 ]]),
new Map([[ 'id', 2 ]]),
new Map([[ 'id', 3 ]]),
new Map([[ 'id', 4 ]]),
new Map([[ 'id', 5 ]]),
new Map([[ 'id', 6 ]]),
new Map([[ 'id', 7 ]]),
new Map([[ 'id', 8 ]]),
new Map([[ 'id', 9 ]]),
);
}

public override defaultComparator(first: TestMap, second: TestMap): number {
return (first.get('id')! < second.get('id')!) ? -1 : 1;
}

public override reverseComparator(first: TestMap, second: TestMap): number {
return (first.get('id')! < second.get('id')!) ? 1 : -1;
}
}
31 changes: 31 additions & 0 deletions test/util/test-sets/object-test-sets.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { TestSets } from './test-sets.model';

type TestObject = { readonly id: number };

export class ObjectTestSets extends TestSets<TestObject> {

public override readonly willSortWithoutComparator = false;

public constructor() {
super(
{ id: 0 },
{ id: 1 },
{ id: 2 },
{ id: 3 },
{ id: 4 },
{ id: 5 },
{ id: 6 },
{ id: 7 },
{ id: 8 },
{ id: 9 },
);
}

public override defaultComparator(first: TestObject, second: TestObject): number {
return (first.id < second.id) ? -1 : 1;
}

public override reverseComparator(first: TestObject, second: TestObject): number {
return (first.id < second.id) ? 1 : -1;
}
}
7 changes: 7 additions & 0 deletions test/util/test-sets/reg-exp-test-sets.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TestSets } from './test-sets.model';

export class RegExpTestSets extends TestSets<RegExp> {
public constructor() {
super(/a/, /b/, /c/, /d/, /e/, /f/, /g/, /h/, /i/, /j/);
}
}
Loading

0 comments on commit cd90e3f

Please sign in to comment.