1
+ import { test , expect , describe } from 'bun:test' ;
2
+ import { findFactorialRecursive , findFactorialIterative } from './recursion-factorial' ;
3
+
4
+ describe ( 'Factorial Functions' , ( ) => {
5
+ // Test cases for both recursive and iterative implementations
6
+ const testCases = [
7
+ { input : 0 , expected : 1 } , // Edge case: 0! = 1
8
+ { input : 1 , expected : 1 } , // Edge case: 1! = 1
9
+ { input : 5 , expected : 120 } , // Normal case: 5! = 120
10
+ { input : 7 , expected : 7 * 6 * 5 * 4 * 3 * 2 * 1 } // Larger number
11
+ ] ;
12
+
13
+ // Test recursive implementation
14
+ test ( 'findFactorialRecursive handles various inputs' , ( ) => {
15
+ testCases . forEach ( ( { input, expected } ) => {
16
+ expect ( findFactorialRecursive ( input ) ) . toBe ( expected ) ;
17
+ } ) ;
18
+ } ) ;
19
+
20
+ // Test iterative implementation
21
+ test ( 'findFactorialIterative handles various inputs' , ( ) => {
22
+ testCases . forEach ( ( { input, expected } ) => {
23
+ expect ( findFactorialIterative ( input ) ) . toBe ( expected ) ;
24
+ } ) ;
25
+ } ) ;
26
+
27
+ // Error and edge case handling
28
+ test ( 'findFactorialRecursive handles negative numbers' , ( ) => {
29
+ expect ( findFactorialRecursive ( - 1 ) ) . toBeUndefined ( ) ;
30
+ } ) ;
31
+
32
+ test ( 'findFactorialIterative handles negative numbers' , ( ) => {
33
+ expect ( findFactorialIterative ( - 1 ) ) . toBeUndefined ;
34
+ } ) ;
35
+
36
+ } ) ;
0 commit comments