Skip to content

Commit cf5ff92

Browse files
committed
Add tests for Maths/IsDivisible
1 parent 469a0e0 commit cf5ff92

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Maths/test/IsDivisible.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { isDivisible } from '../IsDivisible'
2+
3+
describe('isDivisible', () => {
4+
const testCases = [
5+
[0, 1, true],
6+
[0, 2, true],
7+
[1, 1, true],
8+
[1, 2, false],
9+
[2, 1, true],
10+
[4, 4, true],
11+
[16, 4, true],
12+
[36978235, 5, true],
13+
[36978235, 4, false],
14+
[4.5, 1.5, true],
15+
[4.5, 1.2, false],
16+
[5, 0, false],
17+
[5, -0, false]
18+
]
19+
20+
test.each(testCases)("if parameters are (%i, %i) it returns %p", (dividend, divisor, expected) => {
21+
expect(isDivisible(dividend, divisor)).toBe(expected);
22+
})
23+
24+
const errorCases = [
25+
[NaN, NaN],
26+
[NaN, 1],
27+
[1, NaN],
28+
["1", 1],
29+
[1, "1"],
30+
[1, true],
31+
[false, 2]
32+
]
33+
34+
test.each(errorCases)("throws an error if parameters are (%p, %p)", (dividend, divisor) => {
35+
expect(() => {
36+
isDivisible(dividend, divisor)
37+
}).toThrow()
38+
})
39+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy