File tree Expand file tree Collapse file tree 1 file changed +14
-20
lines changed
Dynamic-Programming/tests Expand file tree Collapse file tree 1 file changed +14
-20
lines changed Original file line number Diff line number Diff line change 11import { fastFibonacci } from '../FastFibonacciNumber'
22
33describe ( '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} )
You can’t perform that action at this time.
0 commit comments