-
Notifications
You must be signed in to change notification settings - Fork 20k
Added test cases for RodCuttingTest.java #4744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I request the maintainer(s) to merge my request using "hacktoberfest-accepted" label. |
All reactions
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please:
- remove the
main
method, - mark
RodCutting
asfinal
, - add a
private
default constructor ofRodCutting
.
Sorry, something went wrong.
All reactions
@Test | ||
public void testCutRodWithSinglePiece() { | ||
// Test case 1: Rod length is 1 with a single piece | ||
int[] price1 = {2}; | ||
assertEquals(2, RodCutting.cutRod(price1, 1)); | ||
} | ||
|
||
@Test | ||
public void testCutRodWithTwoPieces() { | ||
// Test case 2: Rod length is 2 with two pieces | ||
int[] price2 = {2, 5}; | ||
assertEquals(5, RodCutting.cutRod(price2, 2)); | ||
} | ||
|
||
@Test | ||
public void testCutRodWithThreePieces() { | ||
// Test case 3: Rod length is 3 with three pieces | ||
int[] price3 = {2, 5, 13}; | ||
assertEquals(13, RodCutting.cutRod(price3, 3)); | ||
} | ||
|
||
@Test | ||
public void testCutRodWithFourPieces() { | ||
// Test case 4: Rod length is 4 with four pieces | ||
int[] price4 = {2, 5, 13, 19}; | ||
assertEquals(19, RodCutting.cutRod(price4, 4)); | ||
} | ||
|
||
@Test | ||
public void testCutRodWithFivePieces() { | ||
// Test case 5: Rod length is 5 with five pieces | ||
int[] price5 = {2, 5, 13, 19, 20}; | ||
assertEquals(21, RodCutting.cutRod(price5, 5)); | ||
} | ||
|
||
@Test | ||
public void testCutRodWithNegativeInput() { | ||
// Test case 6: Negative rod length (should throw an IllegalArgumentException) | ||
int[] negativePrice = {2, 5, 13}; | ||
assertThrows(NegativeArraySizeException.class, () -> RodCutting.cutRod(negativePrice, -3)); | ||
|
||
// Test case 7: Negative prices in the price array (should return 13) | ||
int[] negativePrices = {2, -5, 13}; | ||
assertEquals(13, RodCutting.cutRod(negativePrices, 3)); | ||
} | ||
|
||
@Test | ||
public void testCutRodWithZeroLength() { | ||
// Test case 8: Rod length is greater than the length of the price array (invalid input) | ||
int[] price6 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | ||
assertThrows(ArrayIndexOutOfBoundsException.class, () -> RodCutting.cutRod(price6, 20)); | ||
|
||
// Test case 9: Rod length is 0 (should return 0 as the rod cannot be cut) | ||
int[] emptyPrice = {}; | ||
assertEquals(0, RodCutting.cutRod(emptyPrice, 0)); | ||
} | ||
|
||
@Test | ||
public void testCutRodWithLargeInput() { | ||
// Test case 10: Large rod length | ||
int[] price7 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | ||
assertEquals(10, RodCutting.cutRod(price7, 10)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you verify these test cases?
Sorry, something went wrong.
All reactions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sunilnitdgp this is still pending.
Sorry, something went wrong.
All reactions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide a source of the test data or the method used to create it
Sorry, something went wrong.
All reactions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sunilnitdgp what is the progress?
Sorry, something went wrong.
All reactions
src/main/java/com/thealgorithms/dynamicprogramming/RodCutting.java
Outdated
Show resolved
Hide resolved
Linter is still failing |
All reactions
Sorry, something went wrong.
@siriak Fixed the linter issue. |
All reactions
Sorry, something went wrong.
Sorry, something went wrong.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
All reactions
Sorry, something went wrong.
Please reopen this pull request once you have made the required changes. If you need help, feel free to ask in our Discord server or ping one of the maintainers here. Thank you for your contribution! |
All reactions
Sorry, something went wrong.
siriak
vil02
yanglbme
debasishbsws
BamaCharanChhandogi
Successfully merging this pull request may close these issues.
None yet
clang-format -i --style=file path/to/your/file.java