Skip to content

Commit 5ece143

Browse files
committed
interim commit
1 parent 09845c9 commit 5ece143

File tree

11 files changed

+43
-270
lines changed

11 files changed

+43
-270
lines changed

src/PolylineAlgorithm/PolylineEncoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public Polyline Encode(IEnumerable<Coordinate> coordinates) {
4242
int count = GetCount(coordinates);
4343

4444
if (count == 0) {
45-
return default;
45+
throw new ArgumentException(nameof(coordinates));
4646
}
4747

4848
CoordinateVariance variance = new();

src/PolylineAlgorithm/PolylineEncoding.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public bool TryReadValue(ref int variance, ref ReadOnlyMemory<char> buffer, ref
5454
/// <param name="value">The normalized integer value.</param>
5555
/// <returns>The denormalized double value.</returns>
5656
[MethodImpl(MethodImplOptions.AggressiveInlining)]
57-
public double Denormalize(int value) => (double)value / Defaults.Algorithm.Precision;
57+
public double Denormalize(int value) => Math.Round((double)value / Defaults.Algorithm.Precision, 5);
5858

5959
/// <summary>
6060
/// Attempts to write an encoded value to the buffer.

tests/PolylineAlgorithm.Tests/AsyncPolylineDecoderTest.cs

Lines changed: 0 additions & 86 deletions
This file was deleted.

tests/PolylineAlgorithm.Tests/AsyncPolylineEncoderTest.cs

Lines changed: 0 additions & 100 deletions
This file was deleted.

tests/PolylineAlgorithm.Tests/CoordinateTest.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ public class CoordinateTest {
1515
/// <summary>
1616
/// Provides test data for the <see cref="Constructor_Valid_Parameters_Ok"/> method.
1717
/// </summary>
18-
public static IEnumerable<object[]> Constructor_Valid_Parameters => new List<object[]> {
19-
new object[] { 90, 180 },
20-
new object[] { -90, -180 },
21-
new object[] { 90, -180 },
22-
new object[] { -90, 180 },
23-
};
18+
public static IEnumerable<object[]> Constructor_Valid_Parameters => [
19+
[90, 180],
20+
[-90, -180],
21+
[90, -180],
22+
[-90, 180],
23+
];
2424

2525
/// <summary>
2626
/// Provides test data for the <see cref="Constructor_Invalid_Parameters_Ok"/> method.
2727
/// </summary>
28-
public static IEnumerable<object[]> Constructor_Invalid_Parameters => new List<object[]> {
29-
new object[] { double.MaxValue, double.MaxValue },
30-
new object[] { double.MinValue, double.MinValue },
31-
new object[] { double.MaxValue, double.MinValue },
32-
new object[] { double.MinValue, double.MaxValue },
33-
};
28+
public static IEnumerable<object[]> Constructor_Invalid_Parameters => [
29+
[double.MaxValue, double.MaxValue],
30+
[double.MinValue, double.MinValue],
31+
[double.MaxValue, double.MinValue],
32+
[double.MinValue, double.MaxValue],
33+
];
3434

3535
/// <summary>
3636
/// Tests the parameterless constructor of the <see cref="Coordinate"/> class.

tests/PolylineAlgorithm.Tests/Data/Values.cs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -173,49 +173,4 @@ public static class MalformedPolylineException {
173173
/// </summary>
174174
public static readonly int Position = _random.Next();
175175
}
176-
177-
/// <summary>
178-
/// Defines default values and objects used for testing invalid coordinate exceptions.
179-
/// </summary>
180-
public static class InvalidCoordinateException {
181-
/// <summary>
182-
/// Gets a valid coordinate for testing invalid coordinate exceptions.
183-
/// </summary>
184-
public static readonly Coordinate Valid = new(_random.NextDouble(), _random.NextDouble());
185-
186-
/// <summary>
187-
/// Gets an invalid coordinate for testing invalid coordinate exceptions.
188-
/// </summary>
189-
public static readonly Coordinate Invalid = new(double.MinValue, double.MaxValue);
190-
}
191-
192-
/// <summary>
193-
/// Defines default values and objects used for testing invalid reader state exceptions.
194-
/// </summary>
195-
public static class InvalidReaderStateException {
196-
/// <summary>
197-
/// Gets a random position value for testing invalid reader state exceptions.
198-
/// </summary>
199-
public static readonly int Position = _random.Next();
200-
201-
/// <summary>
202-
/// Gets a random length value for testing invalid reader state exceptions.
203-
/// </summary>
204-
public static readonly int Length = Position;
205-
}
206-
207-
/// <summary>
208-
/// Defines default values and objects used for testing invalid writer state exceptions.
209-
/// </summary>
210-
public static class InvalidWriterStateException {
211-
/// <summary>
212-
/// Gets a random position value for testing invalid writer state exceptions.
213-
/// </summary>
214-
public static readonly int Position = _random.Next();
215-
216-
/// <summary>
217-
/// Gets a random length value for testing invalid writer state exceptions.
218-
/// </summary>
219-
public static readonly int Length = Position;
220-
}
221176
}

tests/PolylineAlgorithm.Tests/InvalidPolylineExceptionTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ public void Throw_Method_Invalid_Coordinate_Parameter_PolylineMalformedException
2121
var position = Values.MalformedPolylineException.Position;
2222

2323
// Act
24-
static void Throw(int position) => InvalidPolylineException.Throw(position);
24+
static void ThrowAt(int position) => InvalidPolylineException.Throw(position);
2525

2626
// Assert
27-
var exception = Assert.ThrowsExactly<InvalidPolylineException>(() => Throw(position));
27+
var exception = Assert.ThrowsExactly<InvalidPolylineException>(() => ThrowAt(position));
28+
2829
Assert.IsFalse(string.IsNullOrWhiteSpace(exception.Message));
2930
}
3031
}

tests/PolylineAlgorithm.Tests/PolylineDecoderTest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ namespace PolylineAlgorithm.Tests;
1515
/// </summary>
1616
[TestClass]
1717
public class PolylineDecoderTest {
18+
public static IEnumerable<object[]> CoordinateCount => [[1], [10], [100], [1_000], [10_000], [100_000], [1_000_000]];
19+
1820
/// <summary>
1921
/// The instance of the <see cref="PolylineDecoder"/> used for testing.
2022
/// </summary>
@@ -55,7 +57,8 @@ public void Decode_Empty_Input_ThrowsException() {
5557
/// </summary>
5658
/// <remarks>Expected result to equal <see cref="Values.Coordinates.Valid"/>.</remarks>
5759
[TestMethod]
58-
public void Decode_Valid_Input_Ok() {
60+
[DynamicData(nameof(CoordinateCount))]
61+
public void Decode_Valid_Input_Ok(int count) {
5962
// Arrange
6063
IEnumerable<Coordinate> expected = RandomValueProvider.GetCoordinates(1);
6164
string value = RandomValueProvider.GetPolyline(1).ToString();

tests/PolylineAlgorithm.Tests/PolylineEncoderTest.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ void EncodeNullCoordinates() {
4040
/// <summary>
4141
/// Tests the <see cref="PolylineEncoder.Encode(IEnumerable{Coordinate})"/> method with an empty input, expecting an <see cref="ArgumentException"/>.
4242
/// </summary>
43-
//[TestMethod]
44-
//public void Encode_EmptyInput_ThrowsException() {
45-
// // Arrange
46-
// IEnumerable<Coordinate> empty = Values.Coordinates.Empty;
43+
[TestMethod]
44+
public void Encode_EmptyInput_ThrowsException() {
45+
// Arrange
46+
IEnumerable<Coordinate> empty = Values.Coordinates.Empty;
4747

48-
// // Act
49-
// void EncodeEmptyCoordinates() {
50-
// Encoder.Encode(empty);
51-
// }
48+
// Act
49+
void EncodeEmptyCoordinates() {
50+
Encoder.Encode(empty);
51+
}
5252

53-
// // Assert
54-
// Assert.ThrowsExactly<ArgumentException>(() => EncodeEmptyCoordinates());
55-
//}
53+
// Assert
54+
Assert.ThrowsExactly<ArgumentException>(() => EncodeEmptyCoordinates());
55+
}
5656

5757
/// <summary>
5858
/// Tests the <see cref="PolylineEncoder.Encode(IEnumerable{Coordinate})"/> method with a valid input.

tests/PolylineAlgorithm.Tests/Validation/CoordinateRangeTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public class CoordinateRangeTest {
1515
/// <summary>
1616
/// Provides test data for the <see cref="Constructor_Valid_Parameters_Ok"/> method.
1717
/// </summary>
18-
public static IEnumerable<object[]> Constructor_Valid_Parameters => new List<object[]> {
19-
new object[] { -90, 90 },
20-
new object[] { -180, 180 },
21-
};
18+
public static IEnumerable<object[]> Constructor_Valid_Parameters => [
19+
[-90, 90],
20+
[-180, 180],
21+
];
2222

2323
/// <summary>
2424
/// Tests the parameterless constructor of the <see cref="CoordinateRange"/> class.

0 commit comments

Comments
 (0)