merge: Add test cases (#854)

This commit is contained in:
YATIN KATHURIA
2021-11-28 11:49:11 +05:30
committed by GitHub
parent cc34088aae
commit 027c0d6307
2 changed files with 31 additions and 10 deletions

View File

@ -1,15 +1,17 @@
// https://en.wikipedia.org/wiki/Fibonacci_number
/** /**
* Return the N-th Fibonacci number * @function Fibonacci
* * @description Function to return the N-th Fibonacci number.
* @param {number} N * @param {Integer} n - The input integer
* @returns {number} * @return {Integer} - Return the N-th Fibonacci number
* @see [Fibonacci](https://en.wikipedia.org/wiki/Fibonacci_number)
*/ */
export const fibonacci = (N) => {
if (N === 0 || N === 1) { const fibonacci = (n) => {
return N if (n < 2) {
return n
} }
return fibonacci(N - 2) + fibonacci(N - 1) return fibonacci(n - 2) + fibonacci(n - 1)
} }
export { fibonacci }

View File

@ -0,0 +1,19 @@
import { fibonacci } from '../FibonacciNumberRecursive'
describe('FibonacciNumberRecursive', () => {
it('should return 0', () => {
expect(fibonacci(0)).toBe(0)
})
it('should return 1', () => {
expect(fibonacci(1)).toBe(1)
})
it('should return 5', () => {
expect(fibonacci(5)).toBe(5)
})
it('should return 9', () => {
expect(fibonacci(9)).toBe(34)
})
})