Skip to content

tests: improve for GeneratePermutations #1263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Nov 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions Backtracking/tests/GeneratePermutations.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
import { factorial } from '../../Recursive/Factorial'
import { permutations } from '../GeneratePermutations'

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]', () => {
expect(permutations([1, 2, 3])).toEqual([
[1, 2, 3],
[1, 3, 2],
[2, 1, 3],
[2, 3, 1],
[3, 1, 2],
[3, 2, 1]
])
const perms = permutations([1, 2, 3])
expect(perms).toHaveLength(factorial(3))
expect(perms).toContainEqual([1, 2, 3])
expect(perms).toContainEqual([1, 3, 2])
expect(perms).toContainEqual([2, 1, 3])
expect(perms).toContainEqual([2, 3, 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))
})
})