Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Adding missing Doctests #1330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions dynamic_programming/abbreviation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
daBcd -> capitalize a and c(dABCd) -> remove d (ABC)
"""


def abbr(a, b):
"""
>>> abbr("daBcd", "ABC")
True
>>> abbr("dBcd", "ABC")
False
"""
n = len(a)
m = len(b)
dp = [[False for _ in range(m + 1)] for _ in range(n + 1)]
Expand All @@ -28,4 +33,7 @@ def abbr(a, b):


if __name__ == "__main__":
print(abbr("daBcd", "ABC")) # expect True
# print(abbr("daBcd", "ABC")) # expect True
import doctest

doctest.testmod()
16 changes: 16 additions & 0 deletions dynamic_programming/fibonacci.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,20 @@ def __init__(self, N=None):
self.fib_array.append(self.fib_array[i - 1] + self.fib_array[i - 2])
elif N == 0:
self.fib_array.append(0)
print(self.fib_array)

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 < len(self.fib_array):
return print(self.fib_array[: sequence_no + 1])
Expand Down Expand Up @@ -46,3 +58,7 @@ def get(self, sequence_no=None):
print("\nInvalid input, please try again.")
except NameError:
print("\n********* Invalid input, good bye!! ************\n")

import doctest

doctest.testmod()