mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 16:26:47 +08:00
merge: Add test cases (#854)
This commit is contained in:
@ -1,15 +1,17 @@
|
||||
|
||||
// https://en.wikipedia.org/wiki/Fibonacci_number
|
||||
|
||||
/**
|
||||
* Return the N-th Fibonacci number
|
||||
*
|
||||
* @param {number} N
|
||||
* @returns {number}
|
||||
* @function Fibonacci
|
||||
* @description Function to return the N-th Fibonacci number.
|
||||
* @param {Integer} n - The input integer
|
||||
* @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) {
|
||||
return N
|
||||
|
||||
const fibonacci = (n) => {
|
||||
if (n < 2) {
|
||||
return n
|
||||
}
|
||||
return fibonacci(N - 2) + fibonacci(N - 1)
|
||||
return fibonacci(n - 2) + fibonacci(n - 1)
|
||||
}
|
||||
|
||||
export { fibonacci }
|
||||
|
19
Recursive/test/FibonacciNumberRecursive.test.js
Normal file
19
Recursive/test/FibonacciNumberRecursive.test.js
Normal 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)
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user