-
Notifications
You must be signed in to change notification settings - Fork 5
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
Fix error message to fit desired usage for indexing of integers larger than max int #164
Fix error message to fit desired usage for indexing of integers larger than max int #164
Conversation
Codecov Report
@@ Coverage Diff @@
## master #164 +/- ##
============================================
+ Coverage 79.44% 80.10% +0.65%
- Complexity 697 714 +17
============================================
Files 95 96 +1
Lines 2097 2151 +54
Branches 258 264 +6
============================================
+ Hits 1666 1723 +57
+ Misses 361 358 -3
Partials 70 70
Continue to review full report at Codecov.
|
* @param s | ||
* @return | ||
*/ | ||
private static boolean isAllDigits(String s) { |
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.
I think a regex check suffices here. return s.matches("^\\d+$")
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.
Thanks for the suggestion! Have replaced the existing function with this regex.
String trimmedIndex = oneBasedIndex.trim(); | ||
if (!StringUtil.isNonZeroUnsignedInteger(trimmedIndex)) { | ||
|
||
if (!isAllDigits(trimmedIndex) || trimmedIndex.equals("0") || trimmedIndex.equals("")) { |
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.
Does isAllDigits
cover the case whereby trimmedIndex.equals("")
?
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.
Have removed the unnecessary condition, thanks for pointing out!
@@ -36,16 +37,59 @@ | |||
|
|||
public static final String MESSAGE_INVALID_INDEX = "Index is not a non-zero unsigned integer."; | |||
|
|||
public static final String MESSAGE_INDEX_OUT_OF_BOUNDS = "The index provided is invalid"; |
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.
Very minor nitpick, remember to add in a full stop here 😅
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.
Okay thanks for the keen observation!
@@ -191,6 +194,10 @@ private CommandResult executeCommand(String commandText) throws CommandException | |||
logger.info("Invalid command: " + commandText); | |||
resultDisplay.setFeedbackToUser(e.getMessage()); | |||
throw e; | |||
} catch (IndexOutOfBoundsException ie) { | |||
logger.info("Invalid index: " + commandText); |
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.
Good use of logging. 👍
clearremark
index results in unexpected error message
#142
Resolves #116, #123, #130, #135, #142
Resolves get, remark, deletelesson, edit and clearremark
Adjusted ParserUtil to break down indexing into 2 cases:
When input < max_int
When input > max_int
When input wiithin list range
When input is empty