Repository navigation
fix: a female or a male Name on each call - #107
Merged
Merged
Conversation
name() chose between the female and the male lists with randNameFlag, which was drawn once when the package started, so every Name() of a run was a female name or every one was a male name (2,000 calls gave 0 male titles, or 0 female ones, depending on the run). The choice is drawn on every call now, and randNameFlag is gone. The tests that set randNameFlag after the call did not test either list, they only left the flag at 51 or 20 for the tests after them. They check that a name is not empty as before, and two new tests check that both genders come up and that the title and the first name of a Name are from the same gender.
bxcodec
approved these changes
Nov 24, 2026
bxcodec
left a comment
Contributor
There was a problem hiding this comment.
LGTM on this, thanks for the PR
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.
Name()was a female name for the whole run of the program, or a male name for the whole run: 2,000 calls gave titles like Mrs., Lady and Queen and none like Mr., Lord and King, or the other way round (four runs of the new test on master: 1,356 and 0, 1,310 and 0, 0 and 1,514, 0 and 1,490 names with a title that only one gender has).Why
namepicks the female or the male lists withrandNameFlag > 50, andrandNameFlagisrand.Intn(100)drawn once ininit(). So the coin was flipped when the package started and every call used the same side. The tests set the flag to 51 and to 20 to reach each list, but they set it after the call, so neither list is tested, and the flag is left at 20 for the tests that follow.What changed
nameflips the coin on every call (rand.Intn(2) == 0).randNameFlagand its line ininit()are gone.randNameFlagafter callingName()check that the name is not empty, as they did, without the flag.TestNameGenderVaries: of 2,000 names about 667 have a title that only a man has (Mr., Prince, King, Lord) and about 750 a title that only a woman has (Dr. and Prof. are in both lists and are left out); it wants 500 of each and fails on master. NewTestNameIsOneGender: the title and the first name of aName()come from the same list; it passes on master and keeps it that way.It is the same kind of process wide value as the card type in #105. I came across it reading the generators.
How it was tested
TestNameGenderVariesfails on master in every run (one gender only), passes on the change in 6 runs in a row.go test ./...,go vetandgofmtpass. I could not run-raceor golangci-lint here (no C compiler and no linter installed), CI does.