@@ -23,8 +23,10 @@ public class EncodingTest {
2323
2424 private static class TestData {
2525
26- private final double latitude ;
27- private final double longitude ;
26+ private final double latitudeDegrees ;
27+ private final double longitudeDegrees ;
28+ private final long latitudeInteger ;
29+ private final long longitudeInteger ;
2830 private final int length ;
2931 private final String code ;
3032
@@ -33,10 +35,12 @@ public TestData(String line) {
3335 if (parts .length != 4 ) {
3436 throw new IllegalArgumentException ("Wrong format of testing data." );
3537 }
36- this .latitude = Double .parseDouble (parts [0 ]);
37- this .longitude = Double .parseDouble (parts [1 ]);
38- this .length = Integer .parseInt (parts [2 ]);
39- this .code = parts [3 ];
38+ this .latitudeDegrees = Double .parseDouble (parts [0 ]);
39+ this .longitudeDegrees = Double .parseDouble (parts [1 ]);
40+ this .latitudeInteger = Long .parseLong (parts [2 ]);
41+ this .longitudeInteger = Long .parseLong (parts [3 ]);
42+ this .length = Integer .parseInt (parts [4 ]);
43+ this .code = parts [5 ];
4044 }
4145 }
4246
@@ -61,9 +65,36 @@ public void testEncodeFromLatLong() {
6165 Assert .assertEquals (
6266 String .format (
6367 "Latitude %f, longitude %f and length %d were wrongly encoded." ,
64- testData .latitude , testData .longitude , testData .length ),
68+ testData .latitudeDegrees , testData .longitudeDegrees , testData .length ),
6569 testData .code ,
66- OpenLocationCode .encode (testData .latitude , testData .longitude , testData .length ));
70+ OpenLocationCode .encode (testData .latitudeDegrees , testData .longitudeDegrees , testData .length ));
71+ }
72+ }
73+
74+ @ Test
75+ public void testDegreesToIntegers () {
76+ for (TestData testData : testDataList ) {
77+ long [] got = OpenLocationCode .degreesToIntegers (testData .latitudeDegrees , testData .longitudeDegrees );
78+ Assert .assertEquals (
79+ String .format ("Latitude %f integer conversion is incorrect" , testData .latitudeDegrees ),
80+ testData .latitudeInteger ,
81+ got [0 ]);
82+ Assert .assertEquals (
83+ String .format ("Longitude %f integer conversion is incorrect" , testData .longitudeDegrees ),
84+ testData .longitudeInteger ,
85+ got [1 ]);
86+ }
87+ }
88+
89+ @ Test
90+ public void testEncodeIntegers () {
91+ for (TestData testData : testDataList ) {
92+ Assert .assertEquals (
93+ String .format (
94+ "Latitude %d, longitude %d and length %d were wrongly encoded." ,
95+ testData .latitudeInteger , testData .longitudeInteger , testData .length ),
96+ testData .code ,
97+ OpenLocationCode .encodeIntegers (testData .latitudeInteger , testData .longitudeInteger , testData .length ));
6798 }
6899 }
69100}
0 commit comments