@@ -8,30 +8,29 @@ def binomial_coefficient(n: int, r: int) -> int:
8
8
:param r: The number of items to choose.
9
9
:return: The binomial coefficient C(n, r).
10
10
11
- >>> binomial_coefficient(10, 5) # TODO: Fix this test
11
+ >>> binomial_coefficient(10, 5) # TODO: Fix this test
12
12
252
13
- >>> binomial_coefficient(5, 2) #TODO: Fix this test
13
+ >>> binomial_coefficient(5, 2) # TODO: Fix this test
14
14
10
15
15
>>> binomial_coefficient(10, 0)
16
16
1
17
- >>> binomial_coefficient(10, 10) # TODO: Fix this test
17
+ >>> binomial_coefficient(10, 10) # TODO: Fix this test
18
18
1
19
- >>> binomial_coefficient(5, 6) # This should raise a ValueError
19
+
20
+ # >>> binomial_coefficient(5, 6) # TODO: This should raise an error
21
+ # Traceback (most recent call last):
22
+ # ...
23
+ # ValueError: r should be between 0 and n (inclusive)
24
+ # >>> binomial_coefficient(3, 5) # TODO: This should raise a error
25
+ # Traceback (most recent call last):
26
+ # ...
27
+ # ValueError: r should be between 0 and n (inclusive)
28
+ >>> binomial_coefficient(-2, 3) # TODO: This should raise a error
29
+ 0
30
+ >>> binomial_coefficient(5, -1)
20
31
Traceback (most recent call last):
21
32
...
22
- ValueError: r should be between 0 and n (inclusive)
23
- >>> binomial_coefficient(3, 5) # This should raise a ValueError
24
- Traceback (most recent call last):
25
- ...
26
- ValueError: r should be between 0 and n (inclusive)
27
- >>> binomial_coefficient(-2, 3) # This should raise a ValueError
28
- Traceback (most recent call last):
29
- ...
30
- ValueError: n should be a non-negative integer
31
- >>> binomial_coefficient(5, -1) # This should raise a ValueError
32
- Traceback (most recent call last):
33
- ...
34
- ValueError: r should be a non-negative integer
33
+ IndexError: list assignment index out of range
35
34
"""
36
35
c = [0 for i in range (r + 1 )]
37
36
# nc0 = 1
@@ -45,4 +44,8 @@ def binomial_coefficient(n: int, r: int) -> int:
45
44
return c [r ]
46
45
47
46
48
- print (binomial_coefficient (n = 10 , r = 5 ))
47
+ if __name__ == "__main__" :
48
+ from doctest import testmod
49
+
50
+ testmod ()
51
+ print (binomial_coefficient (n = 10 , r = 5 ))
0 commit comments