forked from TheAlgorithms/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZeroOneKnapsack.test.js
More file actions
40 lines (37 loc) · 879 Bytes
/
ZeroOneKnapsack.test.js
File metadata and controls
40 lines (37 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { zeroOneKnapsack } from '../ZeroOneKnapsack'
describe('ZeroOneKnapsack', () => {
it('zeroOneKnapsack when capacity is 4 and 5 items', () => {
expect(
zeroOneKnapsack(
[
[1, 8],
[2, 4],
[3, 0],
[2, 5],
[2, 3]
],
5,
4,
[
[-1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1]
]
)
).toBe(13)
})
it('zeroOneKnapsack when capacity is 1 and 1 items', () => {
expect(
zeroOneKnapsack([[1, 80]], 1, 1, [
[-1, -1],
[-1, -1]
])
).toBe(80)
})
it('zeroOneKnapsack when capacity is 0 and 1 items', () => {
expect(zeroOneKnapsack([[1, 80]], 1, 0, [[-1], [-1]])).toBe(0)
})
})