mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-04 15:39:42 +08:00
merge: Add FibonacciNumber.js test case and update the decription of function. (#840)
This commit is contained in:
@ -1,5 +1,10 @@
|
||||
// https://en.wikipedia.org/wiki/Fibonacci_number
|
||||
|
||||
/**
|
||||
* @function Fibonacci
|
||||
* @description Fibonacci is the sum of previous two fibonacci numbers.
|
||||
* @param {Integer} N - The input integer
|
||||
* @return {Integer} fibonacci of N.
|
||||
* @see [Fibonacci_Numbers](https://en.wikipedia.org/wiki/Fibonacci_number)
|
||||
*/
|
||||
const fibonacci = (N) => {
|
||||
// creating array to store values
|
||||
const memo = new Array(N + 1)
|
||||
|
19
Dynamic-Programming/tests/FibonacciNumber.test.js
Normal file
19
Dynamic-Programming/tests/FibonacciNumber.test.js
Normal file
@ -0,0 +1,19 @@
|
||||
import { fibonacci } from '../FibonacciNumber'
|
||||
|
||||
describe('FibonacciNumber', () => {
|
||||
it('fibonacci of 0', () => {
|
||||
expect(fibonacci(0)).toBe(0)
|
||||
})
|
||||
|
||||
it('fibonacci of 1', () => {
|
||||
expect(fibonacci(1)).toBe(1)
|
||||
})
|
||||
|
||||
it('fibonacci of 10', () => {
|
||||
expect(fibonacci(10)).toBe(55)
|
||||
})
|
||||
|
||||
it('fibonacci of 25', () => {
|
||||
expect(fibonacci(25)).toBe(75025)
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user