Add factorial.

This commit is contained in:
Oleksii Trekhleb 2018-04-18 13:07:50 +03:00
parent a10009df64
commit 3e5e78d291

View File

@ -1,4 +1,5 @@
import permutateWithoutRepetitions from '../permutateWithoutRepetitions'; import permutateWithoutRepetitions from '../permutateWithoutRepetitions';
import factorial from '../../../math/factorial/factorial';
describe('permutateString', () => { describe('permutateString', () => {
it('should permutate string', () => { it('should permutate string', () => {
@ -23,7 +24,7 @@ describe('permutateString', () => {
]); ]);
const permutations3 = permutateWithoutRepetitions('ABC'); const permutations3 = permutateWithoutRepetitions('ABC');
expect(permutations3.length).toBe(2 * 3); expect(permutations3.length).toBe(factorial(3));
expect(permutations3).toEqual([ expect(permutations3).toEqual([
'CBA', 'CBA',
'BCA', 'BCA',
@ -34,7 +35,7 @@ describe('permutateString', () => {
]); ]);
const permutations4 = permutateWithoutRepetitions('ABCD'); const permutations4 = permutateWithoutRepetitions('ABCD');
expect(permutations4.length).toBe(2 * 3 * 4); expect(permutations4.length).toBe(factorial(4));
expect(permutations4).toEqual([ expect(permutations4).toEqual([
'DCBA', 'DCBA',
'CDBA', 'CDBA',
@ -63,6 +64,6 @@ describe('permutateString', () => {
]); ]);
const permutations5 = permutateWithoutRepetitions('ABCDEF'); const permutations5 = permutateWithoutRepetitions('ABCDEF');
expect(permutations5.length).toBe(2 * 3 * 4 * 5 * 6); expect(permutations5.length).toBe(factorial(6));
}); });
}); });