forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFractionalKnapsackTest.java
More file actions
32 lines (26 loc) · 960 Bytes
/
FractionalKnapsackTest.java
File metadata and controls
32 lines (26 loc) · 960 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
package com.thealgorithms.greedyalgorithms;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class FractionalKnapsackTest {
@Test
public void testFractionalKnapsackWithExampleCase() {
int[] weight = {10, 20, 30};
int[] value = {60, 100, 120};
int capacity = 50;
assertEquals(240, FractionalKnapsack.fractionalKnapsack(weight, value, capacity));
}
@Test
public void testFractionalKnapsackWithZeroCapacity() {
int[] weight = {10, 20, 30};
int[] value = {60, 100, 120};
int capacity = 0;
assertEquals(0, FractionalKnapsack.fractionalKnapsack(weight, value, capacity));
}
@Test
public void testFractionalKnapsackWithEmptyItems() {
int[] weight = {};
int[] value = {};
int capacity = 50;
assertEquals(0, FractionalKnapsack.fractionalKnapsack(weight, value, capacity));
}
}