Skip to content

Commit 95537cd

Browse files
committed
additional extension tests
1 parent d454a7e commit 95537cd

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
namespace PolylineAlgorithm.Tests;
2+
3+
using PolylineAlgorithm.Extensions;
4+
using PolylineAlgorithm.Utility;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
8+
[TestClass]
9+
public class PolylineEncoderExtensionsTest {
10+
private readonly PolylineEncoder Encoder = new PolylineEncoder();
11+
12+
public static IEnumerable<object[]> CoordinateCount => [[1], [10], [100], [1_000]];
13+
14+
[TestMethod]
15+
public void Encode_Null_Encoder_Empty_List_Throws_ArgumentNullException() {
16+
// Arrange
17+
void Encode() => PolylineEncoderExtensions.Encode(null!, new List<Coordinate>());
18+
19+
// Act
20+
var exception = Assert.ThrowsExactly<ArgumentNullException>(Encode);
21+
22+
// Assert
23+
Assert.AreEqual("encoder", exception.ParamName);
24+
Assert.IsTrue(exception.Message.Contains("Value cannot be null.", StringComparison.Ordinal));
25+
}
26+
27+
[TestMethod]
28+
public void Encode_Null_Encoder_Null_CharArray_Throws_ArgumentNullException() {
29+
// Arrange
30+
void Encode() => PolylineEncoderExtensions.Encode(null!, new Coordinate[0]);
31+
32+
// Act
33+
var exception = Assert.ThrowsExactly<ArgumentNullException>(Encode);
34+
35+
// Assert
36+
Assert.AreEqual("encoder", exception.ParamName);
37+
Assert.IsTrue(exception.Message.Contains("Value cannot be null.", StringComparison.Ordinal));
38+
}
39+
40+
[TestMethod]
41+
[DynamicData(nameof(CoordinateCount), DynamicDataSourceType.Property)]
42+
public void Encode_List_Returns_Expected_Coordinates(int count) {
43+
// Arrange
44+
var coordinates = RandomValueProvider.GetCoordinates(count)
45+
.Select(c => new Coordinate(c.Latitude, c.Longitude))
46+
.ToList();
47+
var expected = RandomValueProvider.GetPolyline(count);
48+
49+
// Act
50+
var result = PolylineEncoderExtensions.Encode(Encoder, coordinates);
51+
52+
// Assert
53+
Assert.AreEqual(expected, result.ToString());
54+
}
55+
56+
[TestMethod]
57+
[DynamicData(nameof(CoordinateCount), DynamicDataSourceType.Property)]
58+
public void Encode_Array_Returns_Expected_Coordinates(int count) {
59+
// Arrange
60+
var coordinates = RandomValueProvider.GetCoordinates(count)
61+
.Select(c => new Coordinate(c.Latitude, c.Longitude))
62+
.ToArray();
63+
var expected = RandomValueProvider.GetPolyline(count);
64+
65+
// Act
66+
var result = PolylineEncoderExtensions.Encode(Encoder, coordinates);
67+
68+
// Assert
69+
Assert.AreEqual(expected, result.ToString());
70+
}
71+
72+
}

0 commit comments

Comments
 (0)