mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 08:16:50 +08:00
fix: Enhance error handling in factorial function (#1430)
This commit is contained in:
@ -10,10 +10,20 @@ describe('Factorial', () => {
|
||||
})
|
||||
|
||||
it('Throw Error for Invalid Input', () => {
|
||||
expect(() => factorial('-')).toThrow('Not a Whole Number')
|
||||
expect(() => factorial(null)).toThrow('Not a Whole Number')
|
||||
expect(() => factorial(undefined)).toThrow('Not a Whole Number')
|
||||
expect(() => factorial(3.142)).toThrow('Not a Whole Number')
|
||||
expect(() => factorial(-1)).toThrow('Not a Positive Number')
|
||||
expect(() => factorial('-')).toThrow(
|
||||
'Input should be a non-negative whole number'
|
||||
)
|
||||
expect(() => factorial(null)).toThrow(
|
||||
'Input should be a non-negative whole number'
|
||||
)
|
||||
expect(() => factorial(undefined)).toThrow(
|
||||
'Input should be a non-negative whole number'
|
||||
)
|
||||
expect(() => factorial(3.142)).toThrow(
|
||||
'Input should be a non-negative whole number'
|
||||
)
|
||||
expect(() => factorial(-1)).toThrow(
|
||||
'Input should be a non-negative whole number'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user