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