Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feat: throw an exception instead on testInteger & testLong #1194

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

SharmaNishchay
Copy link
Contributor

@SharmaNishchay SharmaNishchay commented Mar 30, 2025

Closes #1161

@SharmaNishchay SharmaNishchay changed the title TODO: throw an exception instead on testInteger TODO: throw an exception instead on testInteger & testLong Mar 30, 2025
@SharmaNishchay SharmaNishchay changed the title TODO: throw an exception instead on testInteger & testLong Feat: throw an exception instead on testInteger & testLong Mar 30, 2025
@SharmaNishchay
Copy link
Contributor Author

@mrigger The checks are passing. Please review the changes. Thanks!

Copy link

@bhavaniprasad-tech bhavaniprasad-tech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@test
public void testIntegerValidRange() {
Randomly r = new Randomly();
for (int i = 0; i < 100; i++) {
int val = r.getInteger(5, 10);
assertTrue(val >= 5 && val <= 10);
}
}

@bhavaniprasad-tech
Copy link

Add input validation for getInteger() and update corresponding test

  • Added a check in Randomly.getInteger(left, right) to throw IllegalArgumentException when left > right
  • Updated testInteger() in TestRandomly.java to assert this exception
  • Ensures safer and more predictable behavior for invalid input ranges

@SharmaNishchay
Copy link
Contributor Author

SharmaNishchay commented Apr 9, 2025

Add input validation for getInteger() and update corresponding test

  • Added a check in Randomly.getInteger(left, right) to throw IllegalArgumentException when left > right
  • Updated testInteger() in TestRandomly.java to assert this exception
  • Ensures safer and more predictable behavior for invalid input ranges

I think the testLong2() method already handles that scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TODO: Add Exception for TestRandomly.java
2 participants