Currently, to strictly check input string for correctness a student has to perform two checks:
try to call toInt() on number (to check format and integer range) and throw IllegalArgumentException if NumberFormatException happens;
match with regex (something like [0-9]+) (to forbid signed numbers (+1, -7 etc.)), throw IAE if number does not match this regex.
Most students usually do not do at least one of those and it is rarely noted by teachers. A possible bug can only be found by random tests in some rare cases.
This can be solved two ways:
provide some non random tests (like 1 + +3, 12 + -2, 121212121212121212121 + 3). (I'm not sure if JUnit's assertThrows will allow us to check if IAE but not NFE is thrown)
consider the first two examples correct inputs (and everything accepted by .toInt()). (This way we have to update the model implementation since it tries to strictly check input string).
Currently, to strictly check input string for correctness a student has to perform two checks:
toInt()
on number (to check format and integer range) and throwIllegalArgumentException
ifNumberFormatException
happens;[0-9]+
) (to forbid signed numbers (+1
,-7
etc.)), throw IAE if number does not match this regex.Most students usually do not do at least one of those and it is rarely noted by teachers. A possible bug can only be found by random tests in some rare cases.
This can be solved two ways:
1 + +3
,12 + -2
,121212121212121212121 + 3
). (I'm not sure if JUnit'sassertThrows
will allow us to check if IAE but not NFE is thrown).toInt()
). (This way we have to update the model implementation since it tries to strictly check input string).