Skip to content

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
wants to merge 14 commits into from

Conversation

sunilnitdgp
Copy link
Contributor

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@sunilnitdgp
Copy link
Contributor Author

I request the maintainer(s) to merge my request using "hacktoberfest-accepted" label.

Copy link
Member

@vil02 vil02 left a 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 as final,
  • add a private default constructor of RodCutting.

Comment on lines +9 to +71
@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));
}
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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

Copy link
Member

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?

@vil02 vil02 self-assigned this Oct 9, 2023
@siriak
Copy link
Member

siriak commented Oct 11, 2023

Linter is still failing

@sunilnitdgp
Copy link
Contributor Author

@siriak Fixed the linter issue.

@sunilnitdgp
Copy link
Contributor Author

@vil02 / @siriak Please review this and merge if everything looks good.

Copy link

github-actions bot commented Jan 2, 2024

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.

@github-actions github-actions bot added the stale label Jan 2, 2024
Copy link

github-actions bot commented Jan 9, 2024

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!

@github-actions github-actions bot closed this Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants