Skip to content

Commit

Permalink
Fix generation of female FNR
Browse files Browse the repository at this point in the history
  • Loading branch information
Terje Wiesener authored and khellang committed Oct 18, 2023
1 parent 15fd55a commit ef96770
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Redskap/RandomExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static RandomRangeEnumerator GetRange(this Random random, Gender gender,
// Adjust to an odd or even seed based on the specified gender:
// - Female is even
// - Male is odd
if (gender == Gender.Male && seed % 2 == 0)
if ((gender == Gender.Male) == (seed % 2 == 0))
{
seed = ++seed % count;
}
Expand Down
18 changes: 18 additions & 0 deletions test/Redskap.Tests/IdentificationNumberTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ public void Full_Roundtrip()
}
}

[Fact]
public void Generate_With_Specification()
{
var gen = new Generator(new Random(123));
var earliest = DateTime.Now.AddYears(-80).Date;
var latest = DateTime.Now.AddYears(0).Date;
foreach (var gender in new[] { Gender.Female, Gender.Male })
{
for (var i = 0; i < 10_000; i++)
{
var generated = gen.Generate(Kind.FNumber, gender, earliest, latest);

Assert.InRange(generated.DateOfBirth, earliest, latest);
Assert.Equal(gender, generated.Gender);
}
}
}

public class TestData
{
private TestData(string value, Gender gender, DateTime dateOfBirth, Kind kind)
Expand Down

0 comments on commit ef96770

Please sign in to comment.