Skip to content

Commit 51ce6c6

Browse files
author
Petr Sramek
committed
zxczda
1 parent ca473d0 commit 51ce6c6

File tree

4 files changed

+82
-18
lines changed

4 files changed

+82
-18
lines changed

src/PolylineAlgorithm/Validation/CoordinateValidator.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ namespace PolylineAlgorithm.Validation;
1313
/// <param name="latitudeRange">A latitude range.</param>
1414
/// <param name="longitudeRange">A longitude range.</param>
1515
public sealed class CoordinateValidator(CoordinateRange latitudeRange, CoordinateRange longitudeRange) : ICoordinateValidator {
16-
///// <summary>
17-
///// Represents default coordinate validator. This field is read-only.
18-
///// </summary>
19-
///// <remarks>Validates latitude between -90 and 90; longitude between -180 and 180.</remarks>
20-
//[SuppressMessage("Usage", "CA2211:Non-constant fields should not be visible", Justification = "We want to expose default instance of .")]
21-
2216
/// <summary>
2317
/// A latitude validation range.
2418
/// </summary>

tests/PolylineAlgorithm.Tests/PolylineAlgorithm.Tests.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,4 @@
3434
<ProjectReference Include="..\..\src\PolylineAlgorithm\PolylineAlgorithm.csproj" />
3535
</ItemGroup>
3636

37-
<ItemGroup>
38-
<Folder Include="Validation\" />
39-
</ItemGroup>
40-
4137
</Project>

tests/PolylineAlgorithm.Tests/Validation/CoordinateRangeTest.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace PolylineAlgorithm.Tests;
1212
/// </summary>
1313
[TestClass]
1414
public class CoordinateRangeTest {
15-
public static IEnumerable<object[]> Consructor_Valid_Parameters => [
15+
public static IEnumerable<object[]> Constructor_Valid_Parameters => [
1616
[ -90, 90 ],
1717
[ -180, 180 ],
1818
];
@@ -37,7 +37,7 @@ public void Constructor_Parameterless_Ok() {
3737
}
3838

3939
[TestMethod]
40-
[DynamicData(nameof(Consructor_Valid_Parameters))]
40+
[DynamicData(nameof(Constructor_Valid_Parameters))]
4141
public void Constructor_Valid_Parameters_Ok(double min, double max) {
4242
// Arrange
4343
double belowMax = max - 1;
@@ -46,14 +46,13 @@ public void Constructor_Valid_Parameters_Ok(double min, double max) {
4646
double equalMin = min;
4747
double aboveMax = max + 1;
4848
double aboveMin = min + 1;
49-
5049

5150
// Act
5251
CoordinateRange range = new(min, max);
5352

5453
// Assert
55-
Assert.IsTrue(range.IsInRange(aboveMin));
5654
Assert.IsTrue(range.IsInRange(equalMin));
55+
Assert.IsTrue(range.IsInRange(aboveMin));
5756
Assert.IsTrue(range.IsInRange(equalMax));
5857
Assert.IsTrue(range.IsInRange(belowMax));
5958

@@ -67,20 +66,18 @@ public void Constructor_Invalid_Min_Parameter_ArgumentOutOfRangeException() {
6766
double min = 0;
6867
double max = 0;
6968

70-
7169
// Act
7270
void New(double min, double max) {
7371
CoordinateRange range = new(min, max);
7472

7573
}
7674

77-
7875
// Assert
7976
Assert.ThrowsException<ArgumentOutOfRangeException>(() => New(min, max));
8077
}
8178

8279
[TestMethod]
83-
[DynamicData(nameof(Consructor_Valid_Parameters))]
80+
[DynamicData(nameof(Constructor_Valid_Parameters))]
8481
public void Equals_CoordinateRange_True(double min, double max) {
8582
// Arrange
8683
CoordinateRange @this = new(min, max);
@@ -94,7 +91,7 @@ public void Equals_CoordinateRange_True(double min, double max) {
9491
}
9592

9693
[TestMethod]
97-
[DynamicData(nameof(Consructor_Valid_Parameters))]
94+
[DynamicData(nameof(Constructor_Valid_Parameters))]
9895
public void Equals_CoordinateRange_False(double min, double max) {
9996
// Arrange
10097
Coordinate @this = new(min, max);
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//
2+
// Copyright (c) Pete Sramek. All rights reserved.
3+
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace PolylineAlgorithm.Tests;
7+
8+
using PolylineAlgorithm.Validation;
9+
10+
/// <summary>
11+
/// Tests <see cref="Polyline"/> type.
12+
/// </summary>
13+
[TestClass]
14+
public class CoordinateValidatorTest {
15+
private static readonly CoordinateRange _latitude = new(-90, 90);
16+
private static readonly CoordinateRange _longitude = new(-180, 180);
17+
18+
public static IEnumerable<object[]> IsValid_Method_Parameters => [
19+
[ 0, 0, true ],
20+
[ _latitude.Min, _longitude.Max, true ],
21+
[ _latitude.Min - 1, _longitude.Max, false ],
22+
[ _latitude.Min, _longitude.Max + 1, false ],
23+
[ _latitude.Min - 1, _longitude.Max + 1, false ]
24+
];
25+
26+
[TestMethod]
27+
[DynamicData(nameof(IsValid_Method_Parameters))]
28+
public void IsValid_Valid_Parameters_Ok(double latitude, double longitude, bool expected) {
29+
// Arrange
30+
Coordinate coordinate = new(latitude, longitude);
31+
CoordinateValidator validator = new(_latitude, _longitude);
32+
33+
// Act
34+
bool result = validator.IsValid(coordinate);
35+
36+
// Assert
37+
Assert.AreEqual(expected, result);
38+
}
39+
40+
[TestMethod]
41+
public void Constructor_Invalid_Min_Parameter_ArgumentOutOfRangeException() {
42+
// Arrange
43+
double min = 0;
44+
double max = 0;
45+
46+
// Act
47+
void New(double min, double max) {
48+
CoordinateRange range = new(min, max);
49+
50+
}
51+
52+
// Assert
53+
Assert.ThrowsException<ArgumentOutOfRangeException>(() => New(min, max));
54+
}
55+
56+
[TestMethod]
57+
public void SetDefault_Validator_Ok() {
58+
// Arrange
59+
CoordinateRange range = new(double.MinValue, double.MaxValue);
60+
CoordinateValidator validator = new(range, range);
61+
62+
// Act
63+
ICoordinateValidator original = ICoordinateValidator.Default;
64+
65+
ICoordinateValidator
66+
.SetDefault(validator);
67+
68+
ICoordinateValidator @new = ICoordinateValidator.Default;
69+
70+
ICoordinateValidator
71+
.SetDefault(original);
72+
73+
// Assert
74+
Assert.AreEqual(validator, @new);
75+
Assert.AreNotEqual(original, @new);
76+
}
77+
}

0 commit comments

Comments
 (0)