Skip to content

Commit 5e21695

Browse files
🔍 test(integerKnapsack): More tests.
1 parent f477241 commit 5e21695

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

test/src/integerKnapsack.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import test from 'ava';
2+
3+
import {integerKnapsack} from '../../src';
4+
5+
const macro = (t, v, w, n, W, expected) => {
6+
t.is(n, v.length);
7+
t.is(n, w.length);
8+
const result = integerKnapsack(v, w, n, W);
9+
t.is(expected, result);
10+
};
11+
12+
macro.title = (title, v, w, n, W, expected) =>
13+
title ||
14+
`integerKnapsack(${JSON.stringify(v)}, ${JSON.stringify(
15+
w,
16+
)}, ${n}, ${W}) = ${expected}`;
17+
18+
test(
19+
'wikipedia 0-1 knapsack example',
20+
macro,
21+
[505, 352, 458, 220, 354, 414, 498, 545, 473, 543],
22+
[23, 26, 20, 18, 32, 27, 29, 26, 30, 27],
23+
10,
24+
67,
25+
505,
26+
);
27+
28+
test(
29+
'https://www.geeksforgeeks.org/0-1-knapsack-problem-dp-10',
30+
macro,
31+
[60, 100, 120],
32+
[10, 20, 30],
33+
3,
34+
50,
35+
220,
36+
);

test/src/wikipedia.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)