|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { digitPermutation } from './solution'; |
| 3 | + |
| 4 | +describe('Digit Permutation | Interview | Testcases', () => { |
| 5 | + it('#1 Should return true for numbers with same nonzero digits in same count (ignoring zeros)', () => { |
| 6 | + expect(digitPermutation(10023, 321)).toBe(true); |
| 7 | + expect(digitPermutation(1000, 1)).toBe(true); |
| 8 | + expect(digitPermutation(123, 123)).toBe(true); |
| 9 | + expect(digitPermutation(122, 212)).toBe(true); |
| 10 | + expect(digitPermutation(122, 221)).toBe(true); |
| 11 | + expect(digitPermutation(1001, 11)).toBe(true); |
| 12 | + expect(digitPermutation(1010, 11)).toBe(true); |
| 13 | + }); |
| 14 | + |
| 15 | + it('#2 Should return false when nonzero digit counts differ', () => { |
| 16 | + expect(digitPermutation(112, 12)).toBe(false); |
| 17 | + expect(digitPermutation(123, 124)).toBe(false); |
| 18 | + expect(digitPermutation(122, 22)).toBe(false); |
| 19 | + expect(digitPermutation(1234, 4321)).toBe(true); |
| 20 | + expect(digitPermutation(1234, 43210)).toBe(true); |
| 21 | + expect(digitPermutation(1234, 4322)).toBe(false); |
| 22 | + }); |
| 23 | + |
| 24 | + it('#3 Should handle numbers with only zeros and a single nonzero digit', () => { |
| 25 | + expect(digitPermutation(1000, 1)).toBe(true); |
| 26 | + expect(digitPermutation(10000, 1)).toBe(true); |
| 27 | + expect(digitPermutation(1, 1000)).toBe(true); |
| 28 | + }); |
| 29 | + |
| 30 | + it('#4 Should treat numbers with no nonzero digits as equal', () => { |
| 31 | + expect(digitPermutation(0, 0)).toBe(true); |
| 32 | + expect(digitPermutation(0, 10)).toBe(false); |
| 33 | + }); |
| 34 | + |
| 35 | + it('#5 Should work for large numbers', () => { |
| 36 | + expect(digitPermutation(123456789, 987654321)).toBe(true); |
| 37 | + expect(digitPermutation(123456789, 9876543210)).toBe(true); |
| 38 | + expect(digitPermutation(123456789, 9876543211)).toBe(false); |
| 39 | + }); |
| 40 | +}); |
0 commit comments