Skip to content

Commit e327fad

Browse files
committed
Update GeneratePermutations.test.js
Original test was very limited and also (unnecessarily) strict in that the order of results mattered. I've tweaked the original test so that results can come in any order. Also added additional tests for smaller arrays of strings/booleans. Finally added some sanity testing for larger input arrays.
1 parent e8af126 commit e327fad

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed
Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
import { permutations } from '../GeneratePermutations'
22

33
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+
417
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)
1331
})
1432
})

0 commit comments

Comments
 (0)