-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4c1bfa3
Added test cases for RodCuttingTest.java
sunilnitdgp 17480a4
Changed access type from private to public
sunilnitdgp c26c6d0
Fixed test cases.
sunilnitdgp 5c84eaf
Fixed formatting
sunilnitdgp 8871b0f
Formatted the code
sunilnitdgp f0909c4
formatting
sunilnitdgp e1b3800
Formatted
sunilnitdgp b51e4f5
Fixed review comments
sunilnitdgp 4c4265e
Formatted
sunilnitdgp 511d926
Refactored
sunilnitdgp 8b6c5b3
Refactored
sunilnitdgp 963a8f7
Refactored
sunilnitdgp 260dfd7
Refacttored
sunilnitdgp e56cc1f
Merge branch 'master' into patch-10
vil02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/test/java/com/thealgorithms/dynamicprogramming/RodCuttingTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.thealgorithms.dynamicprogramming; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class RodCuttingTest { | ||
|
||
@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)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?
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.
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
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?