Fix wrong isPrime results, an EOF loop in the sprint4 map reader and a mis-decoded morse colon - #125
Merged
Merged
Conversation
…at EOF - replace the probabilistic isPrime certainty with trial division - make the Reader EOF sticky and fail fast in nextCommand - decode "---..." as a colon and drop two junk reverse-morse entries - emit "\n" from the diamond kata instead of the platform separator - drop the dependabot entries targeting the non-existent master branch Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
kyu6.Prime.isPrimereturned true for composite numbers. It calledBigInteger.isProbablePrime((int) Math.log(num) + 1), so the certainty was derived from the number itself: for9the certainty is3, i.e. Miller-Rabin was allowed to be wrong with probability up to 1/2^3.isPrime(9)reportedtrueon roughly 2% of runs — a non-deterministic kata answer. Replaced with deterministic trial division (num < 2→ false, even numbers handled, odd divisors up tosqrt(num)), which is also faster forint.algorithms.sprint4.Map.Readerreplayed its buffer after EOF.read()refilled only whenptr == len; at EOFlenbecomes-1withptr == 0, so the condition was false and the method kept returning stale bytes from the previous buffer (and eventually ran past its end).ptr >= lenmakes EOF sticky.nextCommand()could spin forever. Its whitespace skip loop had no EOF check, unlikenextInt(), so a truncated input (nlarger than the number of commands actually supplied) left it looping on-1forever. It now throwsIOException("Unexpected end of input"), whichmainalready treats as rejected input.---...decoded to;.---...is a colon; the semicolon-.-.-.was already mapped correctly one line above, so:could never be decoded. Also removed two leftover debug entries in the reverse table ("a" → "b","c" → "d").GiveMeDiamond.printjoined rows withSystem.lineSeparator(); the kata expects\n.TowerBuilder.show()was left alone — it is a display helper, not the kata answer.dependabot.ymlhad two entries targetingmaster, a branch that does not exist in this repository (default ismain), so they could only ever error. Removed; themainentries for maven and github-actions stay.Not changed (needs a decision)
algorithms/sprint0/Utils.printListswallowsIOExceptionper element. There is an explicit test (UtilsTest.printListSwallowsWriterFailures) asserting exactly that, so the behaviour is deliberate; changing it means changing the signature and the test.algorithms/sprint6/DorogayaSetuses-1as a "not found" sentinel, which collides with a legal answer. Fixing it changes the public method contract.**/*Test.java,**/*Tests.java,**/*TestCase.javaand**/*IT.java, so the tag-based suites insrc/test/java/quality/*Suite.javanever run in the build. Wiring them in would duplicate every test run — a decision about how the suites are meant to be used.Test plan
mvn -B -ntp verify(JDK 21) — BUILD SUCCESS,Tests run: 684, Failures: 0, Errors: 0, Skipped: 0, including checkstyle, PMD, SpotBugs and the 70% JaCoCo gates.PrimeTestnow checks primes (2, 3, 5, 7, 11, 13, 101, 7919, 2147483647) and non-primes (-7, -1, 0, 1, 4, 9, 15, 25, 49, 121, 7917, 2147483645); the old code failed on 9 intermittently.MapTest.readerReportsEndOfInputInsteadOfReplayingTheBufferfeeds"g 7"onSystem.inand asserts that the nextnextCommand()/nextInt()throw instead of replaying the buffer; it carries@Timeout(10)so the old infinite loop would fail rather than hang the build.MorseCodeDecoderTestgained the case"---... -.-.-."→":;".🤖 Generated with Claude Code