This repository has been archived by the owner on Dec 12, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
permutateWithoutRepetitions.test.js
71 lines (64 loc) · 2.08 KB
/
permutateWithoutRepetitions.test.js
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
import permutateWithoutRepetitions from '../permutateWithoutRepetitions';
import factorial from '../../../math/factorial/factorial';
describe('permutateWithoutRepetitions', () => {
it('should permutate string', () => {
const permutations0 = permutateWithoutRepetitions([]);
expect(permutations0).toEqual([]);
const permutations1 = permutateWithoutRepetitions(['A']);
expect(permutations1).toEqual([
['A'],
]);
const permutations2 = permutateWithoutRepetitions(['A', 'B']);
expect(permutations2.length).toBe(2);
expect(permutations2).toEqual([
['B', 'A'],
['A', 'B'],
]);
const permutations6 = permutateWithoutRepetitions(['A', 'A']);
expect(permutations6.length).toBe(2);
expect(permutations6).toEqual([
['A', 'A'],
['A', 'A'],
]);
const permutations3 = permutateWithoutRepetitions(['A', 'B', 'C']);
expect(permutations3.length).toBe(factorial(3));
expect(permutations3).toEqual([
['C', 'B', 'A'],
['B', 'C', 'A'],
['B', 'A', 'C'],
['C', 'A', 'B'],
['A', 'C', 'B'],
['A', 'B', 'C'],
]);
const permutations4 = permutateWithoutRepetitions(['A', 'B', 'C', 'D']);
expect(permutations4.length).toBe(factorial(4));
expect(permutations4).toEqual([
['D', 'C', 'B', 'A'],
['C', 'D', 'B', 'A'],
['C', 'B', 'D', 'A'],
['C', 'B', 'A', 'D'],
['D', 'B', 'C', 'A'],
['B', 'D', 'C', 'A'],
['B', 'C', 'D', 'A'],
['B', 'C', 'A', 'D'],
['D', 'B', 'A', 'C'],
['B', 'D', 'A', 'C'],
['B', 'A', 'D', 'C'],
['B', 'A', 'C', 'D'],
['D', 'C', 'A', 'B'],
['C', 'D', 'A', 'B'],
['C', 'A', 'D', 'B'],
['C', 'A', 'B', 'D'],
['D', 'A', 'C', 'B'],
['A', 'D', 'C', 'B'],
['A', 'C', 'D', 'B'],
['A', 'C', 'B', 'D'],
['D', 'A', 'B', 'C'],
['A', 'D', 'B', 'C'],
['A', 'B', 'D', 'C'],
['A', 'B', 'C', 'D'],
]);
const permutations5 = permutateWithoutRepetitions(['A', 'B', 'C', 'D', 'E', 'F']);
expect(permutations5.length).toBe(factorial(6));
});
});