Skip to content

Commit edfe247

Browse files
committed
test: strengthen factor calculation coverage
1 parent add6e56 commit edfe247

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

Maths/test/Factors.test.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { factorsOfANumber } from '../Factors'
22

33
describe('Factors', () => {
4-
factorsOfANumber(50).forEach((num) => {
5-
it(`${num} is a factor of 50`, () => {
6-
const isFactor = 50 % num === 0
7-
expect(isFactor).toBeTruthy()
8-
})
4+
it.each([
5+
[1, [1]],
6+
[16, [1, 2, 4, 8, 16]],
7+
[50, [1, 2, 5, 10, 25, 50]],
8+
[97, [1, 97]]
9+
])('returns every factor of %i in ascending order', (number, expected) => {
10+
expect(factorsOfANumber(number)).toEqual(expected)
911
})
12+
13+
it.each([0, -1, 1.5])(
14+
'returns an empty array for invalid input %s',
15+
(number) => {
16+
expect(factorsOfANumber(number)).toEqual([])
17+
}
18+
)
1019
})

0 commit comments

Comments
 (0)