|
| 1 | +import { isHarshadNumber } from '../HarshadNumber.js' |
| 2 | + |
| 3 | +describe('isHarshadNumber', () => { |
| 4 | + test('1 is a Harshad number', () => { |
| 5 | + expect(isHarshadNumber(1)).toBe(true) |
| 6 | + }) |
| 7 | + |
| 8 | + test('18 is a Harshad number (1+8=9, 18/9=2)', () => { |
| 9 | + expect(isHarshadNumber(18)).toBe(true) |
| 10 | + }) |
| 11 | + |
| 12 | + test('21 is a Harshad number (2+1=3, 21/3=7)', () => { |
| 13 | + expect(isHarshadNumber(21)).toBe(true) |
| 14 | + }) |
| 15 | + |
| 16 | + test('12 is a Harshad number (1+2=3, 12/3=4)', () => { |
| 17 | + expect(isHarshadNumber(12)).toBe(true) |
| 18 | + }) |
| 19 | + |
| 20 | + test('100 is a Harshad number (1+0+0=1, 100/1=100)', () => { |
| 21 | + expect(isHarshadNumber(100)).toBe(true) |
| 22 | + }) |
| 23 | + |
| 24 | + test('111 is a Harshad number (1+1+1=3, 111/3=37)', () => { |
| 25 | + expect(isHarshadNumber(111)).toBe(true) |
| 26 | + }) |
| 27 | + |
| 28 | + test('19 is NOT a Harshad number (1+9=10, 19/10 is not integer)', () => { |
| 29 | + expect(isHarshadNumber(19)).toBe(false) |
| 30 | + }) |
| 31 | + |
| 32 | + test('11 is NOT a Harshad number', () => { |
| 33 | + expect(isHarshadNumber(11)).toBe(false) |
| 34 | + }) |
| 35 | + |
| 36 | + test('23 is NOT a Harshad number', () => { |
| 37 | + expect(isHarshadNumber(23)).toBe(false) |
| 38 | + }) |
| 39 | + |
| 40 | + test('throws TypeError for zero', () => { |
| 41 | + expect(() => isHarshadNumber(0)).toThrow(TypeError) |
| 42 | + }) |
| 43 | + |
| 44 | + test('throws TypeError for negative input', () => { |
| 45 | + expect(() => isHarshadNumber(-18)).toThrow(TypeError) |
| 46 | + }) |
| 47 | + |
| 48 | + test('throws TypeError for float input', () => { |
| 49 | + expect(() => isHarshadNumber(18.5)).toThrow(TypeError) |
| 50 | + }) |
| 51 | +}) |
0 commit comments