-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.spec.ts
85 lines (80 loc) · 2.65 KB
/
index.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import {generatePermutations, getPermutations} from '../../src';
import * as fixtures from '../__fixtures__';
describe('Test suite covering getPermutations()', () => {
test.each(fixtures.invalidArgTestCases)(
'An error is thrown when %s is provided as an arg',
arg => {
// @ts-ignore
expect(() => getPermutations(arg)).toThrow();
}
);
for (const testCase of fixtures.permutables) {
test(testCase.description, () => {
expect(getPermutations(testCase.permutable)).toEqual(testCase.expected);
});
}
});
describe('Test suite covering generatePermutations()', () => {
test.each(fixtures.invalidArgTestCases)(
'An error is thrown when %s is provided as an arg',
arg => {
// @ts-ignore
const generator = generatePermutations(arg);
expect(() => generator.next().value).toThrow();
}
);
for (const testCase of fixtures.permutables) {
test(testCase.description, () => {
expect([...generatePermutations(testCase.permutable)]).toEqual(
testCase.expected
);
});
}
});
// const getNaturalNumberArrayUpTo = (limit: number) => [
// ...Array(limit)
// .fill('')
// .map((val, idx) => idx + 1),
// ];
//
// describe('Performance Testing for getPermutations()', () => {
// const testCases = getNaturalNumberArrayUpTo(6).map(String);
// test.each(testCases)('Performance of 10^%s permutations', pow => {
// const obj = [...Array(Number(6)).fill('')].reduce(
// (prevObj, val, idx) => ({
// ...prevObj,
// [idx]: getNaturalNumberArrayUpTo(10),
// }),
// {}
// );
//
// const start = new Date().getTime();
// getPermutations(obj);
// const end = new Date().getTime() - start;
// console.log(`Calculation of 10^${pow} permutations took ${end}ms`);
// });
// });
//
// describe('Performance Testing for generatePermutations()', () => {
// const testCases = getNaturalNumberArrayUpTo(7).map(String);
// test.each(testCases)('Performance of 10^%s permutations', pow => {
// const obj = [...Array(Number(pow)).fill('')].reduce(
// (prevObj, val, idx) => ({
// ...prevObj,
// [idx]: getNaturalNumberArrayUpTo(10),
// }),
// {}
// );
//
// let permutationsGenerated = 0;
// const start = new Date().getTime();
// // eslint-disable-next-line @typescript-eslint/no-unused-vars
// for (const permutation of generatePermutations(obj)) {
// permutationsGenerated++;
// }
// const end = new Date().getTime() - start;
//
// console.log(`Generated ${permutationsGenerated} permutations`);
// console.log(`Calculation of 10^${pow} permutations took ${end}ms`);
// });
// });