Skip to content

Commit f141217

Browse files
author
Petr Sramek
committed
test documented
1 parent 38c3d6a commit f141217

15 files changed

+412
-147
lines changed

tests/PolylineAlgorithm.Tests/CoordinateTest.cs

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,33 @@ namespace PolylineAlgorithm.Tests;
88
using Microsoft.VisualStudio.TestTools.UnitTesting;
99

1010
/// <summary>
11-
/// Tests <see cref="Polyline"/> type.
11+
/// Tests for the <see cref="Coordinate"/> type.
1212
/// </summary>
1313
[TestClass]
1414
public class CoordinateTest {
15-
public static IEnumerable<object[]> Constructor_Valid_Parameters => [
16-
[ 90, 180 ],
17-
[ -90, -180 ],
18-
[ 90, -180 ],
19-
[ -90, 180 ],
20-
];
21-
22-
public static IEnumerable<object[]> Constructor_Invalid_Parameters => [
23-
[ double.MaxValue, double.MaxValue ],
24-
[ double.MinValue, double.MinValue ],
25-
[ double.MaxValue, double.MinValue ],
26-
[ double.MinValue, double.MaxValue ],
27-
];
28-
15+
/// <summary>
16+
/// Provides test data for the <see cref="Constructor_Valid_Parameters_Ok"/> method.
17+
/// </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+
};
24+
25+
/// <summary>
26+
/// Provides test data for the <see cref="Constructor_Invalid_Parameters_Ok"/> method.
27+
/// </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+
};
34+
35+
/// <summary>
36+
/// Tests the parameterless constructor of the <see cref="Coordinate"/> class.
37+
/// </summary>
2938
[TestMethod]
3039
public void Constructor_Parameterless_Ok() {
3140
// Arrange
@@ -44,6 +53,11 @@ public void Constructor_Parameterless_Ok() {
4453
Assert.AreEqual(longitude, result.Longitude);
4554
}
4655

56+
/// <summary>
57+
/// Tests the <see cref="Coordinate"/> constructor with valid parameters.
58+
/// </summary>
59+
/// <param name="latitude">The latitude value.</param>
60+
/// <param name="longitude">The longitude value.</param>
4761
[TestMethod]
4862
[DynamicData(nameof(Constructor_Valid_Parameters))]
4963
public void Constructor_Valid_Parameters_Ok(double latitude, double longitude) {
@@ -61,6 +75,11 @@ public void Constructor_Valid_Parameters_Ok(double latitude, double longitude) {
6175
Assert.AreEqual(longitude, result.Longitude);
6276
}
6377

78+
/// <summary>
79+
/// Tests the <see cref="Coordinate"/> constructor with invalid parameters.
80+
/// </summary>
81+
/// <param name="latitude">The latitude value.</param>
82+
/// <param name="longitude">The longitude value.</param>
6483
[TestMethod]
6584
[DynamicData(nameof(Constructor_Invalid_Parameters))]
6685
public void Constructor_Invalid_Parameters_Ok(double latitude, double longitude) {
@@ -78,7 +97,11 @@ public void Constructor_Invalid_Parameters_Ok(double latitude, double longitude)
7897
Assert.AreEqual(longitude, result.Longitude);
7998
}
8099

81-
100+
/// <summary>
101+
/// Tests the <see cref="Coordinate.Equals(Coordinate)"/> method with equal coordinates.
102+
/// </summary>
103+
/// <param name="latitude">The latitude value.</param>
104+
/// <param name="longitude">The longitude value.</param>
82105
[TestMethod]
83106
[DynamicData(nameof(Constructor_Valid_Parameters))]
84107
public void Equals_Coordinate_True(double latitude, double longitude) {
@@ -93,6 +116,11 @@ public void Equals_Coordinate_True(double latitude, double longitude) {
93116
Assert.IsTrue(result);
94117
}
95118

119+
/// <summary>
120+
/// Tests the <see cref="Coordinate.Equals(Coordinate)"/> method with unequal coordinates.
121+
/// </summary>
122+
/// <param name="latitude">The latitude value.</param>
123+
/// <param name="longitude">The longitude value.</param>
96124
[TestMethod]
97125
[DynamicData(nameof(Constructor_Valid_Parameters))]
98126
public void Equals_Coordinate_False(double latitude, double longitude) {
@@ -106,4 +134,7 @@ public void Equals_Coordinate_False(double latitude, double longitude) {
106134
// Assert
107135
Assert.IsFalse(result);
108136
}
109-
}
137+
}
138+
139+
140+

tests/PolylineAlgorithm.Tests/Data/Values.cs

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@ namespace PolylineAlgorithm.Tests.Data;
88
using System.Collections.Generic;
99

1010
/// <summary>
11-
/// Defines default values and objects used for testing purposes
11+
/// Defines default values and objects used for testing purposes.
1212
/// </summary>
1313
internal static class Values {
1414
private static readonly Random _random = new(DateTime.Now.Millisecond);
1515

1616
/// <summary>
17-
/// Defines default decoded values and objects udśed for testing purposes
17+
/// Defines default decoded values and objects used for testing purposes.
1818
/// </summary>
1919
public static class Coordinates {
2020
/// <summary>
21-
/// Defines empty range of coordinates. Equals to decoded <seealso cref="Polyline.Empty"/>
21+
/// Defines an empty range of coordinates. Equals to decoded <seealso cref="Polyline.Empty"/>.
2222
/// </summary>
23-
public static readonly IEnumerable<Coordinate> Empty = [];
23+
public static readonly IEnumerable<Coordinate> Empty = Array.Empty<Coordinate>();
2424

2525
/// <summary>
26-
/// Defines range of invalid coordinates. Equals to decoded <seealso cref="Polyline.Invalid"/>
26+
/// Defines a range of invalid coordinates. Equals to decoded <seealso cref="Polyline.Invalid"/>.
2727
/// </summary>
28-
public static readonly IEnumerable<Coordinate> Invalid = [
28+
public static readonly IEnumerable<Coordinate> Invalid = new List<Coordinate> {
2929
new(149.47383, 259.06250),
3030
new(-158.37407, 225.31250),
3131
new(152.99363, -220.93750),
3232
new(-144.49024, -274.37500)
33-
];
33+
};
3434

3535
/// <summary>
36-
/// Defines range of valid coordinates. Equals to decoded <seealso cref="Polyline.Valid"/>
36+
/// Defines a range of valid coordinates. Equals to decoded <seealso cref="Polyline.Valid"/>.
3737
/// </summary>
38-
public static readonly IEnumerable<Coordinate> Valid = [
38+
public static readonly IEnumerable<Coordinate> Valid = new List<Coordinate> {
3939
new(41.45450,-120.00601),
4040
new(-8.48144,-86.82596),
4141
new(39.26923,103.12430),
@@ -136,51 +136,89 @@ public static class Coordinates {
136136
new(-68.86080,-165.10417),
137137
new(-77.15836,-19.18719),
138138
new(88.82714,74.26587),
139-
];
139+
};
140140
}
141141

142142
/// <summary>
143-
/// Defines default encoded values and objects udśed for testing purposes
143+
/// Defines default encoded values and objects used for testing purposes.
144144
/// </summary>
145145
public static class Polyline {
146146
/// <summary>
147-
/// Defines empty string of polyline encoded coordinates. Equals to encoded <seealso cref="Coordinates.Empty"/>
147+
/// Defines an empty string of polyline encoded coordinates. Equals to encoded <seealso cref="Coordinates.Empty"/>.
148148
/// </summary>
149149
public static readonly string Empty = string.Empty;
150150

151151
/// <summary>
152-
/// Defines polyline encoded range of invalid coordinates. Equals to encoded <seealso cref="Coordinates.Invalid"/>
152+
/// Defines a polyline encoded range of invalid coordinates. Equals to encoded <seealso cref="Coordinates.Invalid"/>.
153153
/// </summary>
154154
public static readonly string Invalid = "mnc~Qsm_ja@";
155155

156156
/// <summary>
157-
/// Defines polyline encoded range of invalid coordinates. Equals to encoded <seealso cref="Coordinates.Invalid"/>
157+
/// Defines a polyline encoded range of malformed coordinates.
158158
/// </summary>
159159
public static readonly string Malformed = "d";
160160

161161
/// <summary>
162-
/// Defines polyline encoded range of valid coordinates. Equals to encoded <seealso cref="Coordinates.Valid"/>
162+
/// Defines a polyline encoded range of valid coordinates. Equals to encoded <seealso cref="Coordinates.Valid"/>.
163163
/// </summary>
164164
public static readonly string Valid = @"sq_|Fptm{UrbxoHinoiEuhmbHctjfc@`rocCt|nfJgiauLvc_uIh`pg_@h_fkVgctZoyqfW{rxgQhhymFpuvvDwqcfTlqbcBiegdTwf{uNngc|z@{vhlDnsi_B~nz`O}d_hNp{n`E}kcoKm`bCiul~\jhg|Hv{qoWshzh\{lf_G`pzMqm|bLzswoQbhcm`@b`}cIgignPgxntR|}vo^f~|}L}|_jBa|ujWuxkjQfj|w[wsz`Pmdb{XohnwA`srxWjitms@c_~`Tava_l@jxxcF`d|zHcpnaMnd{kYzccwPxzpiHfsxlL}jjjQqvdbIikyvj@cjdqTh`zoDzqleHnfmik@tbnoB_t}gFkzx_Ct_eiP`wxrBcd_|w@zlhfPtlxgBkwyyZn|~tFlpj|HxqiwUnddkFoo|nTee}dSfkcg`@py`uQiguom@zkkpEfcgkAntuuDzl~il@ir_gCrd~nI_ryeC_qmmMl_kgCz`qgFzkejBmlchYyp`hZ`_cuYzuc}Onqz}Ew~Gcsmj@lp{Hqj_gz@ne{pJnny~]g{tuNxbno[lfq_Lqhwjt@qn|cCuxnMyivuIh{|tR`ylsQlqbfO}rf`LxghfBg~{nAv`gdNbjh_Fglt|NfxwyBowwhW{bdtNdbkqe@rxtwSy{_fX{btm@va`_LkhwuUyqgzK`xdnKgbwsFigt_Mofdn\h|x[ccoPtbpvNz}skb@pl~xEqascV_wsx[`f_z]zewFs`zjAhturWxayhJqmfaAjmhhHxwuwF_aru@ojemVq|beu@kkucBdmryTevflDcbmdAnp|dHfpbd^io}z@e~}dFzcybQ}`hxOyt|bNl}blLnuspKk|t|k@itjfHt}}aVyzmcF_rgmLct}x@bazdq@loajBxygb@f}krVgnuqOcrx_Daqvp_@ew}yUn}kpU|uwnItashEpe_aHusi{Fsu}_Ewfhv[dzhzKxh_qXucxfXmynkGxuqbW|ppgi@vrsq@clryZk`bt^spkyP";
165165
}
166166

167+
/// <summary>
168+
/// Defines default values and objects used for testing malformed polyline exceptions.
169+
/// </summary>
167170
public static class MalformedPolylineException {
171+
/// <summary>
172+
/// Gets a random position value for testing malformed polyline exceptions.
173+
/// </summary>
168174
public static readonly int Position = _random.Next();
169175
}
170176

177+
/// <summary>
178+
/// Defines default values and objects used for testing invalid coordinate exceptions.
179+
/// </summary>
171180
public static class InvalidCoordinateException {
181+
/// <summary>
182+
/// Gets a valid coordinate for testing invalid coordinate exceptions.
183+
/// </summary>
172184
public static readonly Coordinate Valid = new(_random.NextDouble(), _random.NextDouble());
173185

186+
/// <summary>
187+
/// Gets an invalid coordinate for testing invalid coordinate exceptions.
188+
/// </summary>
174189
public static readonly Coordinate Invalid = new(double.MinValue, double.MaxValue);
175190
}
176191

192+
/// <summary>
193+
/// Defines default values and objects used for testing invalid reader state exceptions.
194+
/// </summary>
177195
public static class InvalidReaderStateException {
196+
/// <summary>
197+
/// Gets a random position value for testing invalid reader state exceptions.
198+
/// </summary>
178199
public static readonly int Position = _random.Next();
200+
201+
/// <summary>
202+
/// Gets a random length value for testing invalid reader state exceptions.
203+
/// </summary>
179204
public static readonly int Length = Position;
180205
}
181206

207+
/// <summary>
208+
/// Defines default values and objects used for testing invalid writer state exceptions.
209+
/// </summary>
182210
public static class InvalidWriterStateException {
211+
/// <summary>
212+
/// Gets a random position value for testing invalid writer state exceptions.
213+
/// </summary>
183214
public static readonly int Position = _random.Next();
215+
216+
/// <summary>
217+
/// Gets a random length value for testing invalid writer state exceptions.
218+
/// </summary>
184219
public static readonly int Length = Position;
185220
}
186-
}
221+
}
222+
223+
224+

tests/PolylineAlgorithm.Tests/Internal/PolylineReaderTest.cs

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,30 @@ namespace PolylineAlgorithm.Tests.Internal;
99
using PolylineAlgorithm.Tests.Data;
1010

1111
/// <summary>
12-
/// Defines tests for <see cref="PolylineReader"/> type.
12+
/// Defines tests for the <see cref="PolylineReader"/> type.
1313
/// </summary>
1414
[TestClass]
1515
public class PolylineReaderTest {
16-
public static IEnumerable<object[]> Valid_Constructor_Parameters => [
17-
[ Values.Polyline.Empty ],
18-
[ Values.Polyline.Valid ],
19-
[ Values.Polyline.Invalid ]
20-
];
21-
22-
public static IEnumerable<object[]> Invalid_Read_Method_Parameters => [
23-
[ Values.Polyline.Empty, Values.Coordinates.Empty.Select(c => (c.Latitude, c.Longitude)).ToList() ],
24-
[ Values.Polyline.Invalid, Values.Coordinates.Invalid.Select(c => (c.Latitude, c.Longitude)).ToList() ]
25-
];
26-
27-
16+
/// <summary>
17+
/// Provides test data for the <see cref="Constructor_Valid_Parameter_Ok"/> method.
18+
/// </summary>
19+
public static IEnumerable<object[]> Valid_Constructor_Parameters => new List<object[]> {
20+
new object[] { Values.Polyline.Empty },
21+
new object[] { Values.Polyline.Valid },
22+
new object[] { Values.Polyline.Invalid }
23+
};
24+
25+
/// <summary>
26+
/// Provides test data for the <see cref="Read_Empty_Polyline_InvalidReaderStateException_Thrown"/> and <see cref="Read_Index_Out_Of_Range_InvalidReaderStateException_Thrown"/> methods.
27+
/// </summary>
28+
public static IEnumerable<object[]> Invalid_Read_Method_Parameters => new List<object[]> {
29+
new object[] { Values.Polyline.Empty, Values.Coordinates.Empty.Select(c => (c.Latitude, c.Longitude)).ToList() },
30+
new object[] { Values.Polyline.Invalid, Values.Coordinates.Invalid.Select(c => (c.Latitude, c.Longitude)).ToList() }
31+
};
32+
33+
/// <summary>
34+
/// Tests the parameterless constructor of the <see cref="PolylineReader"/> class.
35+
/// </summary>
2836
[TestMethod]
2937
public void Constructor_Parameterless_Ok() {
3038
// Arrange
@@ -39,6 +47,10 @@ public void Constructor_Parameterless_Ok() {
3947
Assert.AreEqual(position, reader.Position);
4048
}
4149

50+
/// <summary>
51+
/// Tests the <see cref="PolylineReader"/> constructor with valid parameters.
52+
/// </summary>
53+
/// <param name="value">The encoded polyline string.</param>
4254
[TestMethod]
4355
[DynamicData(nameof(Valid_Constructor_Parameters))]
4456
public void Constructor_Valid_Parameter_Ok(string value) {
@@ -55,6 +67,9 @@ public void Constructor_Valid_Parameter_Ok(string value) {
5567
Assert.AreEqual(position, reader.Position);
5668
}
5769

70+
/// <summary>
71+
/// Tests the <see cref="PolylineReader.Read"/> method with a valid parameter.
72+
/// </summary>
5873
[TestMethod]
5974
public void Read_Valid_Parameter_Ok() {
6075
// Arrange
@@ -63,11 +78,11 @@ public void Read_Valid_Parameter_Ok() {
6378
int position = value.Length;
6479
Polyline polyline = Polyline.FromString(value);
6580
PolylineReader reader = new(in polyline);
66-
List<Coordinate> expected = [.. Values.Coordinates.Valid];
67-
List<Coordinate> result = new(expected.Count());
81+
List<Coordinate> expected = new(Values.Coordinates.Valid);
82+
List<Coordinate> result = new(expected.Count);
6883

6984
// Act
70-
for (int i = 0; i < expected.Count(); i++) {
85+
for (int i = 0; i < expected.Count; i++) {
7186
var coordinate = reader.Read();
7287
result.Add(coordinate);
7388
}
@@ -78,6 +93,9 @@ public void Read_Valid_Parameter_Ok() {
7893
CollectionAssert.AreEqual(expected, result);
7994
}
8095

96+
/// <summary>
97+
/// Tests the <see cref="PolylineReader.Read"/> method with an empty polyline, expecting an <see cref="InvalidReaderStateException"/>.
98+
/// </summary>
8199
[TestMethod]
82100
public void Read_Empty_Polyline_InvalidReaderStateException_Thrown() {
83101
// Arrange
@@ -91,9 +109,12 @@ static void Read(string value) {
91109
}
92110

93111
// Assert
94-
var exception = Assert.ThrowsExactly<InvalidReaderStateException>(() => Read(value));
112+
Assert.ThrowsExactly<InvalidReaderStateException>(() => Read(value));
95113
}
96114

115+
/// <summary>
116+
/// Tests the <see cref="PolylineReader.Read"/> method with an index out of range, expecting an <see cref="InvalidReaderStateException"/>.
117+
/// </summary>
97118
[TestMethod]
98119
public void Read_Index_Out_Of_Range_InvalidReaderStateException_Thrown() {
99120
// Arrange
@@ -111,9 +132,12 @@ static void Read(string value, int iterations) {
111132
}
112133

113134
// Assert
114-
var exception = Assert.ThrowsExactly<InvalidReaderStateException>(() => Read(value, iterations));
135+
Assert.ThrowsExactly<InvalidReaderStateException>(() => Read(value, iterations));
115136
}
116137

138+
/// <summary>
139+
/// Tests the <see cref="PolylineReader.Read"/> method with a malformed polyline, expecting an <see cref="InvalidPolylineException"/>.
140+
/// </summary>
117141
[TestMethod]
118142
public void Read_Malformed_Polyline_PolylineMalformedException() {
119143
// Arrange
@@ -125,9 +149,11 @@ static void Read(string value) {
125149
PolylineReader reader = new(in polyline);
126150
_ = reader.Read();
127151
}
128-
;
129152

130153
// Assert
131154
Assert.ThrowsExactly<InvalidPolylineException>(() => Read(value));
132155
}
133-
}
156+
}
157+
158+
159+

0 commit comments

Comments
 (0)