def fib(n):
'''
Before the tests
>>> fib(3)
2
>>> fib(10)
55
>>> [fib(n) for n in range(11)]
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
>>> fib(11)
89
After the tests
'''
values = [0, 1]
if n == 11:
return 'bug'
while( n > len(values) -1 ):
values.append(values[-1] + values[-2])
return values[n]
#if __name__ == "__main__":
# import doctest
# doctest.testmod()
python -m doctest fibonacci_doctest.py
python examples/modules/fibonacci_doctest.py
**********************************************************************
File ".../examples/modules/fibonacci_doctest.py", line 12, in __main__.fib
Failed example:
fib(11)
Expected:
89
Got:
'bug'
**********************************************************************
1 items had failures:
1 of 4 in __main__.fib
***Test Failed*** 1 failures.
doctest