11namespace PolylineAlgorithm . Abstraction . Tests ;
22
33using Microsoft . VisualStudio . TestTools . UnitTesting ;
4+ using PolylineAlgorithm . Abstraction . Properties ;
45using PolylineAlgorithm . Utility ;
56using System ;
67
@@ -14,6 +15,7 @@ public class PolylineDecoderTest {
1415
1516 public static IEnumerable < ( double , double ) > MinAndMaxCoordinates => StaticValueProvider . Invalid . GetMinAndMaxCoordinates ( ) ;
1617
18+ public static IEnumerable < object [ ] > InvalidPolylines => StaticValueProvider . Invalid . GetInvalidPolylines ( ) . Select < string , object [ ] > ( p => [ p ] ) ;
1719
1820 [ TestMethod ]
1921 public void Constructor_Parameterless_Ok ( ) {
@@ -39,104 +41,117 @@ public void Constructor_ValidOptions_Ok() {
3941 }
4042
4143 [ TestMethod ]
42- public void Encode_NullPolyline_Throws_ArgumentException ( ) {
44+ public void Decode_NullPolyline_Throws_ArgumentException ( ) {
4345 // Arrange
44- void Encode ( ) => _decoder . Decode ( null ! ) ;
46+ void Decode ( ) => _decoder . Decode ( null ! ) . ToList ( ) ;
4547
4648 // Act
47- var exception = Assert . ThrowsExactly < ArgumentNullException > ( Encode ) ;
49+ var exception = Assert . ThrowsExactly < ArgumentNullException > ( Decode ) ;
4850
4951 // Assert
50- Assert . AreEqual ( "coordinates " , exception . ParamName ) ;
52+ Assert . AreEqual ( "polyline " , exception . ParamName ) ;
5153 Assert . IsFalse ( string . IsNullOrWhiteSpace ( exception . Message ) ) ;
5254 }
5355
5456 [ TestMethod ]
55- public void Encode_EmptyPolyline_Throws_ArgumentException ( ) {
57+ public void Decode_EmptyPolyline_Throws_ArgumentException ( ) {
5658 // Arrange
57- void Encode ( ) => _decoder . Decode ( string . Empty ) ;
59+ void Decode ( ) => _decoder . Decode ( string . Empty ) . ToList ( ) ;
5860
5961 // Act
60- var exception = Assert . ThrowsExactly < ArgumentException > ( Encode ) ;
62+ var exception = Assert . ThrowsExactly < ArgumentException > ( Decode ) ;
6163
6264 // Assert
63- Assert . AreEqual ( "coordinates " , exception . ParamName ) ;
65+ Assert . AreEqual ( "polyline " , exception . ParamName ) ;
6466 Assert . IsFalse ( string . IsNullOrWhiteSpace ( exception . Message ) ) ;
6567 }
6668
6769 [ TestMethod ]
68- public void Encode_WhitespacePolyline_Throws_ArgumentException ( ) {
70+ public void Decode_WhitespacePolyline_Throws_ArgumentException ( ) {
6971 // Arrange
70- void Encode ( ) => _decoder . Decode ( string . Empty ) ;
72+ void Decode ( ) => _decoder . Decode ( " " ) . ToList ( ) ;
7173
7274 // Act
73- var exception = Assert . ThrowsExactly < ArgumentException > ( Encode ) ;
75+ var exception = Assert . ThrowsExactly < ArgumentException > ( Decode ) ;
7476
7577 // Assert
76- Assert . AreEqual ( "coordinates " , exception . ParamName ) ;
78+ Assert . AreEqual ( "polyline " , exception . ParamName ) ;
7779 Assert . IsFalse ( string . IsNullOrWhiteSpace ( exception . Message ) ) ;
7880 }
7981
8082 [ TestMethod ]
81- public void Encode_BufferTooSmall_Throws_InternalBufferOverflowException ( ) {
83+ [ DynamicData ( nameof ( InvalidPolylines ) , DynamicDataSourceType . Property ) ]
84+ public void Decode_InvalidPolyline_Throws_InvalidPolylineException ( string polyline ) {
8285 // Arrange
83- PolylineDecoder decoder = new PolylineDecoder ( new PolylineEncodingOptions { BufferSize = 12 } ) ;
84- string polyline = RandomValueProvider . GetPolyline ( 2 ) ;
86+ void Decode ( ) => _decoder . Decode ( polyline ) . ToList ( ) ;
8587
8688 // Act
87- var exception = Assert . ThrowsExactly < InternalBufferOverflowException > ( ( ) => decoder . Decode ( polyline ) ) ;
89+ var exception = Assert . ThrowsExactly < InvalidPolylineException > ( Decode ) ;
90+
91+ // Assert
92+ Assert . IsFalse ( string . IsNullOrWhiteSpace ( exception . Message ) ) ;
93+ }
94+
95+
96+ [ TestMethod ]
97+ public void Decode_ShortPolyline_Throws_InvalidPolylineException ( ) {
98+ // Arrange
99+ void Decode ( ) => _decoder . Decode ( "?" ) . ToList ( ) ;
100+
101+ // Act
102+ var exception = Assert . ThrowsExactly < ArgumentException > ( Decode ) ;
88103
89104 // Assert
90105 Assert . IsFalse ( string . IsNullOrWhiteSpace ( exception . Message ) ) ;
91106 }
92107
93108 //[TestMethod]
94109 //[DynamicData(nameof(NotANumberAndInfinityCoordinates))]
95- //public void Encode_NotANumberAndInfinityCoordinate_Throws_ArgumentOutOfRangeException ((double, double) coordinate) {
110+ //public void Decode_NotANumberAndInfinityCoordinate_Throws_ArgumentOutOfRangeException ((double, double) coordinate) {
96111 // // Arrange
97-
112+ // void Decode() => _decoder.Decode([coordinate])
98113 // // Act
99- // var exception = Assert.ThrowsExactly<ArgumentOutOfRangeException>(() => _decoder.Encode([coordinate]) );
114+ // var exception = Assert.ThrowsExactly<ArgumentOutOfRangeException>(Decode );
100115
101116 // // Assert
102117 // Assert.IsFalse(string.IsNullOrWhiteSpace(exception.Message));
103118 //}
104119
105120 //[TestMethod]
106121 //[DynamicData(nameof(MinAndMaxCoordinates))]
107- //public void Encode_MinAndMaxCoordinate_Throws_ArgumentOutOfRangeException ((double, double) coordinate) {
122+ //public void Decode_MinAndMaxCoordinate_Throws_ArgumentOutOfRangeException ((double, double) coordinate) {
108123 // // Arrange
109124
110125 // // Act
111- // var exception = Assert.ThrowsExactly<ArgumentOutOfRangeException>(() => _decoder.Encode ([coordinate]));
126+ // var exception = Assert.ThrowsExactly<ArgumentOutOfRangeException>(() => _decoder.Decode ([coordinate]));
112127
113128 // // Assert
114129 // Assert.IsFalse(string.IsNullOrWhiteSpace(exception.Message));
115130 //}
116131
117132 //[TestMethod]
118133 //[DynamicData(nameof(CoordinateCount))]
119- //public void Encode_RandomValue_ValidInput_Ok (int count) {
134+ //public void Decode_RandomValue_ValidInput_Ok (int count) {
120135 // // Arrange
121136 // IEnumerable<(double Latitude, double Longitude)> coordinates = RandomValueProvider.GetCoordinates(count);
122137 // string expected = RandomValueProvider.GetPolyline(count);
123138
124139 // // Act
125- // var result = _decoder.Encode (coordinates);
140+ // var result = _decoder.Decode (coordinates);
126141
127142 // // Assert
128143 // Assert.AreEqual(expected.Length, result.Length);
129144 // Assert.IsTrue(expected.Equals(result));
130145 //}
131146
132147 //[TestMethod]
133- //public void Encode_StaticValue_ValidInput_Ok () {
148+ //public void Decode_StaticValue_ValidInput_Ok () {
134149 // // Arrange
135150 // IEnumerable<(double Latitude, double Longitude)> coordinates = StaticValueProvider.Valid.GetCoordinates();
136151 // string expected = StaticValueProvider.Valid.GetPolyline();
137152
138153 // // Act
139- // var result = _decoder.Encode (coordinates);
154+ // var result = _decoder.Decode (coordinates);
140155
141156 // // Assert
142157 // Assert.AreEqual(expected.Length, result.Length);
@@ -155,8 +170,8 @@ protected override (double Latitude, double Longitude) CreateCoordinate(double l
155170 }
156171
157172 protected override ReadOnlyMemory < char > GetReadOnlyMemory ( string ? polyline ) {
158- if ( string . IsNullOrWhiteSpace ( polyline ) ) {
159- throw new ArgumentException ( ) ;
173+ if ( string . IsNullOrWhiteSpace ( polyline ) ) {
174+ throw new ArgumentException ( ExceptionMessageResource . ArgumentCannotBeNullEmptyOrWhiteSpaceMessage , nameof ( polyline ) ) ;
160175 }
161176
162177 return polyline . AsMemory ( ) ;
0 commit comments