Skip to content

Commit 453c64c

Browse files
🔍 test: Increase coverage.
1 parent 40585f4 commit 453c64c

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/integerValuesKnapsackUnbounded.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {max, map, range} from '@aureooms/js-itertools';
1010
* @param {Array} w Weights.
1111
* @param {Number} n Size of the problem.
1212
* @param {Number} W Size of the knapsack.
13+
* @param {Number|BigInt} zero The number 0.
1314
* @param {Number} V Any upper bound on OPT >= 0.
1415
* @param {Array} m Memory buffer.
1516
*/
@@ -18,11 +19,13 @@ const integerValuesKnapsackUnbounded = (
1819
w,
1920
n,
2021
W,
22+
zero = 0,
2123
V = Math.floor(
2224
W *
2325
max(
2426
increasing,
2527
map((i) => v[i] / w[i], range(n)),
28+
zero,
2629
),
2730
),
2831
m = new w.constructor(V + 1).fill(W + 1),

test/src/0-1-knapsack-problem.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const approx = (ratio) => {
3939
solve,
4040
name,
4141
approx: ratio,
42+
hypothesis: (_v, _w, n) => n > 0,
4243
};
4344
};
4445

@@ -57,6 +58,14 @@ const solvers = [
5758
];
5859

5960
const instances = [
61+
{
62+
title: 'empty instance',
63+
v: [],
64+
w: [],
65+
n: 0,
66+
W: 15,
67+
opt: 0,
68+
},
6069
{
6170
title: 'wikipedia illustration',
6271
v: [4, 2, 2, 1, 10],

test/src/unbounded-knapsack-problem.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ const solvers = [
4646
];
4747

4848
const instances = [
49+
{
50+
title: 'empty instance',
51+
v: [],
52+
w: [],
53+
n: 0,
54+
W: 15,
55+
opt: 0,
56+
},
4957
{
5058
title: 'wikipedia illustration',
5159
v: [4, 2, 2, 1, 10],

0 commit comments

Comments
 (0)