Skip to content

Commit 3c21c0e

Browse files
Fix for issue #534: Gender-digit is incorrect for Swedish Personnummer generation (#535)
* Corrected gender handling in Swedish Personnummer Second last digit should be even for Female Second last digit should be odd for Male * Reverted change in comment
1 parent 55bde49 commit 3c21c0e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Source/Bogus.Tests/ExtensionTests/SwedishExtensionTest.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void samordningsnummer_should_contain_offset_date_of_birth()
6060
[Theory]
6161
[InlineData(false)]
6262
[InlineData(true)]
63-
public void when_person_is_male_second_last_number_is_even(bool isSamordningsnummer)
63+
public void when_person_is_male_second_last_number_is_odd(bool isSamordningsnummer)
6464
{
6565
var f = new Faker("sv");
6666
var person = f.Person;
@@ -71,15 +71,15 @@ public void when_person_is_male_second_last_number_is_even(bool isSamordningsnum
7171
var secondLast = int.Parse(identificationNumber.Substring(identificationNumber.Length - 2, 1));
7272

7373
secondLast.Should()
74-
.Match(x => x % 2 == 0)
74+
.Match(x => x % 2 == 1)
7575
.And.BeLessThan(10)
7676
.And.BeGreaterThan(0);
7777
}
7878

7979
[Theory]
8080
[InlineData(false)]
8181
[InlineData(true)]
82-
public void when_person_is_female_second_last_number_is_odd(bool isSamordningsnummer)
82+
public void when_person_is_female_second_last_number_is_even(bool isSamordningsnummer)
8383
{
8484
var f = new Faker("sv");
8585
var person = f.Person;
@@ -90,7 +90,7 @@ public void when_person_is_female_second_last_number_is_odd(bool isSamordningsnu
9090
var secondLast = int.Parse(identificationNumber.Substring(identificationNumber.Length - 2, 1));
9191

9292
secondLast.Should()
93-
.Match(x => x % 2 == 1)
93+
.Match(x => x % 2 == 0)
9494
.And.BeLessThan(10)
9595
.And.BeGreaterThan(0);
9696
}

Source/Bogus/Extensions/Sweden/ExtensionsForSweden.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static string Personnummer(this Person person)
4848
/// </summary>
4949
/// <remarks>
5050
/// Coordination numbers enable Swedish public authorities and other organizations with a public function
51-
/// to identify people who are not currently – and have never been – registered at an address in Sweden.
51+
/// to identify people who are not currently – and have never been – registered at an address in Sweden.
5252
/// </remarks>
5353
public static string Samordningsnummer(this Person person)
5454
{
@@ -90,9 +90,9 @@ private static string GenerateIndividualNumber(Randomizer r, Gender gender, Date
9090
private static int GetGenderNumber(Randomizer r, Gender gender)
9191
{
9292
if( gender is Gender.Male )
93-
return r.Even(1, 9);
94-
if( gender is Gender.Female )
9593
return r.Odd(1, 9);
94+
if( gender is Gender.Female )
95+
return r.Even(1, 9);
9696
throw new ArgumentOutOfRangeException(nameof(gender), gender, "Gender not handled.");
9797
}
9898

0 commit comments

Comments
 (0)