Skip to content

Commit 555e8ef

Browse files
🔍 test(knapsackApprox): Cover 100%.
1 parent 4fe6f78 commit 555e8ef

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/src/examples.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {all, map} from '@aureooms/js-itertools';
55
import {
66
integerValuesKnapsack,
77
integerWeightsKnapsack,
8+
knapsackApprox,
89
} from '../../src';
910

1011
const macro = (t, solve, _name, v, w, n, W, opt, approx) => {
@@ -29,6 +30,18 @@ macro.title = (title, solve, name, v, w, n, W, opt, approx) =>
2930
w,
3031
)}, ${n}, ${W}) >= ${approx} * ${opt}`;
3132

33+
const approx = (ratio) => {
34+
const eps = 1 - ratio;
35+
const name = `${knapsackApprox.name}(eps=${eps})`;
36+
const solve = (v, w, n, W) => knapsackApprox(eps, v, w, n, W);
37+
38+
return {
39+
solve,
40+
name,
41+
approx: ratio,
42+
};
43+
};
44+
3245
const solvers = [
3346
{
3447
solve: integerValuesKnapsack,
@@ -38,6 +51,9 @@ const solvers = [
3851
solve: integerWeightsKnapsack,
3952
hypothesis: (_, w) => all(map((x) => Number.isInteger(x), w)),
4053
},
54+
approx(1 / 2),
55+
approx(2 / 3),
56+
approx(3 / 4),
4157
];
4258

4359
const instances = [

0 commit comments

Comments
 (0)