File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1919 'use strict' ;
2020
2121 function fibonacci ( n ) {
22+ if ( n > 97 ) {
23+ throw 'Input too large, results in inaccurate fibonacci value.' ;
24+ }
2225 var n1 = 0 ;
2326 var n2 = 1 ;
2427 var aux ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var mod = require ( '../../src/others/fibonacci.js' ) ;
4+ var fibonacci = mod . fibonacci ;
5+
6+ describe ( 'fibonacci algorithm' , function ( ) {
7+ it ( 'should return value 1 with input 1.' , function ( ) {
8+ expect ( fibonacci ( 1 ) ) . toBe ( 1 ) ;
9+ } ) ;
10+ it ( 'should return value 1 with input 2.' , function ( ) {
11+ expect ( fibonacci ( 2 ) ) . toBe ( 1 ) ;
12+ } ) ;
13+ it ( 'should return value 2 with input 3.' , function ( ) {
14+ expect ( fibonacci ( 3 ) ) . toBe ( 2 ) ;
15+ } ) ;
16+ it ( 'should return value 3 with input 4.' , function ( ) {
17+ expect ( fibonacci ( 4 ) ) . toBe ( 3 ) ;
18+ } ) ;
19+ it ( 'should return value 5 with input 5.' , function ( ) {
20+ expect ( fibonacci ( 5 ) ) . toBe ( 5 ) ;
21+ } ) ;
22+ it ( 'should be 83621143489848422977 with input 97.' , function ( ) {
23+ expect ( fibonacci ( 97 ) ) . toBe ( 83621143489848422977 ) ;
24+ } ) ;
25+ it ( 'should throw when input is too large.' , function ( ) {
26+ expect ( function ( ) { fibonacci ( 98 ) } ) . toThrow ( 'Input too large, results in inaccurate fibonacci value.' ) ;
27+ } ) ;
28+ } ) ;
You can’t perform that action at this time.
0 commit comments