Skip to content

Commit 621d9be

Browse files
committed
updated tests
1 parent 9541f03 commit 621d9be

6 files changed

Lines changed: 73 additions & 14 deletions

File tree

tests/PolylineAlgorithm.Abstraction.Tests/InvalidPolylineExceptionTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ public void Throw_Method_Invalid_Coordinate_Parameter_PolylineMalformedException
2121
var position = Random.Shared.Next();
2222
static void ThrowAt(int position) => InvalidPolylineException.Throw(position);
2323

24-
// Act && Assert
24+
// Act
2525
var exception = Assert.ThrowsExactly<InvalidPolylineException>(() => ThrowAt(position));
26+
27+
// Assert
2628
Assert.IsFalse(string.IsNullOrWhiteSpace(exception.Message));
2729
Assert.IsTrue(exception.Message.Contains(position.ToString()));
2830
}

tests/PolylineAlgorithm.Abstraction.Tests/PolylineAlgorithm.Abstraction.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
<ItemGroup>
4242
<ProjectReference Include="..\..\src\PolylineAlgorithm.Abstraction\PolylineAlgorithm.Abstraction.csproj" />
43+
<ProjectReference Include="..\..\utilities\PolylineAlgorithm.Utility\PolylineAlgorithm.Utility.csproj" />
4344
</ItemGroup>
4445

4546
</Project>

tests/PolylineAlgorithm.Abstraction.Tests/PolylineEncoderTest.cs

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,73 @@
11
namespace PolylineAlgorithm.Abstraction.Tests;
22

3-
using Microsoft.Extensions.Logging;
4-
using Microsoft.Extensions.Logging.Testing;
53
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using PolylineAlgorithm.Utility;
65
using System;
76

87
[TestClass]
98
public class PolylineEncoderTest {
10-
internal static readonly FakeLoggerProvider loggerProvider = new();
9+
private static readonly PolylineEncoder _encoder = new PolylineEncoder();
10+
11+
public static IEnumerable<object[]> CoordinateCount => [[1], [10], [100], [1_000]];
12+
13+
[TestMethod]
14+
public void Encode_NullCoordinates_Throws_ArgumentException() {
15+
// Arrange
16+
void Encode() => _encoder.Encode(null!);
17+
18+
// Act
19+
var exception = Assert.ThrowsExactly<ArgumentNullException>(Encode);
20+
21+
// Assert
22+
Assert.AreEqual("coordinates", exception.ParamName);
23+
Assert.IsFalse(string.IsNullOrWhiteSpace(exception.Message));
24+
}
25+
26+
[TestMethod]
27+
public void Encode_EmptyCoordinates_Throws_ArgumentException() {
28+
// Arrange
29+
void Encode() => _encoder.Encode(Array.Empty<(double Latitude, double Longitude)>());
30+
31+
// Act
32+
var exception = Assert.ThrowsExactly<ArgumentException>(Encode);
33+
34+
// Assert
35+
Assert.AreEqual("coordinates", exception.ParamName);
36+
Assert.IsFalse(string.IsNullOrWhiteSpace(exception.Message));
37+
}
1138

1239
[TestMethod]
13-
public void TestEncodeEmptyCollection() {
14-
var encoder = new PolylineEncoder(new() { LoggerFactory = new FakeLoggerFactory(loggerProvider) });
15-
void Encode() => encoder.Encode(Array.Empty<(double Latitude, double Longitude)>());
16-
var exception = Assert.ThrowsExactly<ArgumentException>(Encode, "The input collection cannot be empty.");
17-
///loggerProvider.Collector.LatestRecord,(exception, LogLevel.Error, "Argument cannot be empty enumeration");
40+
[DynamicData(nameof(CoordinateCount))]
41+
public void Encode_RandomValue_ValidInput_Ok(int count) {
42+
// Arrange
43+
IEnumerable<(double Latitude, double Longitude)> coordinates = RandomValueProvider.GetCoordinates(count);
44+
string expected = RandomValueProvider.GetPolyline(count);
45+
46+
// Act
47+
var result = _encoder.Encode(coordinates);
48+
49+
// Assert
50+
Assert.AreEqual(expected.Length, result.Length);
51+
Assert.IsTrue(expected.Equals(result));
52+
}
53+
54+
[TestMethod]
55+
public void Encode_StaticValue_ValidInput_Ok() {
56+
// Arrange
57+
IEnumerable<(double Latitude, double Longitude)> coordinates = StaticValueProvider.GetCoordinates();
58+
string expected = StaticValueProvider.GetPolyline();
59+
60+
// Act
61+
var result = _encoder.Encode(coordinates);
62+
63+
// Assert
64+
Assert.AreEqual(expected.Length, result.Length);
65+
Assert.IsTrue(expected.Equals(result));
1866
}
1967

2068
public class PolylineEncoder : PolylineEncoder<(double Latitude, double Longitude), string> {
21-
public PolylineEncoder(PolylineEncodingOptions options) : base(options) { }
69+
public PolylineEncoder()
70+
: base(new()) { }
2271

2372
protected override string CreatePolyline(ReadOnlyMemory<char> polyline) => polyline.ToString();
2473
protected override double GetLatitude((double Latitude, double Longitude) coordinate) => coordinate.Latitude;

tests/PolylineAlgorithm.Abstraction.Tests/PolylineEncodingTest.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,10 @@ public void Normalize_Throws_ArgumentOutOfRangeException(double value, PolylineE
227227
// Arrange
228228
static int Normalize(double value, PolylineEncoding.ValueType type) => PolylineEncoding.Normalize(value, type);
229229

230-
// Act & Assert
230+
// Act
231231
var exception = Assert.ThrowsExactly<ArgumentOutOfRangeException>(() => Normalize(value, type));
232+
233+
// Assert
232234
Assert.IsFalse(string.IsNullOrWhiteSpace(exception.Message));
233235
}
234236

@@ -238,8 +240,10 @@ public void Denormalize_Throws_ArgumentOutOfRangeException(int value, PolylineEn
238240
// Arrange
239241
static double Denormalize(int value, PolylineEncoding.ValueType type) => PolylineEncoding.Denormalize(value, type);
240242

241-
// Act & Assert
243+
// Act
242244
var exception = Assert.ThrowsExactly<ArgumentOutOfRangeException>(() => Denormalize(value, type));
245+
246+
// Assert
243247
Assert.IsFalse(string.IsNullOrWhiteSpace(exception.Message));
244248
}
245249

tests/PolylineAlgorithm.Tests/PolylineEncoderTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void Encode_EmptyInput_ThrowsException() {
5757
/// <remarks>Expected result is that the encoded polyline matches <see cref="Values.Polyline.Valid"/>.</remarks>
5858
[TestMethod]
5959
[DynamicData(nameof(CoordinateCount))]
60-
public void Random_Value_Encode_ValidInput_Ok(int count) {
60+
public void Encode_RandomValue_ValidInput_Ok(int count) {
6161
// Arrange
6262
IEnumerable<Coordinate> valid = RandomValueProvider.GetCoordinates(count).Select(c => new Coordinate(c.Latitude, c.Longitude));
6363
Polyline expected = Polyline.FromString(RandomValueProvider.GetPolyline(count));
@@ -76,7 +76,7 @@ public void Random_Value_Encode_ValidInput_Ok(int count) {
7676
/// </summary>
7777
/// <remarks>Expected result is that the encoded polyline matches <see cref="Values.Polyline.Valid"/>.</remarks>
7878
[TestMethod]
79-
public void Static_Value_Encode_ValidInput_Ok() {
79+
public void Encode_StaticValue_ValidInput_Ok() {
8080
// Arrange
8181
IEnumerable<Coordinate> valid = StaticValueProvider.GetCoordinates().Select(c => new Coordinate(c.Latitude, c.Longitude));
8282
Polyline expected = Polyline.FromString(StaticValueProvider.GetPolyline());

utilities/PolylineAlgorithm.Utility/PolylineAlgorithm.Utility.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
2828
<_Parameter1>PolylineAlgorithm.Tests</_Parameter1>
2929
</AssemblyAttribute>
30+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
31+
<_Parameter1>PolylineAlgorithm.Abstraction.Tests</_Parameter1>
32+
</AssemblyAttribute>
3033
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
3134
<_Parameter1>PolylineAlgorithm.Benchmarks</_Parameter1>
3235
</AssemblyAttribute>

0 commit comments

Comments
 (0)