forked from TheAlgorithms/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinomial_coefficient.test.ts
More file actions
34 lines (30 loc) · 939 Bytes
/
binomial_coefficient.test.ts
File metadata and controls
34 lines (30 loc) · 939 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
32
33
34
import { binomialCoefficient } from '../binomial_coefficient'
describe('binomialCoefficient', () => {
it('should calculate the correct binomial coefficient', () => {
// Test cases with expected results
const testCases: [number, number, number][] = [
[5, 2, 10],
[10, 3, 120],
[6, 0, 1],
[4, 4, 1],
[7, 5, 21],
[10, 10, 1]
]
// Iterate through each test case and verify the result
testCases.forEach(([n, k, expected]) => {
const result = binomialCoefficient(n, k)
expect(result).toEqual(expected)
})
})
it('should return 0 if k is larger than n or negative', () => {
const invalidCases: [number, number][] = [
[5, 6], // k is larger than n
[10, -3], // k is negative
[5, 10] // k is larger than n
]
invalidCases.forEach(([n, k]) => {
const result = binomialCoefficient(n, k)
expect(result).toEqual(0)
})
})
})