NeonNumber algorithm in maths package#7420
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7420 +/- ##
=========================================
Coverage 79.53% 79.54%
- Complexity 7177 7180 +3
=========================================
Files 798 799 +1
Lines 23474 23481 +7
Branches 4617 4619 +2
=========================================
+ Hits 18671 18678 +7
Misses 4055 4055
Partials 748 748 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
prashantpiyush1111
left a comment
There was a problem hiding this comment.
Overall structure is good — final class, private constructor,
and JavaDoc are all in place.
However, there are a few issues that need to be fixed
before merging:
- Integer overflow in
isNeon()method - No handling for negative inputs
isNeon(0)works by coincidence, not by logic- Missing edge case tests
Please address the inline comments.
| * @return true if neon number, false otherwise | ||
| */ | ||
| public static boolean isNeon(final int number) { | ||
| int square = number * number; |
There was a problem hiding this comment.
Integer overflow risk! For large inputs (e.g. number = 50000),
number * number exceeds Integer.MAX_VALUE and gives wrong result.
Fix:
long square = (long) number * number;
| */ | ||
| public static boolean isNeon(final int number) { | ||
| int square = number * number; | ||
| int digitSum = 0; |
There was a problem hiding this comment.
No validation for negative numbers. isNeon(-5) won't crash
but behavior is unintended.
Fix: Add at the start of method:
if (number < 0) {
throw new IllegalArgumentException("Input must be non-negative");
}
| int square = number * number; | ||
| int digitSum = 0; | ||
| int temp = square; | ||
| while (temp > 0) { |
There was a problem hiding this comment.
When number = 0, temp = 0, so this loop never runs.
isNeon(0) returns true only by coincidence.
Fix:
if (number == 0) return true;
| public class NeonNumberTest { | ||
|
|
||
| @Test | ||
| public void testIsNeonTrue() { |
There was a problem hiding this comment.
assertTrue(NeonNumber.isNeon(0)) passes but for wrong reason —
loop never executes for 0. Consider adding explicit test
that verifies the logic, not just the output.
| } | ||
|
|
||
| @Test | ||
| public void testIsNeonFalse() { |
There was a problem hiding this comment.
Missing edge case tests:
-
Negative input:
assertThrows(IllegalArgumentException.class,
() -> NeonNumber.isNeon(-1)); -
Large number to catch overflow:
assertFalse(NeonNumber.isNeon(50000));
prashantpiyush1111
left a comment
There was a problem hiding this comment.
Comment box mein ye likho:
Please address the inline comments
before this can be merged:
-
Integer overflow: use
long square = (long) number * number -
Add negative input validation
-
Handle isNeon(0) explicitly
-
Add missing edge case tests
Added NeonNumber algorithm that checks if a
number is a Neon Number.
Example: 9 → 9²=81 → 8+1=9 ✓