Skip to content

Commit c12e903

Browse files
author
houcem
committed
update: optimize tests
1 parent ca78551 commit c12e903

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed
Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
import { fastFibonacci } from '../FastFibonacciNumber'
22

33
describe('Testing FibonacciNumber', () => {
4-
it('Testing for invalid type', () => {
5-
expect(() => fastFibonacci('0')).toThrowError()
6-
expect(() => fastFibonacci('12')).toThrowError()
7-
expect(() => fastFibonacci(true)).toThrowError()
8-
})
9-
10-
it('fast fibonacci of 0', () => {
11-
expect(fastFibonacci(0)).toBe(0)
12-
})
4+
const errorCases = ['0', '12', true]
135

14-
it('fast fibonacci of 1', () => {
15-
expect(fastFibonacci(1)).toBe(1)
6+
test.each(errorCases)('throws an error if %p is invalid', (input) => {
7+
expect(() => {
8+
fastFibonacci(input)
9+
}).toThrow()
1610
})
1711

18-
it('fast fibonacci of 10', () => {
19-
expect(fastFibonacci(10)).toBe(55)
20-
})
21-
22-
it('fast fibonacci of 25', () => {
23-
expect(fastFibonacci(25)).toBe(75025)
24-
})
12+
const testCases = [
13+
[0, 0],
14+
[1, 1],
15+
[10, 55],
16+
[25, 75025],
17+
[40, 102334155]
18+
]
2519

26-
it('fast fibonacci of 40', () => {
27-
expect(fastFibonacci(40)).toBe(102334155)
20+
test.each(testCases)('if input is %i it returns %i', (input, expected) => {
21+
expect(fastFibonacci(input)).toBe(expected)
2822
})
2923
})

0 commit comments

Comments
 (0)