Skip to content

Commit fd2f306

Browse files
committed
Add test case for negative rod length in RodCuttingTest
1 parent c6e01a8 commit fd2f306

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/test/java/com/thealgorithms/dynamicprogramming/RodCuttingTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,11 @@ void testCutRodEmptyPrices() {
9393
int length = 5;
9494
assertThrows(IllegalArgumentException.class, () -> RodCutting.cutRod(prices, length), "An empty prices array should throw an IllegalArgumentException.");
9595
}
96+
@Test
97+
void testCutRodNegativeLength() {
98+
int[] prices = {1, 5, 8, 9, 10}; // Prices are irrelevant for negative length
99+
int length = -1;
100+
assertThrows(IllegalArgumentException.class, () -> RodCutting.cutRod(prices, length),
101+
"A negative rod length should throw an IllegalArgumentException.");
102+
}
96103
}

0 commit comments

Comments
 (0)