- Notifications
You must be signed in to change notification settings - Fork 46.7k
/
Copy pathtest_knapsack.py
53 lines (42 loc) · 1.02 KB
/
test_knapsack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Created on Fri Oct 16 09:31:07 2020
@author: Dr. Tobias Schröder
@license: MIT-license
This file contains the test-suite for the knapsack problem.
"""
importunittest
fromknapsackimportknapsackask
classTest(unittest.TestCase):
deftest_base_case(self):
"""
test for the base case
"""
cap=0
val= [0]
w= [0]
c=len(val)
assertk.knapsack(cap, w, val, c) ==0
val= [60]
w= [10]
c=len(val)
assertk.knapsack(cap, w, val, c) ==0
deftest_easy_case(self):
"""
test for the base case
"""
cap=3
val= [1, 2, 3]
w= [3, 2, 1]
c=len(val)
assertk.knapsack(cap, w, val, c) ==5
deftest_knapsack(self):
"""
test for the knapsack
"""
cap=50
val= [60, 100, 120]
w= [10, 20, 30]
c=len(val)
assertk.knapsack(cap, w, val, c) ==220
if__name__=="__main__":
unittest.main()