Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit66a7fd7

Browse files
committed
Merge pull requestmgechev#59 from Jakehp/master
fibonacci spec and throw on too large of input.
2 parentsd60b8b8 +2664ca5 commit66a7fd7

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

‎src/others/fibonacci.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
'use strict';
2020

2121
functionfibonacci(n){
22+
if(n>97){
23+
throw'Input too large, results in inaccurate fibonacci value.';
24+
}
2225
varn1=0;
2326
varn2=1;
2427
varaux;

‎test/others/fibonacci.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
varmod=require('../../src/others/fibonacci.js');
4+
varfibonacci=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+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp