|
1 | 1 | import { permutations } from '../GeneratePermutations'
|
2 | 2 |
|
3 | 3 | describe('Permutations', () => {
|
| 4 | + it('Permutations of [a]', () => { |
| 5 | + const perms = permutations(['a']) |
| 6 | + expect(perms).toHaveLength(1) |
| 7 | + expect(perms).toContainEqual(['a']) |
| 8 | + }) |
| 9 | + |
| 10 | + it('Permutations of [true, false]', () => { |
| 11 | + const perms = permutations([true, false]) |
| 12 | + expect(perms).toHaveLength(2 * 1) |
| 13 | + expect(perms).toContainEqual([true, false]) |
| 14 | + expect(perms).toContainEqual([false, true]) |
| 15 | + }) |
| 16 | + |
4 | 17 | it('Permutations of [1, 2, 3]', () => {
|
5 |
| - expect(permutations([1, 2, 3])).toEqual([ |
6 |
| - [1, 2, 3], |
7 |
| - [1, 3, 2], |
8 |
| - [2, 1, 3], |
9 |
| - [2, 3, 1], |
10 |
| - [3, 1, 2], |
11 |
| - [3, 2, 1] |
12 |
| - ]) |
| 18 | + const perms = permutations([1, 2, 3]) |
| 19 | + expect(perms).toHaveLength(3 * 2 * 1) |
| 20 | + expect(perms).toContainEqual([1, 2, 3]) |
| 21 | + expect(perms).toContainEqual([1, 3, 2]) |
| 22 | + expect(perms).toContainEqual([2, 1, 3]) |
| 23 | + expect(perms).toContainEqual([2, 3, 1]) |
| 24 | + expect(perms).toContainEqual([3, 1, 2]) |
| 25 | + expect(perms).toContainEqual([3, 2, 1]) |
| 26 | + }) |
| 27 | + |
| 28 | + it('Permutation counts across larger input arrays', () => { |
| 29 | + expect(permutations([1, 2, 3, 4, 5, 6])).toHaveLength(720) |
| 30 | + expect(permutations([1, 2, 3, 4, 5, 6, 7])).toHaveLength(5040) |
13 | 31 | })
|
14 | 32 | })
|
0 commit comments