|
1 | | -import { numberOfDigit, numberOfDigitsUsingLog } from '../NumberOfDigits' |
| 1 | +import { numberOfDigits } from '../NumberOfDigits.js' |
2 | 2 |
|
3 | | -describe('NumberOfDigits', () => { |
4 | | - it('should return the correct number of digits for an integer', () => { |
5 | | - expect(numberOfDigit(1234000)).toBe(7) |
| 3 | +describe('numberOfDigits', () => { |
| 4 | + test('numberOfDigits(0) returns 1', () => { |
| 5 | + expect(numberOfDigits(0)).toBe(1) |
6 | 6 | }) |
7 | 7 |
|
8 | | - it('should return the correct number of digits for a negative number', () => { |
9 | | - expect(numberOfDigit(-2346243)).toBe(7) |
| 8 | + test('numberOfDigits(1) returns 1', () => { |
| 9 | + expect(numberOfDigits(1)).toBe(1) |
10 | 10 | }) |
11 | 11 |
|
12 | | - it.each([ |
13 | | - [0, 1], |
14 | | - [123423232, 9], |
15 | | - [-123423232, 9], |
16 | | - [9999, 4] |
17 | | - ])( |
18 | | - 'should return the correct number of digits in an integer', |
19 | | - (value, expected) => { |
20 | | - expect(numberOfDigitsUsingLog(value)).toBe(expected) |
21 | | - } |
22 | | - ) |
| 12 | + test('numberOfDigits(123) returns 3', () => { |
| 13 | + expect(numberOfDigits(123)).toBe(3) |
| 14 | + }) |
| 15 | + |
| 16 | + test('numberOfDigits(9999) returns 4', () => { |
| 17 | + expect(numberOfDigits(9999)).toBe(4) |
| 18 | + }) |
| 19 | + |
| 20 | + test('numberOfDigits(-9999) returns 4', () => { |
| 21 | + expect(numberOfDigits(-9999)).toBe(4) |
| 22 | + }) |
| 23 | + |
| 24 | + test('numberOfDigits(1000000) returns 7', () => { |
| 25 | + expect(numberOfDigits(1000000)).toBe(7) |
| 26 | + }) |
| 27 | + |
| 28 | + test('numberOfDigits(-1) returns 1', () => { |
| 29 | + expect(numberOfDigits(-1)).toBe(1) |
| 30 | + }) |
| 31 | + |
| 32 | + test('throws TypeError for float input', () => { |
| 33 | + expect(() => numberOfDigits(1.5)).toThrow(TypeError) |
| 34 | + }) |
| 35 | + |
| 36 | + test('throws TypeError for string input', () => { |
| 37 | + expect(() => numberOfDigits('123')).toThrow(TypeError) |
| 38 | + }) |
| 39 | + |
| 40 | + test('throws TypeError for NaN', () => { |
| 41 | + expect(() => numberOfDigits(NaN)).toThrow(TypeError) |
| 42 | + }) |
23 | 43 | }) |
0 commit comments