Skip to content

Commit 6a28e44

Browse files
committed
Added tests for dynamic programming
1 parent 90ef219 commit 6a28e44

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_dynamic_programming.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
import unittest
3+
4+
from pygorithm.dynamic_programming import (
5+
binary_knapsack,
6+
lis
7+
)
8+
9+
10+
class TestBinaryKnapsack(unittest.TestCase):
11+
def test_binary_knapsack(self):
12+
value = [60, 100, 120]
13+
weight = [10, 20, 30]
14+
W = 50
15+
n = len(value)
16+
self.assertEqual(binary_knapsack.knapsack(W, value, weight, n), 220)
17+
18+
class TestLongestIncreasingSubsequence(unittest.TestCase):
19+
def test_lis(self):
20+
_list = [10, 22, 9, 33, 21, 50, 41, 60]
21+
ans = lis.longest_increasing_subsequence(_list)
22+
self.assertEqual(ans[0], 5)
23+
self.assertEqual(ans[1], [10, 22, 33, 50, 60])
24+
25+
if __name__ == '__main__':
26+
unittest.main()

0 commit comments

Comments
 (0)