forked from TheAlgorithms/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisHarshad.test.js
More file actions
31 lines (27 loc) · 870 Bytes
/
isHarshad.test.js
File metadata and controls
31 lines (27 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { isHarshad } from '../IsHarshad.js'
describe('Harshad number tests', () => {
test('Basic Harshad numbers', () => {
expect(isHarshad(18)).toBe(true)
expect(isHarshad(21)).toBe(true)
expect(isHarshad(12)).toBe(true)
expect(isHarshad(6804)).toBe(true)
expect(isHarshad('18')).toBe(true)
expect(isHarshad(2025)).toBe(true)
})
test('Non-Harshad numbers', () => {
expect(isHarshad(19)).toBe(false)
expect(isHarshad(25)).toBe(false)
expect(isHarshad(97)).toBe(false)
})
test('Edge cases', () => {
expect(isHarshad(0)).toBe(false)
expect(isHarshad(-18)).toBe(false)
expect(isHarshad(1)).toBe(true)
expect(isHarshad(10)).toBe(true)
})
test('Input validation', () => {
expect(isHarshad(18.5)).toBe(false)
expect(isHarshad(null)).toBe(false)
expect(isHarshad(undefined)).toBe(false)
})
})