@@ -305,4 +305,158 @@ mod tests {
305305 let valid = "_p~iF~ps|U" ; // Should decode to reasonable coordinates
306306 assert ! ( decode( valid, 5 ) . is_ok( ) ) ;
307307 }
308+
309+ #[ test]
310+ fn test_validate_nan_longitude ( ) {
311+ let coord = LngLat {
312+ lng_deg : f64:: NAN ,
313+ lat_deg : 0.0 ,
314+ } ;
315+ let result = validate_decoded_coordinate ( & coord) ;
316+ assert ! ( matches!( result, Err ( PolylineError :: InvalidCoordinate ( ..) ) ) ) ;
317+ }
318+
319+ #[ test]
320+ fn test_validate_nan_latitude ( ) {
321+ let coord = LngLat {
322+ lng_deg : 0.0 ,
323+ lat_deg : f64:: NAN ,
324+ } ;
325+ let result = validate_decoded_coordinate ( & coord) ;
326+ assert ! ( matches!( result, Err ( PolylineError :: InvalidCoordinate ( ..) ) ) ) ;
327+ }
328+
329+ #[ test]
330+ fn test_validate_infinity_longitude ( ) {
331+ let coord = LngLat {
332+ lng_deg : f64:: INFINITY ,
333+ lat_deg : 0.0 ,
334+ } ;
335+ let result = validate_decoded_coordinate ( & coord) ;
336+ assert ! ( matches!( result, Err ( PolylineError :: InvalidCoordinate ( ..) ) ) ) ;
337+ }
338+
339+ #[ test]
340+ fn test_validate_neg_infinity_longitude ( ) {
341+ let coord = LngLat {
342+ lng_deg : f64:: NEG_INFINITY ,
343+ lat_deg : 0.0 ,
344+ } ;
345+ let result = validate_decoded_coordinate ( & coord) ;
346+ assert ! ( matches!( result, Err ( PolylineError :: InvalidCoordinate ( ..) ) ) ) ;
347+ }
348+
349+ #[ test]
350+ fn test_validate_infinity_latitude ( ) {
351+ let coord = LngLat {
352+ lng_deg : 0.0 ,
353+ lat_deg : f64:: INFINITY ,
354+ } ;
355+ let result = validate_decoded_coordinate ( & coord) ;
356+ assert ! ( matches!( result, Err ( PolylineError :: InvalidCoordinate ( ..) ) ) ) ;
357+ }
358+
359+ #[ test]
360+ fn test_validate_neg_infinity_latitude ( ) {
361+ let coord = LngLat {
362+ lng_deg : 0.0 ,
363+ lat_deg : f64:: NEG_INFINITY ,
364+ } ;
365+ let result = validate_decoded_coordinate ( & coord) ;
366+ assert ! ( matches!( result, Err ( PolylineError :: InvalidCoordinate ( ..) ) ) ) ;
367+ }
368+
369+ #[ test]
370+ fn test_validate_longitude_below_lower_bound ( ) {
371+ let coord = LngLat {
372+ lng_deg : -180.2 ,
373+ lat_deg : 0.0 ,
374+ } ;
375+ let result = validate_decoded_coordinate ( & coord) ;
376+ assert ! ( matches!( result, Err ( PolylineError :: InvalidCoordinate ( ..) ) ) ) ;
377+ }
378+
379+ #[ test]
380+ fn test_validate_longitude_at_lower_bound ( ) {
381+ let coord = LngLat {
382+ lng_deg : -180.1 ,
383+ lat_deg : 0.0 ,
384+ } ;
385+ let result = validate_decoded_coordinate ( & coord) ;
386+ assert ! ( result. is_ok( ) ) ;
387+ }
388+
389+ #[ test]
390+ fn test_validate_longitude_at_upper_bound ( ) {
391+ let coord = LngLat {
392+ lng_deg : 180.1 ,
393+ lat_deg : 0.0 ,
394+ } ;
395+ let result = validate_decoded_coordinate ( & coord) ;
396+ assert ! ( result. is_ok( ) ) ;
397+ }
398+
399+ #[ test]
400+ fn test_validate_longitude_above_upper_bound ( ) {
401+ let coord = LngLat {
402+ lng_deg : 180.2 ,
403+ lat_deg : 0.0 ,
404+ } ;
405+ let result = validate_decoded_coordinate ( & coord) ;
406+ assert ! ( matches!( result, Err ( PolylineError :: InvalidCoordinate ( ..) ) ) ) ;
407+ }
408+
409+ #[ test]
410+ fn test_validate_latitude_below_lower_bound ( ) {
411+ let coord = LngLat {
412+ lng_deg : 0.0 ,
413+ lat_deg : -90.2 ,
414+ } ;
415+ let result = validate_decoded_coordinate ( & coord) ;
416+ assert ! ( matches!( result, Err ( PolylineError :: InvalidCoordinate ( ..) ) ) ) ;
417+ }
418+
419+ #[ test]
420+ fn test_validate_latitude_at_lower_bound ( ) {
421+ let coord = LngLat {
422+ lng_deg : 0.0 ,
423+ lat_deg : -90.1 ,
424+ } ;
425+ let result = validate_decoded_coordinate ( & coord) ;
426+ assert ! ( result. is_ok( ) ) ;
427+ }
428+
429+ #[ test]
430+ fn test_validate_latitude_at_upper_bound ( ) {
431+ let coord = LngLat {
432+ lng_deg : 0.0 ,
433+ lat_deg : 90.1 ,
434+ } ;
435+ let result = validate_decoded_coordinate ( & coord) ;
436+ assert ! ( result. is_ok( ) ) ;
437+ }
438+
439+ #[ test]
440+ fn test_validate_latitude_above_upper_bound ( ) {
441+ let coord = LngLat {
442+ lng_deg : 0.0 ,
443+ lat_deg : 90.2 ,
444+ } ;
445+ let result = validate_decoded_coordinate ( & coord) ;
446+ assert ! ( matches!( result, Err ( PolylineError :: InvalidCoordinate ( ..) ) ) ) ;
447+ }
448+
449+ #[ test]
450+ fn test_validate_valid_coordinates ( ) {
451+ let coords = vec ! [
452+ LngLat :: new_deg( 0.0 , 0.0 ) ,
453+ LngLat :: new_deg( -122.4194 , 37.7749 ) ,
454+ LngLat :: new_deg( 180.0 , 90.0 ) ,
455+ LngLat :: new_deg( -180.0 , -90.0 ) ,
456+ ] ;
457+
458+ for coord in coords {
459+ assert ! ( validate_decoded_coordinate( & coord) . is_ok( ) ) ;
460+ }
461+ }
308462}
0 commit comments