diff --git a/index.js b/index.js index 636af8d..96ad4c6 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,7 @@ exports.fibonacci = function(n) { if(n==0 || n==1) return n; + if (n<0) + return (undefined); return this.fibonacci(n-1) + this.fibonacci(n-2); } \ No newline at end of file diff --git a/test/test.js b/test/test.js index 0160835..e9f4b05 100644 --- a/test/test.js +++ b/test/test.js @@ -6,6 +6,12 @@ describe('Regular fibonacci value', function() { }); }); +describe('negative fibonacci value', function() { + it('should return undefined for fib(-3)', function() { + assert.strictEqual(main.fibonacci(-3), undefined); + }); +}); + describe('First two terms', function() { it('should return 0 and 1 for first two terms', function() { assert.strictEqual(main.fibonacci(0), 0);