Repository navigation
NumberTheory, Sequences, Statistics on double[], math and string property tests - #9
Conversation
gcd, lcm, primality and prime factorisation stay in NumberTheory; fibonacci, fibonacciSimpleBinetFormula and fibonacciBinetFormula move unchanged to the new math.Sequences, with their tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mean, median, mode and meanAbsoluteDeviation now take double[] (mode returns double); method bodies are unchanged apart from the types. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- NumberTheory: gcdLoop and gcdRecursive agree; gcd divides both; lcm * gcd = a * b; lcm of a list is a multiple of every element; isPrime agrees with trial division; prime factors multiply back to n, are prime and sorted; primeFactorsSet holds the distinct factors - Sequences (exhaustive): each Fibonacci variant matches an exact BigInteger reference over the range its Javadoc claims (46, 67, 71) - Statistics: mean within [min, max]; median is the sorted middle; mode is one of the values - StringUtils: isPalindrome agrees with reversing; mirrored strings are palindromes; shuffles are anagrams (case-insensitive); isAnagram agrees with letter counts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 78 |
| Duplication | 0 |
AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.
TIP This summary will be updated as you push new changes.
There was a problem hiding this comment.
Pull Request Overview
Two blocking correctness gaps remain: the Binet Fibonacci implementations accept invalid negative indices, and Statistics methods fail or return NaN for empty arrays. These affect documented API behavior and should be addressed before merging. The Sequences implementation also has a precision-risk suggestion involving BigDecimal construction.
Test suggestions
- Verify both gcd implementations agree and the result divides both positive inputs.
- Verify two-value and list lcm behavior, including the gcd/lcm product invariant.
- Verify primality against trial division, including values near Integer.MAX_VALUE.
- Verify prime factors multiply to the input, are prime and sorted, and that the factor set is distinct.
- Verify all Fibonacci implementations against an exact reference over their documented ranges.
- Verify mean bounds, median ordering behavior, and mode membership for double[] data.
- Verify palindrome and anagram properties, including shuffled and case-insensitive inputs.
- Verify Statistics behavior for empty arrays, especially median and mean absolute deviation.
Prompt proposal for missing tests
Consider implementing these tests if applicable:
1. Verify Statistics behavior for empty arrays, especially median and mean absolute deviation.
Make this review better
TIP Add a ticket key to the branch or title so the reviewer can check the PR against it. Or tell us which ticket tracker you use here.
TIP Add Codacy review.md instructions or an AGENTS.md so the reviewer knows your conventions.
TIP How was this review? Give us feedback
| * @return the Average Absolute Deviation from data | ||
| */ | ||
| public static double meanAbsoluteDeviation(int[] data) { | ||
| public static double meanAbsoluteDeviation(double[] data) { |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Define and apply an explicit empty-array result before dividing by data.length.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| * @return | ||
| */ | ||
| public static double median(int[] data) { | ||
| public static double median(double[] data) { |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Handle data.length == 0 before indexing, using the intended empty-data contract.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
| public static double fibonacciSimpleBinetFormula(int n) { | ||
| if (n == 0) { | ||
| return 0; | ||
| } | ||
| final double phi = (1 + Math.sqrt(5)) / 2; | ||
| final double sqrt5 = Math.sqrt(5); | ||
| return ((Math.pow(phi, n) - Math.pow(-phi, -n)) / sqrt5); |
There was a problem hiding this comment.
🟡 MEDIUM RISK
Add the same negative-index validation used by fibonacci before evaluating either Binet formula.
TIP React 👍 if this review is right, or reply with what's wrong and how it could be better to help improve the reviewer.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9 +/- ##
============================================
+ Coverage 92.41% 94.09% +1.68%
- Complexity 260 264 +4
============================================
Files 23 24 +1
Lines 593 593
Branches 94 94
============================================
+ Hits 548 558 +10
+ Misses 26 17 -9
+ Partials 19 18 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Clears Codacy/PMD AvoidDecimalLiteralsInBigDecimalConstructor (High). Results are unchanged: SequencesPropertyTest checks every n in 0..71 against an exact BigInteger reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sequences only has static methods, so it gets a private constructor (JaCoCo leaves private empty constructors out of coverage), and fibonacci(-1) is now tested to throw with its message. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Last of the three library-redesign PRs. Algorithms are moved or retyped as they are; no method bodies were rewritten.
Math
Algebra→NumberTheory(git rename): gcd (gcdLoop,gcdRecursive), lcm,isPrimeand prime factorisation.Sequencesclass holdsfibonacci,fibonacciSimpleBinetFormulaandfibonacciBinetFormula, moved unchanged together with their tests.Statisticsnow takesdouble[](modereturnsdouble). Only the types changed. Rainfall now usesStatistics.mean.MeasurementandGeometrykeep all their methods (Q10).Property tests (jqwik)
isPrimeagrees with trial division; prime factors multiply back to n, are all prime and come out sorted;primeFactorsSetholds the distinct factors.BigIntegerreference over the ranges the Javadoc states (fibonacci≤ 46, simple Binet ≤ 67,BigIntegerBinet ≤ 71). All three claims hold.isPalindromeagrees with reversing the string; mirrored strings are palindromes; shuffles are anagrams, case-insensitively;isAnagramagrees with letter counts. Inputs are ASCII letters, since both methods comparecharbychar.Checked that the properties catch real bugs: breaking
gcdLoop's loop condition made 4 properties fail.Not changed, but worth knowing
Statistics.mediansorts the array it's given in place, so the caller's data gets reordered.Statistics.meansums naively, so values nearDouble.MAX_VALUEoverflow toInfinity.Test plan
./mvnw verify: 581 tests, coverage floors met🤖 Generated with Claude Code