CreditCardSource never produced a Discover card - #12
Merged
Conversation
CreditCardType.Random picked the type with Random.Next(1, 4), which stops at AmericanExpress. Discover is the last value of the enum and was unreachable: 5000 generated cards contained prefixes 3, 4 and 5 only, not a single 6. The picker reads the selectable types from the enum now, so a card type added later is drawn without anyone having to remember this line. Found by a reflection sweep over all 81 public sources plus a range sweep over every source with a (min, max) constructor. Those two sweeps found nothing else: no hangs, no exceptions, no constant sources beyond the intended Default* and LoremIpsum ones, no value outside a requested range. 867 tests per framework. Co-Authored-By: Claude Opus 5 (1M context) <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.
Found while checking whether "all bugs gone" is actually true before tagging v6.0.0. It was not.
The bug
CreditCardType.Randompicked the card type withRandom.Next(1, 4), whose upper bound is exclusive, so it stopped atAmericanExpress.Discover = 4is the last value of the enum and could never be produced. Measured over 5000 generated cards:The picker reads the selectable types from the enum now, so a card type added later is drawn without anyone having to remember this one line. The sequence of
CreditCardSourcechanged, which is why this has to land before the tag rather than in 6.1.How it was found
Two reflection sweeps over the built library, since reading code has repeatedly missed this class of bug:
Default*andLoremIpsumsources.(min, max)constructor given a narrow range, checked that all 400 draws land inside it and that both bounds are reachable, plus a reversed range to check it throws instead of hanging or returning nonsense. Clean.Neither sweep found anything else. The
CreditCardSourcebug came from a targeted grep for the off-by-one pattern that had already bittenRandomStringSourceandUrlSourcein #10.Not fixed here
LoremIpsumSource(count)puts its blank-line separator in the wrong place:count: 3givesTT\n\nTinstead ofT\n\nT\n\nT. It is deterministic text, so no generated sequence depends on it and 6.1 can fix it without breaking anyone.Verification
dotnet build -c Releasezero warnings, 867 tests per framework on net8/9/10, 2607 total, all green.🤖 Generated with Claude Code