Skip to content

Commit

Permalink
Merge pull request #67 from Cimpress-MCP/master
Browse files Browse the repository at this point in the history
Release fix for long NL postalcodes
  • Loading branch information
mmaruniak authored Dec 7, 2017
2 parents 11e00e3 + 0ca066d commit 7c99322
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,35 @@ namespace PostalCodes.UnitTests.CountrySpecificPostalCodes
internal class NLPostalCodeManualTests
{
[Test]
[TestCase("9992 ZZ", "9991")]
[TestCase("9992 ZZ", "9992ZY")]
[TestCase("9992", "9991")]
[TestCase("1000 ZZ", "0999")]
[TestCase("4000 ZZ", "3999")]
[TestCase("1000", "0999")]
[TestCase("1000 AA", "0999ZZ")]
[TestCase("4000 ZZ", "4000ZY")]
[TestCase("4000", "3999")]
[TestCase("1422", "1421")]
public void Predecessor_ValidInput_ReturnsCorrectPostalCode(string postalCode, string postalCodePredecessor)
{
Assert.AreEqual(postalCodePredecessor, (new NLPostalCode(postalCode)).Predecessor.ToString());
}

[Test]
[TestCase("9992 ZZ", "9993")]
[TestCase("9992", "9993")]
[TestCase("1000 ZZ", "1001")]
[TestCase("4000 ZZ", "4001")]
[TestCase("9992 ZZ", "9993AA")]
[TestCase("9992", "9993")]
[TestCase("1000", "1001")]
[TestCase("1000 ZZ", "1001AA")]
[TestCase("4000", "4001")]
[TestCase("4000 ZZ", "4001AA")]
[TestCase("8999", "9000")]
[TestCase("8999AA", "8999AB")]
public void Successor_ValidInput_ReturnsCorrectPostalCode(string postalCode, string postalCodeSuccessor)
{
Assert.AreEqual(postalCodeSuccessor, (new NLPostalCode(postalCode)).Successor.ToString());
}

[Test]
[TestCase("0000 ZZ")]
[TestCase("0000 AA")]
[TestCase("0000")]
public void Predecessor_FirstInRange_ReturnsNull(string postalCode)
{
Expand Down
17 changes: 13 additions & 4 deletions src/PostalCodes.UnitTests/Generated/NLPostalCodeTests.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ namespace PostalCodes.UnitTests.Generated
internal class NLPostalCodeTests
{

[TestCase("9999ZZ","9998")]
[TestCase("1000AA","0999")]
[TestCase("9999","9998")]
[TestCase("1000","0999")]
[TestCase("9999ZZ","9999ZY")]
[TestCase("1000AA","0999ZZ")]
public void Predecessor_ValidInput_ReturnsCorrectPostalCode(string postalCode, string postalCodePredecessor)
{
var code = new NLPostalCode(postalCode);
Expand All @@ -18,8 +20,10 @@ public void Predecessor_ValidInput_ReturnsCorrectPostalCode(string postalCode, s
Assert.AreEqual(codePredecessor.ToHumanReadableString(), code.Predecessor.ToHumanReadableString());
}

[TestCase("0999ZZ","1000")]
[TestCase("3456JT","3457")]
[TestCase("0999","1000")]
[TestCase("3456","3457")]
[TestCase("0999ZZ","1000AA")]
[TestCase("3456JT","3456JU")]
public void Successor_ValidInput_ReturnsCorrectPostalCode(string postalCode, string postalCodeSuccessor)
{
var code = new NLPostalCode(postalCode);
Expand Down Expand Up @@ -48,6 +52,11 @@ public void InvalidCode_ThrowsArgumentException(string postalCode)
Assert.Throws<ArgumentException>(() => new NLPostalCode(postalCode));
}

[TestCase("1234", "1236")]
[TestCase("1234AA", "1236AA")]
[TestCase("1235", "1237AA")]
[TestCase("1235ZY", "1235ZZ")]
[TestCase("1234ZZ", "1235")]
public void CompareTo_ReturnsExpectedSign(string postalCodeBefore, string postalCodeAfter)
{
var b = new NLPostalCode(postalCodeBefore);
Expand Down
3 changes: 2 additions & 1 deletion src/PostalCodes.UnitTests/PostalCodeFactoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ internal class PostalCodeFactoryTests
[TestCase("GB", "A1 9ZZ", "A19ZZ", "GBPostalCode")] // long
[TestCase("PT", "0042", "0042", "PTPostalCode")]
[TestCase("CA", "A9A9A9", "A9A9A9", "CAPostalCode")]
[TestCase("NL", "0024 ZZ", "0024", "NLPostalCode")]
[TestCase("NL", "0024", "0024", "NLPostalCode")] // short NL
[TestCase("NL", "0024 ZZ", "0024ZZ", "NLPostalCode")] // long NL
[TestCase("MT", "PLA1234", "PLA1234", "MTPostalCode")]
[TestCase("??", "004", "004", "DefaultPostalCode")]
public void CreatePostalCode_ReturnsCorrectObjectType(string country, string postalCode, string normalizedPostalCode, string objectTypeName)
Expand Down
2 changes: 1 addition & 1 deletion src/PostalCodes/Generated/NLPostalCode.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override int GetHashCode ()
RegexShort = new Regex("^[0-9]{4}$", RegexOptions.Compiled),
OutputDefault = "xxxx xx",
OutputShort = "xxxx",
AutoConvertToShort = true,
AutoConvertToShort = false,
ShortExpansionAsLowestInRange = "AA",
ShortExpansionAsHighestInRange = "ZZ",
LeftPaddingCharacter = "0",
Expand Down
23 changes: 17 additions & 6 deletions src/countries/NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"LeftPaddingCharacter" : "0",

"AutoConvertToShort" : "true",
"AutoConvertToShort" : "false",
"ShortExpansionAsLowestInRange" : "AA",
"ShortExpansionAsHighestInRange" : "ZZ"
}
Expand All @@ -26,13 +26,24 @@
"Valid" : ["1235DF", "5983DH"],
"Invalid" : [ "12j4h", "k3j51l" ],
"Predecessor" : {
"9999ZZ" : "9998",
"1000AA" : "0999"
"9999" : "9998",
"1000" : "0999",
"9999ZZ": "9999ZY",
"1000AA": "0999ZZ"
},
"Successor" : {
"0999ZZ" : "1000",
"3456JT" : "3457"
"0999" : "1000",
"3456" : "3457",
"0999ZZ": "1000AA",
"3456JT": "3456JU"
},
"IsBefore" : {}
"IsBefore" : {
"1234": "1236",
"1234AA": "1234AB",
"1235": "1237AA",
"1234AA": "1236AA",
"1235ZY": "1235ZZ",
"1234ZZ": "1235"
}
}
}

0 comments on commit 7c99322

Please sign in to comment.