Skip to content

Commit

Permalink
merge: Add test case (TheAlgorithms#851)
Browse files Browse the repository at this point in the history
* Add test case

* minor fix

* delete files

* rename file
  • Loading branch information
Yatin-kathuria authored Nov 27, 2021
1 parent c33b19a commit 51415f8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
18 changes: 18 additions & 0 deletions Recursive/Factorial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @function Factorial
* @description function to find factorial using recursion.
* @param {Integer} n - The input integer
* @return {Integer} - Factorial of n.
* @see [Factorial](https://en.wikipedia.org/wiki/Factorial)
* @example 5! = 1*2*3*4*5 = 120
* @example 2! = 1*2 = 2
*/

const factorial = (n) => {
if (n === 0) {
return 1
}
return n * factorial(n - 1)
}

export { factorial }
11 changes: 0 additions & 11 deletions Recursive/factorial.js

This file was deleted.

11 changes: 11 additions & 0 deletions Recursive/test/Factorial.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { factorial } from '../Factorial'

describe('Factorial', () => {
it('should return factorial 1 for value "0"', () => {
expect(factorial(0)).toBe(1)
})

it('should return factorial 120 for value "5"', () => {
expect(factorial(5)).toBe(120)
})
})

0 comments on commit 51415f8

Please sign in to comment.