mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
Add edge case to handle negative rod length in RodCutting algorithm (#5904)
This commit is contained in:
@@ -93,4 +93,10 @@ class RodCuttingTest {
|
||||
int length = 5;
|
||||
assertThrows(IllegalArgumentException.class, () -> RodCutting.cutRod(prices, length), "An empty prices array should throw an IllegalArgumentException.");
|
||||
}
|
||||
@Test
|
||||
void testCutRodNegativeLength() {
|
||||
int[] prices = {1, 5, 8, 9, 10}; // Prices are irrelevant for negative length
|
||||
int length = -1;
|
||||
assertThrows(IllegalArgumentException.class, () -> RodCutting.cutRod(prices, length), "A negative rod length should throw an IllegalArgumentException.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user