|
1 | 1 | import { fastFibonacci } from '../FastFibonacciNumber' |
2 | 2 |
|
3 | 3 | 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] |
13 | 5 |
|
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() |
16 | 10 | }) |
17 | 11 |
|
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 | + ] |
25 | 19 |
|
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) |
28 | 22 | }) |
29 | 23 | }) |
0 commit comments