Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit71d3d44

Browse files
authored
tests: improve for GeneratePermutations (#1263)
1 parent9d4adbb commit71d3d44

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed
Lines 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+
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+
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+
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))
1332
})
1433
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp