|
1 | | -import { findBinomialCoefficient } from '../BinomialCoefficient.js' |
| 1 | +import { binomialCoefficient } from '../BinomialCoefficient.js' |
2 | 2 |
|
3 | | -describe('Testing findBinomialCoefficient function', () => { |
4 | | - it('should return 56', () => { |
5 | | - const binomialCoefficient = findBinomialCoefficient(8, 3) |
6 | | - expect(binomialCoefficient).toBe(56) |
| 3 | +describe('binomialCoefficient', () => { |
| 4 | + test('binomialCoefficient(5, 0) returns 1', () => { |
| 5 | + expect(binomialCoefficient(5, 0)).toBe(1) |
7 | 6 | }) |
8 | 7 |
|
9 | | - it('should return 10', () => { |
10 | | - const binomialCoefficient = findBinomialCoefficient(5, 2) |
11 | | - expect(binomialCoefficient).toBe(10) |
| 8 | + test('binomialCoefficient(5, 5) returns 1', () => { |
| 9 | + expect(binomialCoefficient(5, 5)).toBe(1) |
12 | 10 | }) |
13 | 11 |
|
14 | | - it('should throw error when supplied arguments other than number', () => { |
15 | | - expect(() => { |
16 | | - findBinomialCoefficient('eight', 'three') |
17 | | - }).toThrow(Error) |
| 12 | + test('binomialCoefficient(5, 1) returns 5', () => { |
| 13 | + expect(binomialCoefficient(5, 1)).toBe(5) |
18 | 14 | }) |
19 | 15 |
|
20 | | - it('should throw error when n is less than zero', () => { |
21 | | - expect(() => { |
22 | | - findBinomialCoefficient(-1, 3) |
23 | | - }).toThrow(Error) |
| 16 | + test('binomialCoefficient(5, 2) returns 10', () => { |
| 17 | + expect(binomialCoefficient(5, 2)).toBe(10) |
24 | 18 | }) |
25 | 19 |
|
26 | | - it('should throw error when k is less than zero', () => { |
27 | | - expect(() => { |
28 | | - findBinomialCoefficient(1, -3) |
29 | | - }).toThrow(Error) |
| 20 | + test('binomialCoefficient(10, 3) returns 120', () => { |
| 21 | + expect(binomialCoefficient(10, 3)).toBe(120) |
30 | 22 | }) |
31 | 23 |
|
32 | | - it('should throw error when n and k are less than zero', () => { |
33 | | - expect(() => { |
34 | | - findBinomialCoefficient(-1, -3) |
35 | | - }).toThrow(Error) |
| 24 | + test('binomialCoefficient(6, 3) returns 20', () => { |
| 25 | + expect(binomialCoefficient(6, 3)).toBe(20) |
| 26 | + }) |
| 27 | + |
| 28 | + test('binomialCoefficient(k > n) returns 0', () => { |
| 29 | + expect(binomialCoefficient(3, 5)).toBe(0) |
| 30 | + }) |
| 31 | + |
| 32 | + test('binomialCoefficient(0, 0) returns 1', () => { |
| 33 | + expect(binomialCoefficient(0, 0)).toBe(1) |
| 34 | + }) |
| 35 | + |
| 36 | + test('binomialCoefficient(10, 10) returns 1', () => { |
| 37 | + expect(binomialCoefficient(10, 10)).toBe(1) |
| 38 | + }) |
| 39 | + |
| 40 | + test('throws TypeError for negative n', () => { |
| 41 | + expect(() => binomialCoefficient(-5, 2)).toThrow(TypeError) |
| 42 | + }) |
| 43 | + |
| 44 | + test('throws TypeError for negative k', () => { |
| 45 | + expect(() => binomialCoefficient(5, -2)).toThrow(TypeError) |
| 46 | + }) |
| 47 | + |
| 48 | + test('throws TypeError for float input', () => { |
| 49 | + expect(() => binomialCoefficient(5.5, 2)).toThrow(TypeError) |
36 | 50 | }) |
37 | 51 | }) |
0 commit comments