- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathKnapsackMemoizationTest.java
49 lines (41 loc) · 1.44 KB
/
KnapsackMemoizationTest.java
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
41
42
43
44
45
46
47
48
49
packagecom.thealgorithms.dynamicprogramming;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importorg.junit.jupiter.api.Test;
publicclassKnapsackMemoizationTest {
KnapsackMemoizationknapsackMemoization = newKnapsackMemoization();
@Test
voidtest1() {
int[] weight = {1, 3, 4, 5};
int[] value = {1, 4, 5, 7};
intcapacity = 10;
assertEquals(13, knapsackMemoization.knapSack(capacity, weight, value, weight.length));
}
@Test
voidtest2() {
int[] weight = {95, 4, 60, 32, 23, 72, 80, 62, 65, 46};
int[] value = {55, 10, 47, 5, 4, 50, 8, 61, 85, 87};
intcapacity = 269;
assertEquals(295, knapsackMemoization.knapSack(capacity, weight, value, weight.length));
}
@Test
voidtest3() {
int[] weight = {10, 20, 30};
int[] value = {60, 100, 120};
intcapacity = 50;
assertEquals(220, knapsackMemoization.knapSack(capacity, weight, value, weight.length));
}
@Test
voidtest4() {
int[] weight = {1, 2, 3};
int[] value = {10, 20, 30};
intcapacity = 0;
assertEquals(0, knapsackMemoization.knapSack(capacity, weight, value, weight.length));
}
@Test
voidtest5() {
int[] weight = {1, 2, 3, 8};
int[] value = {10, 20, 30, 40};
intcapacity = 50;
assertEquals(100, knapsackMemoization.knapSack(capacity, weight, value, weight.length));
}
}