|
| 1 | +import { getNarcissisticNumbers } from '../NarcissisticNumber.js' |
| 2 | + |
| 3 | +describe('getNarcissisticNumbers', () => { |
| 4 | + test('single digits 1-9 are all narcissistic', () => { |
| 5 | + expect(getNarcissisticNumbers(9)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]) |
| 6 | + }) |
| 7 | + |
| 8 | + test('getNarcissisticNumbers(10) returns [1..9]', () => { |
| 9 | + expect(getNarcissisticNumbers(10)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]) |
| 10 | + }) |
| 11 | + |
| 12 | + test('153 is narcissistic', () => { |
| 13 | + const result = getNarcissisticNumbers(153) |
| 14 | + expect(result).toContain(153) |
| 15 | + }) |
| 16 | + |
| 17 | + test('370 is narcissistic', () => { |
| 18 | + const result = getNarcissisticNumbers(370) |
| 19 | + expect(result).toContain(370) |
| 20 | + }) |
| 21 | + |
| 22 | + test('371 is narcissistic', () => { |
| 23 | + const result = getNarcissisticNumbers(371) |
| 24 | + expect(result).toContain(371) |
| 25 | + }) |
| 26 | + |
| 27 | + test('407 is narcissistic', () => { |
| 28 | + const result = getNarcissisticNumbers(407) |
| 29 | + expect(result).toContain(407) |
| 30 | + }) |
| 31 | + |
| 32 | + test('getNarcissisticNumbers(500) returns correct list', () => { |
| 33 | + expect(getNarcissisticNumbers(500)).toEqual([ |
| 34 | + 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407 |
| 35 | + ]) |
| 36 | + }) |
| 37 | + |
| 38 | + test('100 is NOT narcissistic', () => { |
| 39 | + const result = getNarcissisticNumbers(100) |
| 40 | + expect(result).not.toContain(100) |
| 41 | + }) |
| 42 | + |
| 43 | + test('throws TypeError for zero', () => { |
| 44 | + expect(() => getNarcissisticNumbers(0)).toThrow(TypeError) |
| 45 | + }) |
| 46 | + |
| 47 | + test('throws TypeError for negative input', () => { |
| 48 | + expect(() => getNarcissisticNumbers(-5)).toThrow(TypeError) |
| 49 | + }) |
| 50 | + |
| 51 | + test('throws TypeError for float input', () => { |
| 52 | + expect(() => getNarcissisticNumbers(9.5)).toThrow(TypeError) |
| 53 | + }) |
| 54 | +}) |
0 commit comments