Skip to content

Commit

Permalink
fix integer check (#48)
Browse files Browse the repository at this point in the history
* fix integer check

* test for fixed integer check
  • Loading branch information
yascho authored Apr 7, 2023
1 parent b714862 commit c1cb903
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mknapsack/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def pad_array(ar, width):

def check_all_int(ar):
"""Check if all input values are integers."""
return all(i == 0 or i % int(i) == 0 for i in ar)
return all(i - int(i) == 0 for i in ar)
10 changes: 10 additions & 0 deletions mknapsack/tests/test__single.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
'solution': [0, 1, 1, 1, 1, 1, 1, 0, 0, 0]
}

single_knapsack_case_small_real = {
'case': 'small-real',
'profits': [16, 78, 35, 89, 36, 94, 75, 74, 100, 80],
'weights': [30, 18, 0.4, 23, 20, 59, 61, 70, 75, 76],
'capacity': 190,
'total_profit': 407,
'solution': [0, 1, 1, 1, 1, 1, 1, 0, 0, 0]
}

single_knapsack_case_small_reverse = { # Ensure ordering works
'case': 'small-reverse',
'profits': [16, 78, 35, 89, 36, 94, 75, 74, 100, 80][::-1],
Expand Down Expand Up @@ -71,6 +80,7 @@
{'method': 'mt2', **single_knapsack_case_large},
{'method': 'mt1r', **single_knapsack_case_small, 'tolerance': 1e-07},
{'method': 'mt1r', **single_knapsack_case_medium, 'tolerance': 1e-07},
{'method': 'mt1r', **single_knapsack_case_small_real, 'tolerance': 1e-07},
{'method': 'mt1r', **single_knapsack_case_medium_real, 'tolerance': 1e-07}
]

Expand Down

0 comments on commit c1cb903

Please sign in to comment.