Skip to content

Commit 185b3e1

Browse files
authored
Merge pull request #64 from Cimpress-MCP/us-auto-shorten
Do not auto-shorten US as well
2 parents 117ad94 + 17921bf commit 185b3e1

File tree

7 files changed

+436
-19
lines changed

7 files changed

+436
-19
lines changed

.nuget/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="EWSoftware.SHFB" version="2014.11.22.0" />
4-
<package id="NUnit.Runners" version="2.6.4" />
53
<package id="coveralls.net" version="0.5.0" />
4+
<package id="EWSoftware.SHFB" version="2014.11.22.0" />
5+
<package id="NUnit.Runners" version="2.6.4" />
66
<package id="OpenCover" version="4.5.3723" />
77
</packages>

src/PostalCodes.UnitTests/Generated/USPostalCodeTests.gen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal class USPostalCodeTests
88
{
99

1010
[TestCase("12346","12345")]
11-
[TestCase("12346-1234","12345")]
11+
[TestCase("12346-1234","12346-1233")]
1212
public void Predecessor_ValidInput_ReturnsCorrectPostalCode(string postalCode, string postalCodePredecessor)
1313
{
1414
var code = new USPostalCode(postalCode);
@@ -19,7 +19,7 @@ public void Predecessor_ValidInput_ReturnsCorrectPostalCode(string postalCode, s
1919
}
2020

2121
[TestCase("12346","12347")]
22-
[TestCase("12346-1234","12347")]
22+
[TestCase("12346-1234","12346-1235")]
2323
public void Successor_ValidInput_ReturnsCorrectPostalCode(string postalCode, string postalCodeSuccessor)
2424
{
2525
var code = new USPostalCode(postalCode);

src/PostalCodes.UnitTests/PostalCodeRangeTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,15 @@ public static IEnumerable<ITestCaseData> Contains_WithPostalCode_TestCases
222222
{
223223
get
224224
{
225-
var rangeUS = MakeRangeUS("28000 0000", "28000 9999");
226-
yield return new TestCaseData(rangeUS, new USPostalCode("28000")).Returns(true);
227-
yield return new TestCaseData(rangeUS, new USPostalCode("28000 1235")).Returns(true);
225+
var rangeUS1 = MakeRangeUS("28000 0000", "28000 9999");
226+
var rangeUS2 = MakeRangeUS("28000", "28000");
227+
var rangeUS3 = MakeRangeUS("28000", "29000");
228+
yield return new TestCaseData(rangeUS1, new USPostalCode("28000")).Returns(true);
229+
yield return new TestCaseData(rangeUS1, new USPostalCode("28000 1235")).Returns(true);
230+
yield return new TestCaseData(rangeUS2, new USPostalCode("28000")).Returns(true);
231+
yield return new TestCaseData(rangeUS2, new USPostalCode("28000 1235")).Returns(true);
232+
yield return new TestCaseData(rangeUS3, new USPostalCode("28000")).Returns(true);
233+
yield return new TestCaseData(rangeUS3, new USPostalCode("28000 1235")).Returns(true);
228234
}
229235
}
230236

src/PostalCodes/Generated/USPostalCode.gen.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public override int GetHashCode ()
4040
RegexShort = new Regex("^[0-9]{5}$", RegexOptions.Compiled),
4141
OutputDefault = "xxxxx-xxxx",
4242
OutputShort = "xxxxx",
43-
AutoConvertToShort = true,
43+
AutoConvertToShort = false,
4444
ShortExpansionAsLowestInRange = "0000",
4545
ShortExpansionAsHighestInRange = "9999",
4646
LeftPaddingCharacter = "0",

src/PostalCodes/PostalCodeRange.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ public class PostalCodeRange : IEquatable<PostalCodeRange>, IComparable<PostalCo
1212
/// The lazy default
1313
/// </summary>
1414
private static readonly Lazy<PostalCodeRange> LazyDefault = new Lazy<PostalCodeRange>(() => new PostalCodeRange(null, null));
15-
15+
16+
private PostalCode _start;
17+
private PostalCode _end;
18+
1619
/// <summary>
1720
/// Gets the default.
1821
/// </summary>
@@ -43,8 +46,8 @@ public PostalCodeRange(PostalCode start, PostalCode end)
4346
"PostalCodeRange end ({0}) can't be before start ({1})", end, start));
4447
}
4548

46-
Start = start != null ? start.ExpandPostalCodeAsLowestInRange() : start;
47-
End = end != null ? end.ExpandPostalCodeAsHighestInRange() : end;
49+
_start = start != null ? start.ExpandPostalCodeAsLowestInRange() : null;
50+
_end = end != null ? end.ExpandPostalCodeAsHighestInRange() : null;
4851
}
4952

5053
/// <summary>
@@ -69,13 +72,21 @@ public bool IsDefault
6972
/// Gets the start.
7073
/// </summary>
7174
/// <value>The start.</value>
72-
public PostalCode Start { get; private set; }
75+
public PostalCode Start
76+
{
77+
get { return _start; }
78+
set { _start = value != null ? value.ExpandPostalCodeAsLowestInRange() : null; }
79+
}
7380

7481
/// <summary>
7582
/// Gets the end.
7683
/// </summary>
7784
/// <value>The end.</value>
78-
public PostalCode End { get; private set; }
85+
public PostalCode End
86+
{
87+
get { return _end; }
88+
set { _end = value != null ? value.ExpandPostalCodeAsHighestInRange() : null; }
89+
}
7990

8091
/// <summary>
8192
/// Gets the predecessor postal code.
@@ -346,8 +357,9 @@ public static bool Contains(PostalCodeRange range, PostalCode specificCode)
346357
{
347358
return false;
348359
}
349-
return range.IsDefault
350-
|| ((range.Start <= specificCode) && (specificCode <= range.End));
360+
361+
return range.IsDefault ||
362+
((range.Start <= specificCode.ExpandPostalCodeAsLowestInRange()) && (specificCode.ExpandPostalCodeAsHighestInRange() <= range.End));
351363
}
352364

353365
/// <summary>

0 commit comments

Comments
 (0)