mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Added doctests for fibonacci.py (#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 <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
7c1dfec086
commit
6b588e4d44
|
@ -81,6 +81,18 @@ def fib_recursive(n: int) -> list[int]:
|
|||
def fib_recursive_term(i: int) -> int:
|
||||
"""
|
||||
Calculates the i-th (0-indexed) Fibonacci number using recursion
|
||||
>>> fib_recursive_term(0)
|
||||
0
|
||||
>>> fib_recursive_term(1)
|
||||
1
|
||||
>>> fib_recursive_term(5)
|
||||
5
|
||||
>>> fib_recursive_term(10)
|
||||
55
|
||||
>>> fib_recursive_term(-1)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
Exception: n is negative
|
||||
"""
|
||||
if i < 0:
|
||||
raise Exception("n is negative")
|
||||
|
@ -197,6 +209,10 @@ def fib_binet(n: int) -> list[int]:
|
|||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
|
||||
doctest.testmod()
|
||||
|
||||
num = 30
|
||||
time_func(fib_iterative, num)
|
||||
time_func(fib_recursive, num) # Around 3s runtime
|
||||
|
|
Loading…
Reference in New Issue
Block a user