forked from TheAlgorithms/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactorial.test.js
More file actions
31 lines (26 loc) · 997 Bytes
/
Factorial.test.js
File metadata and controls
31 lines (26 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { calcFactorial } from '../Factorial'
describe('calcFactorial', () => {
it('should return a statement for value "0"', () => {
expect(calcFactorial(0)).toBe('The factorial of 0 is 1.')
})
it('should return a statement for "null" and "undefined"', () => {
const nullFactorial = calcFactorial(null)
const undefinedFactorial = calcFactorial(undefined)
expect(nullFactorial).toBe(
'Sorry, factorial does not exist for null or undefined numbers.'
)
expect(undefinedFactorial).toBe(
'Sorry, factorial does not exist for null or undefined numbers.'
)
})
it('should not support negative numbers', () => {
const negativeFactorial = calcFactorial(-5)
expect(negativeFactorial).toBe(
'Sorry, factorial does not exist for negative numbers.'
)
})
it('should return the factorial of a positive number', () => {
const positiveFactorial = calcFactorial(3)
expect(positiveFactorial).toBe('The factorial of 3 is 6')
})
})