Skip to content

Commit 575e49a

Browse files
committed
added test
1 parent 8ced7e0 commit 575e49a

7 files changed

Lines changed: 67 additions & 7 deletions

File tree

src/PolylineAlgorithm.Abstraction/PolylineEncoding.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static double Denormalize(int value, ValueType type) {
9595
/// <param name="type">The type of value to validate, such as <see cref="ValueType.Latitude"/> or <see cref="ValueType.Longitude"/>.</param>
9696
/// <returns><see langword="true"/> if the normalized value is within the valid range for the specified value type;
9797
/// otherwise, <see langword="false"/>.</returns>
98-
public static bool ValidateNormalizedValue(int value, ValueType type) => (type, value) switch {
98+
private static bool ValidateNormalizedValue(int value, ValueType type) => (type, value) switch {
9999
(ValueType.Latitude, int normalized) when normalized >= Defaults.Coordinate.Latitude.Normalized.Min && normalized <= Defaults.Coordinate.Latitude.Normalized.Max => true,
100100
(ValueType.Longitude, int normalized) when normalized >= Defaults.Coordinate.Longitude.Normalized.Min && normalized <= Defaults.Coordinate.Longitude.Normalized.Max => true,
101101
_ => false,
@@ -111,7 +111,7 @@ public static double Denormalize(int value, ValueType type) {
111111
/// <param name="type">The type of value to validate, such as latitude or longitude.</param>
112112
/// <returns><see langword="true"/> if the <paramref name="value"/> is within the valid range for the specified <paramref
113113
/// name="type"/>; otherwise, <see langword="false"/>.</returns>
114-
public static bool ValidateDenormalizedValue(double value, ValueType type) => (type, value) switch {
114+
private static bool ValidateDenormalizedValue(double value, ValueType type) => (type, value) switch {
115115
(ValueType.Latitude, double denormalized) when denormalized >= Defaults.Coordinate.Latitude.Min && denormalized <= Defaults.Coordinate.Latitude.Max => true,
116116
(ValueType.Longitude, double denormalized) when denormalized >= Defaults.Coordinate.Longitude.Min && denormalized <= Defaults.Coordinate.Longitude.Max => true,
117117
_ => false,

src/PolylineAlgorithm/Polyline.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public override string ToString() {
7575
return string.Empty;
7676
}
7777

78-
return Value.ToString() ?? string.Empty;
78+
return Value.ToString();
7979
}
8080

8181
/// <summary>

tests/PolylineAlgorithm.Abstraction.Tests/PolylineDecoderTest.cs renamed to tests/PolylineAlgorithm.Abstraction.Tests/AbstractPolylineDecoderTest.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System;
77

88
[TestClass]
9-
public class PolylineDecoderTest {
9+
public class AbstractPolylineDecoderTest {
1010
private static readonly PolylineDecoder _decoder = new PolylineDecoder();
1111

1212
public static IEnumerable<object[]> CoordinateCount => [[1], [10], [100], [1_000]];
@@ -28,7 +28,7 @@ public void Constructor_Parameterless_Ok() {
2828
}
2929

3030
[TestMethod]
31-
public void Constructor_ValidOptions_Ok() {
31+
public void Constructor_Options_Instance_Ok() {
3232
// Arrange
3333
var options = new PolylineEncodingOptions();
3434

@@ -40,6 +40,19 @@ public void Constructor_ValidOptions_Ok() {
4040
Assert.AreSame(options, decoder.Options);
4141
}
4242

43+
[TestMethod]
44+
public void Constructor_Null_Options_Throws_ArgumentNullException() {
45+
// Arrange
46+
void New() => new PolylineDecoder(null!);
47+
48+
// Act
49+
var exception = Assert.ThrowsExactly<ArgumentNullException>(New);
50+
51+
// Assert
52+
Assert.AreEqual("options", exception.ParamName);
53+
Assert.IsFalse(string.IsNullOrWhiteSpace(exception.Message));
54+
}
55+
4356
[TestMethod]
4457
public void Decode_NullPolyline_Throws_ArgumentException() {
4558
// Arrange

tests/PolylineAlgorithm.Abstraction.Tests/PolylineEncoderTest.cs renamed to tests/PolylineAlgorithm.Abstraction.Tests/AbstractPolylineEncoderTest.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System;
66

77
[TestClass]
8-
public class PolylineEncoderTest {
8+
public class AbstractPolylineEncoderTest {
99
private static readonly PolylineEncoder _encoder = new PolylineEncoder();
1010

1111
public static IEnumerable<object[]> CoordinateCount => [[1], [10], [100], [1_000]];
@@ -38,6 +38,20 @@ public void Constructor_ValidOptions_Ok() {
3838
Assert.AreSame(options, encoder.Options);
3939
}
4040

41+
42+
[TestMethod]
43+
public void Constructor_Null_Options_Throws_ArgumentNullException() {
44+
// Arrange
45+
void New() => new PolylineEncoder(null!);
46+
47+
// Act
48+
var exception = Assert.ThrowsExactly<ArgumentNullException>(New);
49+
50+
// Assert
51+
Assert.AreEqual("options", exception.ParamName);
52+
Assert.IsFalse(string.IsNullOrWhiteSpace(exception.Message));
53+
}
54+
4155
[TestMethod]
4256
public void Encode_NullCoordinates_Throws_ArgumentException() {
4357
// Arrange

tests/PolylineAlgorithm.Abstraction.Tests/PolylineEncodingOptionsTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Microsoft.Extensions.Logging;
44
using Microsoft.Extensions.Logging.Abstractions;
55
using Microsoft.Extensions.Logging.Testing;
6-
using static PolylineAlgorithm.Abstraction.Tests.PolylineEncoderTest;
6+
using static PolylineAlgorithm.Abstraction.Tests.AbstractPolylineEncoderTest;
77

88
[TestClass]
99
public class PolylineEncodingOptionsTest {

tests/PolylineAlgorithm.Abstraction.Tests/PolylineOptionsBuilderTest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ public void Build_Returns_Instance_With_Default_Values() {
3232
Assert.AreEqual(loggerFactory, options.LoggerFactory);
3333
}
3434

35+
[TestMethod]
36+
public void WithBufferSize_Small_BufferSize_Parameter_Returns_Throws_ArgumentOutOfRangeException() {
37+
// Arrange
38+
void WithSmallBufferSize() => PolylineEncodingOptionsBuilder.Create()
39+
.WithBufferSize(11);
40+
41+
// Act
42+
var exception = Assert.ThrowsException<ArgumentOutOfRangeException>(WithSmallBufferSize);
43+
44+
// Assert
45+
Assert.IsNotNull(exception);
46+
Assert.AreEqual("maxBufferSize", exception.ParamName);
47+
Assert.IsTrue(exception.Message.Contains("Buffer size must be greater than 11."));
48+
}
49+
3550
[TestMethod]
3651
public void Build_Returns_Instance_With_Expected_Buffer_Size() {
3752
// Arrange
@@ -64,4 +79,19 @@ public void Build_Returns_Instance_With_Expected_LoggerFactory() {
6479
Assert.IsNotNull(options);
6580
Assert.AreEqual(expected, options.LoggerFactory);
6681
}
82+
83+
[TestMethod]
84+
public void WithLoggerFactory_Null_Parameter_Returns_Throws_ArgumentNullException() {
85+
// Arrange
86+
void WithNullLoggerFactory() => PolylineEncodingOptionsBuilder.Create()
87+
.WithLoggerFactory(null!);
88+
89+
// Act
90+
var exception = Assert.ThrowsException<ArgumentNullException>(WithNullLoggerFactory);
91+
92+
// Assert
93+
Assert.IsNotNull(exception);
94+
Assert.AreEqual("loggerFactory", exception.ParamName);
95+
Assert.IsTrue(exception.Message.Contains("Logger factory cannot be null."));
96+
}
6797
}

tests/PolylineAlgorithm.Tests/PolylineTest.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ public void Equality_Operators_Correct_Results() {
254254
Polyline polyline = Polyline.FromString(nameof(polyline));
255255
Polyline equal = Polyline.FromString(nameof(polyline));
256256
Polyline notEqual = Polyline.FromString(nameof(notEqual));
257+
Polyline empty = new Polyline();
257258
string typeNotEqual = "not a polyline";
258259

259260
// Act && Assert
@@ -266,6 +267,8 @@ public void Equality_Operators_Correct_Results() {
266267
Assert.IsTrue(polyline.Equals(equal));
267268
Assert.IsTrue(polyline.Equals((object)equal));
268269

270+
Assert.IsFalse(polyline.Equals(empty));
271+
Assert.IsFalse(polyline.Equals(notEqual));
269272
Assert.IsFalse(polyline.Equals((object)notEqual));
270273
Assert.IsFalse(polyline.Equals(typeNotEqual));
271274
}

0 commit comments

Comments
 (0)