You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* This test class verifies the correctness of the wine selling problem solutions.
11
+
*/
12
+
classWineProblemTest {
13
+
14
+
/**
15
+
* Test for wpRecursion method.
16
+
*/
17
+
@Test
18
+
voidtestWpRecursion() {
19
+
int[] wines = {2, 3, 5, 1, 4}; // Prices of wines
20
+
intexpectedProfit = 50; // The expected maximum profit
21
+
assertEquals(expectedProfit, WineProblem.wpRecursion(wines, 0, wines.length - 1), "The maximum profit using recursion should be 50.");
22
+
}
23
+
24
+
/**
25
+
* Test for wptd method (Top-Down DP with Memoization).
26
+
*/
27
+
@Test
28
+
voidtestWptd() {
29
+
int[] wines = {2, 3, 5, 1, 4}; // Prices of wines
30
+
intexpectedProfit = 50; // The expected maximum profit
31
+
assertEquals(expectedProfit, WineProblem.wptd(wines, 0, wines.length - 1, newint[wines.length][wines.length]), "The maximum profit using top-down DP should be 50.");
32
+
}
33
+
34
+
/**
35
+
* Test for wpbu method (Bottom-Up DP with Tabulation).
36
+
*/
37
+
@Test
38
+
voidtestWpbu() {
39
+
int[] wines = {2, 3, 5, 1, 4}; // Prices of wines
40
+
intexpectedProfit = 50; // The expected maximum profit
41
+
assertEquals(expectedProfit, WineProblem.wpbu(wines), "The maximum profit using bottom-up DP should be 50.");
42
+
}
43
+
44
+
/**
45
+
* Test with a single wine.
46
+
*/
47
+
@Test
48
+
voidtestSingleWine() {
49
+
int[] wines = {10}; // Only one wine
50
+
intexpectedProfit = 10; // Selling the only wine at year 1
51
+
assertEquals(expectedProfit, WineProblem.wpbu(wines), "The maximum profit for a single wine should be 10.");
52
+
}
53
+
54
+
/**
55
+
* Test with multiple wines of the same price.
56
+
*/
57
+
@Test
58
+
voidtestSamePriceWines() {
59
+
int[] wines = {5, 5, 5}; // All wines have the same price
assertEquals(expectedProfit, WineProblem.wpbu(wines), "The maximum profit with same price wines should be 30.");
62
+
}
63
+
64
+
/**
65
+
* Test with no wines.
66
+
*/
67
+
@Test
68
+
voidtestNoWines() {
69
+
int[] wines = {};
70
+
assertThrows(IllegalArgumentException.class, () -> WineProblem.wpbu(wines), "The maximum profit for no wines should throw an IllegalArgumentException.");
0 commit comments