mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 09:28:26 +08:00
tests: improve for GeneratePermutations (#1263)
This commit is contained in:
@ -1,14 +1,33 @@
|
|||||||
|
import { factorial } from '../../Recursive/Factorial'
|
||||||
import { permutations } from '../GeneratePermutations'
|
import { permutations } from '../GeneratePermutations'
|
||||||
|
|
||||||
describe('Permutations', () => {
|
describe('Permutations', () => {
|
||||||
|
it('Permutations of [a]', () => {
|
||||||
|
const perms = permutations(['a'])
|
||||||
|
expect(perms).toHaveLength(factorial(1))
|
||||||
|
expect(perms).toContainEqual(['a'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Permutations of [true, false]', () => {
|
||||||
|
const perms = permutations([true, false])
|
||||||
|
expect(perms).toHaveLength(factorial(2))
|
||||||
|
expect(perms).toContainEqual([true, false])
|
||||||
|
expect(perms).toContainEqual([false, true])
|
||||||
|
})
|
||||||
|
|
||||||
it('Permutations of [1, 2, 3]', () => {
|
it('Permutations of [1, 2, 3]', () => {
|
||||||
expect(permutations([1, 2, 3])).toEqual([
|
const perms = permutations([1, 2, 3])
|
||||||
[1, 2, 3],
|
expect(perms).toHaveLength(factorial(3))
|
||||||
[1, 3, 2],
|
expect(perms).toContainEqual([1, 2, 3])
|
||||||
[2, 1, 3],
|
expect(perms).toContainEqual([1, 3, 2])
|
||||||
[2, 3, 1],
|
expect(perms).toContainEqual([2, 1, 3])
|
||||||
[3, 1, 2],
|
expect(perms).toContainEqual([2, 3, 1])
|
||||||
[3, 2, 1]
|
expect(perms).toContainEqual([3, 1, 2])
|
||||||
])
|
expect(perms).toContainEqual([3, 2, 1])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Permutation counts across larger input arrays', () => {
|
||||||
|
expect(permutations([1, 2, 3, 4, 5, 6, 7, 8])).toHaveLength(factorial(8))
|
||||||
|
expect(permutations([1, 2, 3, 4, 5, 6, 7, 8, 9])).toHaveLength(factorial(9))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user