Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 71d3d44

Browse filesBrowse files
authored
tests: improve for GeneratePermutations (TheAlgorithms#1263)
1 parent 9d4adbb commit 71d3d44
Copy full SHA for 71d3d44

File tree

Expand file treeCollapse file tree

1 file changed

+27
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+27
-8
lines changed
Open diff view settings
Collapse file
+27-8Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
1+
import { factorial } from '../../Recursive/Factorial'
12
import { permutations } from '../GeneratePermutations'
23

34
describe('Permutations', () => {
5+
it('Permutations of [a]', () => {
6+
const perms = permutations(['a'])
7+
expect(perms).toHaveLength(factorial(1))
8+
expect(perms).toContainEqual(['a'])
9+
})
10+
11+
it('Permutations of [true, false]', () => {
12+
const perms = permutations([true, false])
13+
expect(perms).toHaveLength(factorial(2))
14+
expect(perms).toContainEqual([true, false])
15+
expect(perms).toContainEqual([false, true])
16+
})
17+
418
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+
const perms = 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))
1332
})
1433
})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.