|
| 1 | +import { getLuckyNumbers } from '../LuckyNumbers.js' |
| 2 | + |
| 3 | +describe('getLuckyNumbers', () => { |
| 4 | + test('getLuckyNumbers(1) returns [1]', () => { |
| 5 | + expect(getLuckyNumbers(1)).toEqual([1]) |
| 6 | + }) |
| 7 | + |
| 8 | + test('getLuckyNumbers(10) returns [1, 3, 7, 9]', () => { |
| 9 | + expect(getLuckyNumbers(10)).toEqual([1, 3, 7, 9]) |
| 10 | + }) |
| 11 | + |
| 12 | + test('getLuckyNumbers(20) returns correct list', () => { |
| 13 | + expect(getLuckyNumbers(20)).toEqual([1, 3, 7, 9, 13, 15]) |
| 14 | + }) |
| 15 | + |
| 16 | + test('all results are within limit', () => { |
| 17 | + const result = getLuckyNumbers(50) |
| 18 | + expect(result.every((n) => n <= 50)).toBe(true) |
| 19 | + }) |
| 20 | + |
| 21 | + test('result is sorted in ascending order', () => { |
| 22 | + const result = getLuckyNumbers(50) |
| 23 | + expect(result).toEqual([...result].sort((a, b) => a - b)) |
| 24 | + }) |
| 25 | + |
| 26 | + test('1 is always a lucky number', () => { |
| 27 | + expect(getLuckyNumbers(10)[0]).toBe(1) |
| 28 | + }) |
| 29 | + |
| 30 | + test('getLuckyNumbers(50) has correct count', () => { |
| 31 | + expect(getLuckyNumbers(50)).toHaveLength(13) |
| 32 | + }) |
| 33 | + |
| 34 | + test('throws TypeError for zero', () => { |
| 35 | + expect(() => getLuckyNumbers(0)).toThrow(TypeError) |
| 36 | + }) |
| 37 | + |
| 38 | + test('throws TypeError for negative input', () => { |
| 39 | + expect(() => getLuckyNumbers(-10)).toThrow(TypeError) |
| 40 | + }) |
| 41 | + |
| 42 | + test('throws TypeError for float input', () => { |
| 43 | + expect(() => getLuckyNumbers(10.5)).toThrow(TypeError) |
| 44 | + }) |
| 45 | +}) |
0 commit comments