mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Adding missing Doctests (#1330)
* Adding doctests in abbreviation * Adding doctests in fibonacci.py
This commit is contained in:
parent
b6cc37d461
commit
ea47ae2932
@ -11,8 +11,13 @@ a=daBcd and b="ABC"
|
|||||||
daBcd -> capitalize a and c(dABCd) -> remove d (ABC)
|
daBcd -> capitalize a and c(dABCd) -> remove d (ABC)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def abbr(a, b):
|
def abbr(a, b):
|
||||||
|
"""
|
||||||
|
>>> abbr("daBcd", "ABC")
|
||||||
|
True
|
||||||
|
>>> abbr("dBcd", "ABC")
|
||||||
|
False
|
||||||
|
"""
|
||||||
n = len(a)
|
n = len(a)
|
||||||
m = len(b)
|
m = len(b)
|
||||||
dp = [[False for _ in range(m + 1)] for _ in range(n + 1)]
|
dp = [[False for _ in range(m + 1)] for _ in range(n + 1)]
|
||||||
@ -28,4 +33,7 @@ def abbr(a, b):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print(abbr("daBcd", "ABC")) # expect True
|
# print(abbr("daBcd", "ABC")) # expect True
|
||||||
|
import doctest
|
||||||
|
|
||||||
|
doctest.testmod()
|
||||||
|
@ -14,8 +14,20 @@ class Fibonacci:
|
|||||||
self.fib_array.append(self.fib_array[i - 1] + self.fib_array[i - 2])
|
self.fib_array.append(self.fib_array[i - 1] + self.fib_array[i - 2])
|
||||||
elif N == 0:
|
elif N == 0:
|
||||||
self.fib_array.append(0)
|
self.fib_array.append(0)
|
||||||
|
print(self.fib_array)
|
||||||
|
|
||||||
def get(self, sequence_no=None):
|
def get(self, sequence_no=None):
|
||||||
|
"""
|
||||||
|
>>> Fibonacci(5).get(3)
|
||||||
|
[0, 1, 1, 2, 3, 5]
|
||||||
|
[0, 1, 1, 2]
|
||||||
|
>>> Fibonacci(5).get(6)
|
||||||
|
[0, 1, 1, 2, 3, 5]
|
||||||
|
Out of bound.
|
||||||
|
>>> Fibonacci(5).get(-1)
|
||||||
|
[0, 1, 1, 2, 3, 5]
|
||||||
|
[]
|
||||||
|
"""
|
||||||
if sequence_no != None:
|
if sequence_no != None:
|
||||||
if sequence_no < len(self.fib_array):
|
if sequence_no < len(self.fib_array):
|
||||||
return print(self.fib_array[: sequence_no + 1])
|
return print(self.fib_array[: sequence_no + 1])
|
||||||
@ -46,3 +58,7 @@ if __name__ == "__main__":
|
|||||||
print("\nInvalid input, please try again.")
|
print("\nInvalid input, please try again.")
|
||||||
except NameError:
|
except NameError:
|
||||||
print("\n********* Invalid input, good bye!! ************\n")
|
print("\n********* Invalid input, good bye!! ************\n")
|
||||||
|
|
||||||
|
import doctest
|
||||||
|
|
||||||
|
doctest.testmod()
|
||||||
|
Loading…
Reference in New Issue
Block a user