Skip to content

Commit 9bb736a

Browse files
authored
tests: checks factorial code (#304)
1 parent c668fa2 commit 9bb736a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lesson_07/conditionals/src/lesson7.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
binarySearch,
33
compareStrings,
4+
computeFactorial,
45
getFirstNFibonacciNumbers,
56
} from "./lesson7.js";
67

@@ -42,4 +43,20 @@ describe("Lesson7 Tests", () => {
4243
// Test for value not present in the array
4344
expect(binarySearch(values, 0, values.length - 1, 4)).toBe(-1);
4445
});
46+
test("testComputeFactorial", () => {
47+
// Test for n = 0 (edge case)
48+
expect(computeFactorial(0)).toBe(1);
49+
50+
// Test for n = 1
51+
expect(computeFactorial(1)).toBe(1);
52+
53+
// Test for n = 5
54+
expect(computeFactorial(5)).toBe(120);
55+
56+
// Test for n = 10
57+
expect(computeFactorial(10)).toBe(3628800);
58+
59+
// Test for negative n (edge case)
60+
expect(computeFactorial(-5)).toBe(0);
61+
});
4562
});

0 commit comments

Comments
 (0)