Skip to content

Commit 3ee415b

Browse files
committed
polyline decoder extesnsion tests
1 parent 6e48d25 commit 3ee415b

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

src/PolylineAlgorithm/Extensions/PolylineDecoderExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,12 @@ public static IEnumerable<Coordinate> Decode(this IPolylineDecoder<Polyline, Coo
5858

5959
return decoder.Decode(Polyline.FromCharArray(polyline));
6060
}
61+
62+
public static IEnumerable<Coordinate> Decode(this IPolylineDecoder<Polyline, Coordinate> decoder, ReadOnlyMemory<char> polyline) {
63+
if (decoder is null) {
64+
throw new ArgumentNullException(nameof(decoder));
65+
}
66+
67+
return decoder.Decode(Polyline.FromMemory(polyline));
68+
}
6169
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 PolylineDecoderExtensionsTest {
10+
private readonly PolylineDecoder decoder = new PolylineDecoder();
11+
12+
public static IEnumerable<object[]> CoordinateCount => [[1], [10], [100], [1_000]];
13+
14+
[TestMethod]
15+
[DynamicData(nameof(CoordinateCount), DynamicDataSourceType.Property)]
16+
public void Decode_String_Returns_Expected_Coordinates(int count) {
17+
// Arrange
18+
var polyline = RandomValueProvider.GetPolyline(count);
19+
var expected = RandomValueProvider.GetCoordinates(count)
20+
.Select(c => new Coordinate(c.Latitude, c.Longitude))
21+
.ToList();
22+
23+
// Act
24+
var result = PolylineDecoderExtensions.Decode(decoder, polyline).ToList();
25+
26+
// Assert
27+
CollectionAssert.AreEqual(expected, result);
28+
}
29+
30+
[TestMethod]
31+
[DynamicData(nameof(CoordinateCount), DynamicDataSourceType.Property)]
32+
public void Decode_CharArray_Returns_Expected_Coordinates(int count) {
33+
// Arrange
34+
var polyline = RandomValueProvider.GetPolyline(count).ToCharArray();
35+
var expected = RandomValueProvider.GetCoordinates(count)
36+
.Select(c => new Coordinate(c.Latitude, c.Longitude))
37+
.ToList();
38+
39+
// Act
40+
var result = PolylineDecoderExtensions.Decode(decoder, polyline).ToList();
41+
42+
// Assert
43+
CollectionAssert.AreEqual(expected, result);
44+
}
45+
46+
[TestMethod]
47+
[DynamicData(nameof(CoordinateCount), DynamicDataSourceType.Property)]
48+
public void Decode_Memory_Returns_Expected_Coordinates(int count) {
49+
// Arrange
50+
var polyline = RandomValueProvider.GetPolyline(count).AsMemory();
51+
var expected = RandomValueProvider.GetCoordinates(count)
52+
.Select(c => new Coordinate(c.Latitude, c.Longitude))
53+
.ToList();
54+
55+
// Act
56+
var result = PolylineDecoderExtensions.Decode(decoder, polyline).ToList();
57+
58+
// Assert
59+
CollectionAssert.AreEqual(expected, result);
60+
}
61+
62+
}

0 commit comments

Comments
 (0)