|
| 1 | +import { describe, it, expect } from 'vitest' |
| 2 | +import { findNthLexicographicPermutation } from '../Problem024' |
| 3 | + |
| 4 | +describe('findNthLexicographicPermutation', () => { |
| 5 | + it('should return the correct permutation for small cases', () => { |
| 6 | + expect(findNthLexicographicPermutation([0, 1, 2], 1)).toBe('012') |
| 7 | + expect(findNthLexicographicPermutation([0, 1, 2], 2)).toBe('021') |
| 8 | + expect(findNthLexicographicPermutation([0, 1, 2], 6)).toBe('210') |
| 9 | + }) |
| 10 | + |
| 11 | + it('should return the correct 1st permutation for digits 0-9', () => { |
| 12 | + expect( |
| 13 | + findNthLexicographicPermutation([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1) |
| 14 | + ).toBe('0123456789') |
| 15 | + }) |
| 16 | + |
| 17 | + it('should return the correct millionth permutation for digits 0-9', () => { |
| 18 | + expect( |
| 19 | + findNthLexicographicPermutation([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 1000000) |
| 20 | + ).toBe('2783915460') |
| 21 | + }) |
| 22 | + |
| 23 | + it('should return the correct permutation for a smaller set of digits', () => { |
| 24 | + expect(findNthLexicographicPermutation([1, 2, 3, 4], 12)).toBe('2431') |
| 25 | + expect(findNthLexicographicPermutation([1, 2, 3, 4], 24)).toBe('4321') |
| 26 | + }) |
| 27 | + |
| 28 | + it('should handle large values of n', () => { |
| 29 | + expect(findNthLexicographicPermutation([0, 1, 2, 3, 4], 120)).toBe('43210') |
| 30 | + }) |
| 31 | +}) |
0 commit comments