Skip to content

CreditCardSource never produced a Discover card - #12

Merged
holonsoftFounder merged 1 commit into
mainfrom
fix/credit-card-discover
Sep 11, 2026
Merged

CreditCardSource never produced a Discover card#12
holonsoftFounder merged 1 commit into
mainfrom
fix/credit-card-discover

Conversation

@holonsoftFounder

Copy link
Copy Markdown
Member

Found while checking whether "all bugs gone" is actually true before tagging v6.0.0. It was not.

The bug

CreditCardType.Random picked the card type with Random.Next(1, 4), whose upper bound is exclusive, so it stopped at AmericanExpress. Discover = 4 is the last value of the enum and could never be produced. Measured over 5000 generated cards:

prefix 3 (AmericanExpress): 1640
prefix 4 (Visa):            1650
prefix 5 (MasterCard):      1710
prefix 6 (Discover):           0

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 CreditCardSource changed, 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:

  1. Every public source (81 of them) instantiated with its parameterless constructor, 60 draws each, flagged for constant output, exceptions, hangs and infinity/NaN. Clean apart from the intentionally constant Default* and LoremIpsum sources.
  2. Every source with a (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 CreditCardSource bug came from a targeted grep for the off-by-one pattern that had already bitten RandomStringSource and UrlSource in #10.

Not fixed here

LoremIpsumSource(count) puts its blank-line separator in the wrong place: count: 3 gives TT\n\nT instead of T\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 Release zero warnings, 867 tests per framework on net8/9/10, 2607 total, all green.

🤖 Generated with Claude Code

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>
@holonsoftFounder
holonsoftFounder merged commit 3f068eb into main Sep 11, 2026
2 checks passed
@holonsoftFounder
holonsoftFounder deleted the fix/credit-card-discover branch September 11, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant