mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 23:11:09 +00:00
bc8df6de31
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.2.2 → v0.3.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.2.2...v0.3.2) - [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.9.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.8.0...v1.9.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
54 lines
1.0 KiB
Python
54 lines
1.0 KiB
Python
"""
|
|
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.
|
|
"""
|
|
|
|
import unittest
|
|
|
|
from knapsack import knapsack as k
|
|
|
|
|
|
class Test(unittest.TestCase):
|
|
def test_base_case(self):
|
|
"""
|
|
test for the base case
|
|
"""
|
|
cap = 0
|
|
val = [0]
|
|
w = [0]
|
|
c = len(val)
|
|
assert k.knapsack(cap, w, val, c) == 0
|
|
|
|
val = [60]
|
|
w = [10]
|
|
c = len(val)
|
|
assert k.knapsack(cap, w, val, c) == 0
|
|
|
|
def test_easy_case(self):
|
|
"""
|
|
test for the base case
|
|
"""
|
|
cap = 3
|
|
val = [1, 2, 3]
|
|
w = [3, 2, 1]
|
|
c = len(val)
|
|
assert k.knapsack(cap, w, val, c) == 5
|
|
|
|
def test_knapsack(self):
|
|
"""
|
|
test for the knapsack
|
|
"""
|
|
cap = 50
|
|
val = [60, 100, 120]
|
|
w = [10, 20, 30]
|
|
c = len(val)
|
|
assert k.knapsack(cap, w, val, c) == 220
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|