Skip to content

Commit ea21f2c

Browse files
committed
rerafcct
1 parent ad2fd94 commit ea21f2c

14 files changed

+57
-43
lines changed

src/PolylineAlgorithm/Internal/Defaults.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ internal static class Polyline {
117117
/// Contains constants related to the polyline blocks.
118118
/// </summary>
119119
internal static class Block {
120-
/// <summary>
121-
/// An array of delimiter byte values used in polyline encoding, derived by adding the ASCII value of the question mark ('?') to a range of integers.
122-
/// </summary>
123-
internal static readonly byte[] Delimiters = [.. Enumerable.Range(0, 32).Select(n => (byte)(n + Algorithm.QuestionMark))];
124-
125120
/// <summary>
126121
/// Contains constants related to the length of encoded coordinates in polyline encoding.
127122
/// </summary>

tests/PolylineAlgorithm.Tests/AbstractPolylineDecoderTest.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace PolylineAlgorithm.Tests;
1313

1414
[TestClass]
1515
public class AbstractPolylineDecoderTest {
16-
private static readonly PolylineDecoder _decoder = new PolylineDecoder();
16+
private static readonly PolylineDecoder _decoder = new();
1717

1818
public static IEnumerable<object[]> CoordinateCount => [[1], [10], [100], [1_000]];
1919

@@ -49,7 +49,7 @@ public void Constructor_Options_Instance_Ok() {
4949
[TestMethod]
5050
public void Constructor_Null_Options_Throws_ArgumentNullException() {
5151
// Arrange
52-
void New() => new PolylineDecoder(null!);
52+
static void New() => new PolylineDecoder(null!);
5353

5454
// Act
5555
var exception = Assert.ThrowsExactly<ArgumentNullException>(New);
@@ -62,7 +62,9 @@ public void Constructor_Null_Options_Throws_ArgumentNullException() {
6262
[TestMethod]
6363
public void Decode_NullPolyline_Throws_ArgumentException() {
6464
// Arrange
65-
void Decode() => _decoder.Decode(null!).ToList();
65+
#pragma warning disable IDE0305 // Simplify collection initialization
66+
static void Decode() => _decoder.Decode(null!).ToList();
67+
#pragma warning restore IDE0305 // Simplify collection initialization
6668

6769
// Act
6870
var exception = Assert.ThrowsExactly<ArgumentNullException>(Decode);
@@ -75,7 +77,9 @@ public void Decode_NullPolyline_Throws_ArgumentException() {
7577
[TestMethod]
7678
public void Decode_EmptyPolyline_Throws_ArgumentException() {
7779
// Arrange
78-
void Decode() => _decoder.Decode(string.Empty).ToList();
80+
#pragma warning disable IDE0305 // Simplify collection initialization
81+
static void Decode() => _decoder.Decode(string.Empty).ToList();
82+
#pragma warning restore IDE0305 // Simplify collection initialization
7983

8084
// Act
8185
var exception = Assert.ThrowsExactly<ArgumentException>(Decode);
@@ -88,7 +92,9 @@ public void Decode_EmptyPolyline_Throws_ArgumentException() {
8892
[TestMethod]
8993
public void Decode_WhitespacePolyline_Throws_ArgumentException() {
9094
// Arrange
91-
void Decode() => _decoder.Decode(" ").ToList();
95+
#pragma warning disable IDE0305 // Simplify collection initialization
96+
static void Decode() => _decoder.Decode(" ").ToList();
97+
#pragma warning restore IDE0305 // Simplify collection initialization
9298

9399
// Act
94100
var exception = Assert.ThrowsExactly<ArgumentException>(Decode);
@@ -102,7 +108,9 @@ public void Decode_WhitespacePolyline_Throws_ArgumentException() {
102108
[DynamicData(nameof(InvalidPolylines), DynamicDataSourceType.Property)]
103109
public void Decode_InvalidPolyline_Throws_InvalidPolylineException(string polyline) {
104110
// Arrange
111+
#pragma warning disable IDE0305 // Simplify collection initialization
105112
void Decode() => _decoder.Decode(polyline).ToList();
113+
#pragma warning restore IDE0305 // Simplify collection initialization
106114

107115
// Act
108116
var exception = Assert.ThrowsExactly<InvalidPolylineException>(Decode);
@@ -115,7 +123,9 @@ public void Decode_InvalidPolyline_Throws_InvalidPolylineException(string polyli
115123
[TestMethod]
116124
public void Decode_ShortPolyline_Throws_InvalidPolylineException() {
117125
// Arrange
118-
void Decode() => _decoder.Decode("?").ToList();
126+
#pragma warning disable IDE0305 // Simplify collection initialization
127+
static void Decode() => _decoder.Decode("?").ToList();
128+
#pragma warning restore IDE0305 // Simplify collection initialization
119129

120130
// Act
121131
var exception = Assert.ThrowsExactly<ArgumentException>(Decode);

tests/PolylineAlgorithm.Tests/AbstractPolylineEncoderTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace PolylineAlgorithm.Tests;
1313

1414
[TestClass]
1515
public class AbstractPolylineEncoderTest {
16-
private static readonly PolylineEncoder _encoder = new PolylineEncoder();
16+
private static readonly PolylineEncoder _encoder = new();
1717

1818
public static IEnumerable<object[]> CoordinateCount => [[1], [10], [100], [1_000]];
1919

@@ -49,7 +49,7 @@ public void Constructor_ValidOptions_Ok() {
4949
[TestMethod]
5050
public void Constructor_Null_Options_Throws_ArgumentNullException() {
5151
// Arrange
52-
void New() => new PolylineEncoder(null!);
52+
static void New() => new PolylineEncoder(null!);
5353

5454
// Act
5555
var exception = Assert.ThrowsExactly<ArgumentNullException>(New);
@@ -62,7 +62,7 @@ public void Constructor_Null_Options_Throws_ArgumentNullException() {
6262
[TestMethod]
6363
public void Encode_NullCoordinates_Throws_ArgumentException() {
6464
// Arrange
65-
void Encode() => _encoder.Encode(null!);
65+
static void Encode() => _encoder.Encode(null!);
6666

6767
// Act
6868
var exception = Assert.ThrowsExactly<ArgumentNullException>(Encode);
@@ -75,7 +75,7 @@ public void Encode_NullCoordinates_Throws_ArgumentException() {
7575
[TestMethod]
7676
public void Encode_EmptyCoordinates_Throws_ArgumentException() {
7777
// Arrange
78-
void Encode() => _encoder.Encode(Array.Empty<(double Latitude, double Longitude)>());
78+
static void Encode() => _encoder.Encode([]);
7979

8080
// Act
8181
var exception = Assert.ThrowsExactly<ArgumentException>(Encode);
@@ -88,7 +88,7 @@ public void Encode_EmptyCoordinates_Throws_ArgumentException() {
8888
[TestMethod]
8989
public void Encode_BufferTooSmall_Throws_InternalBufferOverflowException() {
9090
// Arrange
91-
PolylineEncoder _encoder = new PolylineEncoder(new PolylineEncodingOptions { MaxBufferSize = 12 });
91+
PolylineEncoder _encoder = new(new PolylineEncodingOptions { MaxBufferSize = 12 });
9292
IEnumerable<(double Latitude, double Longitude)> coordinates = RandomValueProvider.GetCoordinates(2);
9393

9494
// Act

tests/PolylineAlgorithm.Tests/CoordinateTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ public void GetHashCode_Equal_For_Equal_Coordinates() {
231231
[TestMethod]
232232
public void ToString_Format_Ok() {
233233
var c = new Coordinate(12.34, 56.78);
234-
StringAssert.Contains(c.ToString(), "Latitude: 12.34");
235-
StringAssert.Contains(c.ToString(), "Longitude: 56.78");
234+
Assert.Contains("Latitude: 12.34", c.ToString());
235+
Assert.Contains("Longitude: 56.78", c.ToString());
236236
}
237237

238238
/// <summary>

tests/PolylineAlgorithm.Tests/FakeLoggerFactory.cs renamed to tests/PolylineAlgorithm.Tests/Fakes/FakeLoggerFactory.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
44
//
55

6-
namespace PolylineAlgorithm.Tests;
6+
namespace PolylineAlgorithm.Tests.Fakes;
77

88
using Microsoft.Extensions.Logging;
99
using Microsoft.Extensions.Logging.Testing;
1010

1111
internal class FakeLoggerFactory : ILoggerFactory {
1212
private bool _isDisposed;
13-
1413
public FakeLoggerFactory(FakeLoggerProvider loggerProvider) {
15-
Provider = loggerProvider;
14+
Provider = loggerProvider ?? throw new ArgumentNullException(nameof(loggerProvider));
1615
}
1716

1817
public ILoggerProvider Provider { get; private set; }
1918

20-
2119
public void AddProvider(ILoggerProvider provider) {
2220
Provider = provider;
2321
}

tests/PolylineAlgorithm.Tests/Internal/CoordinateVarianceTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void ToString_Returns_Value_Containing_Variance(int latitude, int longitu
8888
string result = variance.ToString();
8989

9090
// Assert
91-
StringAssert.Contains(result, $"Latitude: {latitude}");
92-
StringAssert.Contains(result, $"Longitude: {longitude}");
91+
Assert.Contains($"Latitude: {latitude}", result);
92+
Assert.Contains($"Longitude: {longitude}", result);
9393
}
9494
}

tests/PolylineAlgorithm.Tests/Internal/LoggingTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace PolylineAlgorithm.Tests.Internal;
99
using Microsoft.Extensions.Logging.Testing;
1010
using PolylineAlgorithm.Internal.Logging;
1111
using PolylineAlgorithm.Tests;
12+
using PolylineAlgorithm.Tests.Fakes;
1213

1314
[TestClass]
1415
public class LoggingTest {

tests/PolylineAlgorithm.Tests/InvalidPolylineExceptionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public void Throw_Method_Invalid_Coordinate_Parameter_PolylineMalformedException
2626

2727
// Assert
2828
Assert.IsFalse(string.IsNullOrWhiteSpace(exception.Message));
29-
Assert.IsTrue(exception.Message.Contains(position.ToString()));
29+
Assert.Contains(position.ToString(), exception.Message);
3030
}
3131
}

tests/PolylineAlgorithm.Tests/PolylineDecoderExtensionsTest.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ namespace PolylineAlgorithm.Tests;
1212

1313
[TestClass]
1414
public class PolylineDecoderExtensionsTest {
15-
private readonly PolylineDecoder decoder = new PolylineDecoder();
15+
private readonly PolylineDecoder _decoder = new();
1616

1717
public static IEnumerable<object[]> CoordinateCount => [[1], [10], [100], [1_000]];
1818

1919
[TestMethod]
2020
public void Decode_Null_Decoder_Null_String_Throws_ArgumentNullException() {
2121
// Arrange
22-
void Decode() => PolylineDecoderExtensions.Decode(null!, string.Empty).ToList();
22+
#pragma warning disable IDE0305 // Simplify collection initialization
23+
static void Decode() => PolylineDecoderExtensions.Decode(null!, string.Empty).ToList();
24+
#pragma warning restore IDE0305 // Simplify collection initialization
2325

2426
// Act
2527
var exception = Assert.ThrowsExactly<ArgumentNullException>(Decode);
@@ -32,7 +34,9 @@ public void Decode_Null_Decoder_Null_String_Throws_ArgumentNullException() {
3234
[TestMethod]
3335
public void Decode_Null_Decoder_Null_CharArray_Throws_ArgumentNullException() {
3436
// Arrange
35-
void Decode() => PolylineDecoderExtensions.Decode(null!, []).ToList();
37+
#pragma warning disable IDE0305 // Simplify collection initialization
38+
static void Decode() => PolylineDecoderExtensions.Decode(null!, []).ToList();
39+
#pragma warning restore IDE0305 // Simplify collection initialization
3640

3741
// Act
3842
var exception = Assert.ThrowsExactly<ArgumentNullException>(Decode);
@@ -45,7 +49,9 @@ public void Decode_Null_Decoder_Null_CharArray_Throws_ArgumentNullException() {
4549
[TestMethod]
4650
public void Decode_Null_Decoder_Empty_Memory_Throws_ArgumentNullException() {
4751
// Arrange
48-
void Decode() => PolylineDecoderExtensions.Decode(null!, Memory<char>.Empty).ToList();
52+
#pragma warning disable IDE0305 // Simplify collection initialization
53+
static void Decode() => PolylineDecoderExtensions.Decode(null!, Memory<char>.Empty).ToList();
54+
#pragma warning restore IDE0305 // Simplify collection initialization
4955

5056
// Act
5157
var exception = Assert.ThrowsExactly<ArgumentNullException>(Decode);
@@ -65,7 +71,7 @@ public void Decode_String_Returns_Expected_Coordinates(int count) {
6571
.ToList();
6672

6773
// Act
68-
var result = PolylineDecoderExtensions.Decode(decoder, polyline).ToList();
74+
var result = PolylineDecoderExtensions.Decode(_decoder, polyline).ToList();
6975

7076
// Assert
7177
CollectionAssert.AreEqual(expected, result);
@@ -81,7 +87,7 @@ public void Decode_CharArray_Returns_Expected_Coordinates(int count) {
8187
.ToList();
8288

8389
// Act
84-
var result = PolylineDecoderExtensions.Decode(decoder, polyline).ToList();
90+
var result = PolylineDecoderExtensions.Decode(_decoder, polyline).ToList();
8591

8692
// Assert
8793
CollectionAssert.AreEqual(expected, result);
@@ -97,7 +103,7 @@ public void Decode_Memory_Returns_Expected_Coordinates(int count) {
97103
.ToList();
98104

99105
// Act
100-
var result = PolylineDecoderExtensions.Decode(decoder, polyline).ToList();
106+
var result = PolylineDecoderExtensions.Decode(_decoder, polyline).ToList();
101107

102108
// Assert
103109
CollectionAssert.AreEqual(expected, result);

tests/PolylineAlgorithm.Tests/PolylineDecoderTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public void Decode_Default_Polyline_Throws_ArgumentException() {
2929
Polyline empty = new();
3030

3131
// Act
32+
#pragma warning disable IDE0305 // Simplify collection initialization
3233
void Execute(Polyline value) => Decoder.Decode(value).ToList();
34+
#pragma warning restore IDE0305 // Simplify collection initialization
3335

3436
// Assert
3537
Assert.ThrowsExactly<ArgumentException>(() => Execute(empty));

0 commit comments

Comments
 (0)