Skip to content

Commit a52908b

Browse files
nkstonksgithub-actionscclausspre-commit-ci[bot]
authored andcommitted
Added doctests for fibonacci.py (TheAlgorithms#10836)
* added other possible cases * added test for correct output of truth table * few fibonacci tests added * updating DIRECTORY.md * Update nor_gate.py * updating DIRECTORY.md * Update fibonacci.py removed whitespace * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: = <=> Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent a051e24 commit a52908b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: maths/fibonacci.py

+16
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ def fib_recursive(n: int) -> list[int]:
8181
def fib_recursive_term(i: int) -> int:
8282
"""
8383
Calculates the i-th (0-indexed) Fibonacci number using recursion
84+
>>> fib_recursive_term(0)
85+
0
86+
>>> fib_recursive_term(1)
87+
1
88+
>>> fib_recursive_term(5)
89+
5
90+
>>> fib_recursive_term(10)
91+
55
92+
>>> fib_recursive_term(-1)
93+
Traceback (most recent call last):
94+
...
95+
Exception: n is negative
8496
"""
8597
if i < 0:
8698
raise Exception("n is negative")
@@ -197,6 +209,10 @@ def fib_binet(n: int) -> list[int]:
197209

198210

199211
if __name__ == "__main__":
212+
import doctest
213+
214+
doctest.testmod()
215+
200216
num = 30
201217
time_func(fib_iterative, num)
202218
time_func(fib_recursive, num) # Around 3s runtime

0 commit comments

Comments
 (0)