Skip to content

Commit e678879

Browse files
jpg-130poyea
authored andcommitted
Adding doctests for sum_of_subset.py (TheAlgorithms#1333)
1 parent ea47ae2 commit e678879

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

dynamic_programming/sum_of_subset.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
def isSumSubset(arr, arrLen, requiredSum):
2-
2+
"""
3+
>>> isSumSubset([2, 4, 6, 8], 4, 5)
4+
False
5+
>>> isSumSubset([2, 4, 6, 8], 4, 14)
6+
True
7+
"""
38
# a subset value says 1 if that subset sum can be formed else 0
49
# initially no subsets can be formed hence False/0
510
subset = [[False for i in range(requiredSum + 1)] for i in range(arrLen + 1)]
@@ -22,14 +27,9 @@ def isSumSubset(arr, arrLen, requiredSum):
2227
# uncomment to print the subset
2328
# for i in range(arrLen+1):
2429
# print(subset[i])
30+
print(subset[arrLen][requiredSum])
2531

26-
return subset[arrLen][requiredSum]
27-
32+
if __name__ == "__main__":
33+
import doctest
2834

29-
arr = [2, 4, 6, 8]
30-
requiredSum = 5
31-
arrLen = len(arr)
32-
if isSumSubset(arr, arrLen, requiredSum):
33-
print("Found a subset with required sum")
34-
else:
35-
print("No subset with required sum")
35+
doctest.testmod()

0 commit comments

Comments
 (0)