- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathWineProblemTest.java
72 lines (63 loc) · 2.4 KB
/
WineProblemTest.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
packagecom.thealgorithms.dynamicprogramming;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.api.Assertions.assertThrows;
importorg.junit.jupiter.api.Test;
/**
* Unit tests for the WineProblem class.
* This test class verifies the correctness of the wine selling problem solutions.
*/
classWineProblemTest {
/**
* Test for wpRecursion method.
*/
@Test
voidtestWpRecursion() {
int[] wines = {2, 3, 5, 1, 4}; // Prices of wines
intexpectedProfit = 50; // The expected maximum profit
assertEquals(expectedProfit, WineProblem.wpRecursion(wines, 0, wines.length - 1), "The maximum profit using recursion should be 50.");
}
/**
* Test for wptd method (Top-Down DP with Memoization).
*/
@Test
voidtestWptd() {
int[] wines = {2, 3, 5, 1, 4}; // Prices of wines
intexpectedProfit = 50; // The expected maximum profit
assertEquals(expectedProfit, WineProblem.wptd(wines, 0, wines.length - 1, newint[wines.length][wines.length]), "The maximum profit using top-down DP should be 50.");
}
/**
* Test for wpbu method (Bottom-Up DP with Tabulation).
*/
@Test
voidtestWpbu() {
int[] wines = {2, 3, 5, 1, 4}; // Prices of wines
intexpectedProfit = 50; // The expected maximum profit
assertEquals(expectedProfit, WineProblem.wpbu(wines), "The maximum profit using bottom-up DP should be 50.");
}
/**
* Test with a single wine.
*/
@Test
voidtestSingleWine() {
int[] wines = {10}; // Only one wine
intexpectedProfit = 10; // Selling the only wine at year 1
assertEquals(expectedProfit, WineProblem.wpbu(wines), "The maximum profit for a single wine should be 10.");
}
/**
* Test with multiple wines of the same price.
*/
@Test
voidtestSamePriceWines() {
int[] wines = {5, 5, 5}; // All wines have the same price
intexpectedProfit = 30; // Profit is 5 * (1 + 2 + 3)
assertEquals(expectedProfit, WineProblem.wpbu(wines), "The maximum profit with same price wines should be 30.");
}
/**
* Test with no wines.
*/
@Test
voidtestNoWines() {
int[] wines = {};
assertThrows(IllegalArgumentException.class, () -> WineProblem.wpbu(wines), "The maximum profit for no wines should throw an IllegalArgumentException.");
}
}