Open
Show file tree
Hide file tree
Changes from all commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,9 +2,11 @@
## Backtracking
* [All Combinations Of Size K](https://.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/all_combinations_of_size_k.ts)
* [Generateparentheses](https://.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/generateparentheses.ts)
* [Generatepermutations](https://.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/generatepermutations.ts)
* Test
* [All Combinations Of Size K.Test](https://.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/test/all_combinations_of_size_k.test.ts)
* [Generateparentheses.Test](https://.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/test/generateparentheses.test.ts)
* [Generatepermutations.Test](https://.com/TheAlgorithms/TypeScript/blob/HEAD/backtracking/test/generatepermutations.test.ts)

## Bit Manipulation
* [Add Binary](https://.com/TheAlgorithms/TypeScript/blob/HEAD/bit_manipulation/add_binary.ts)
Expand DownExpand Up@@ -156,6 +158,8 @@

## Search
* [Binary Search](https://.com/TheAlgorithms/TypeScript/blob/HEAD/search/binary_search.ts)
* [Exponential Search](https://.com/TheAlgorithms/TypeScript/blob/HEAD/search/exponential_search.ts)
* [Fibonacci Search](https://.com/TheAlgorithms/TypeScript/blob/HEAD/search/fibonacci_search.ts)
* [Interpolation Search](https://.com/TheAlgorithms/TypeScript/blob/HEAD/search/interpolation_search.ts)
* [Jump Search](https://.com/TheAlgorithms/TypeScript/blob/HEAD/search/jump_search.ts)
* [Linear Search](https://.com/TheAlgorithms/TypeScript/blob/HEAD/search/linear_search.ts)
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
import { permutations } from '../generatepermutations'

const factorial = (n: number): number => {
if (n === 0 || n === 1) {
return 1
}
return n * factorial(n - 1)
}

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]', () => {
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))
})
})
Loading