forked from mapcode-foundation/mapcode-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecoderTest.java
More file actions
295 lines (253 loc) · 12.4 KB
/
Copy pathDecoderTest.java
File metadata and controls
295 lines (253 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
* Copyright (C) 2014-2015 Stichting Mapcode Foundation (http://www.mapcode.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mapcode;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertEquals;
@SuppressWarnings({"OverlyBroadThrowsClause", "ProhibitedExceptionDeclared"})
public class DecoderTest {
private static final Logger LOG = LoggerFactory.getLogger(DecoderTest.class);
@Test
public void decodeMapcodeWithTerritory() throws Exception {
LOG.info("decodeMapcodeWithTerritory");
final Point point = MapcodeCodec.decode("49.4V", Territory.NLD);
assertEquals("decode latitude", 52376514, point.getLatMicroDeg());
assertEquals("decode longitude", 4908543, point.getLonMicroDeg());
}
@Test
public void decodeUpperLowercaseMapcode() throws Exception {
LOG.info("decodeUpperLowercaseMapcode");
final Point point1 = MapcodeCodec.decode("XXXXX.1234");
assertEquals("decode latitude", 59596312, point1.getLatMicroDeg());
assertEquals("decode longitude", 155931892, point1.getLonMicroDeg());
final Point point2 = MapcodeCodec.decode("Xxxxx.1234");
assertEquals("decode latitude", 59596312, point2.getLatMicroDeg());
assertEquals("decode longitude", 155931892, point2.getLonMicroDeg());
final Point point3 = MapcodeCodec.decode("xxxxx.1234");
assertEquals("decode latitude", 59596312, point3.getLatMicroDeg());
assertEquals("decode longitude", 155931892, point3.getLonMicroDeg());
}
@Test
public void decodeFullMapcode() throws Exception {
LOG.info("decodeFullMapcode");
final Point point1 = MapcodeCodec.decode("NLD 49.4V");
assertEquals("decode latitude", 52376514, point1.getLatMicroDeg());
assertEquals("decode longitude", 4908543, point1.getLonMicroDeg());
final Point point2 = MapcodeCodec.decode("US-ID LQJT.N94S");
assertEquals("decode latitude", 45011346, point2.getLatMicroDeg());
assertEquals("decode longitude", -113232731, point2.getLonMicroDeg());
final Point point3 = MapcodeCodec.decode("US_ID LQJT.N94S");
assertEquals("decode latitude", 45011346, point3.getLatMicroDeg());
assertEquals("decode longitude", -113232731, point3.getLonMicroDeg());
}
@Test
public void decodeInternationalMapcodeWithTerritory() throws Exception {
LOG.info("decodeInternationalMapcodeWithTerritory");
final Point point = MapcodeCodec.decode("VHXGB.1J9J", Territory.AAA);
assertEquals("decode latitude", 52376504, point.getLatMicroDeg());
assertEquals("decode longitude", 4908535, point.getLonMicroDeg());
}
@Test
public void decodeFullInternationalMapcode() throws Exception {
LOG.info("decodeFullInternationalMapcode");
final Point point = MapcodeCodec.decode("VHXGB.1J9J");
assertEquals("decode latitude", 52376504, point.getLatMicroDeg());
assertEquals("decode longitude", 4908535, point.getLonMicroDeg());
}
@Test
public void highPrecisionMapcodeWithTerritory() throws Exception {
LOG.info("highPrecisionMapcodeWithTerritory");
final Point point = MapcodeCodec.decode("49.4V-K2", Territory.NLD);
assertEquals("decode hi-precision latitude", 52376512, point.getLatMicroDeg());
assertEquals("decode hi-precision longitude", 4908540, point.getLonMicroDeg());
}
@Test
public void highPrecisionFullMapcode() throws Exception {
LOG.info("highPrecisionFullMapcode");
Point point = MapcodeCodec.decode("NLD 49.4V-K2");
assertEquals("decode hi-precision latitude", 52376512, point.getLatMicroDeg());
assertEquals("decode hi-precision longitude", 4908540, point.getLonMicroDeg());
point = MapcodeCodec.decode("NLD P42.NB1-0");
assertEquals("decode 8-precision latitude", 51999954, point.getLatMicroDeg());
assertEquals("decode 8-precision longitude", 4999900, point.getLonMicroDeg());
point = MapcodeCodec.decode("NLD P42.NB1-123");
assertEquals("decode 8-precision latitude", 51999948, point.getLatMicroDeg());
assertEquals("decode 8-precision longitude", 4999924, point.getLonMicroDeg());
point = MapcodeCodec.decode("NLD P42.NB1-MVRGBD0S");
assertEquals("decode 8-precision latitude", 51999999, point.getLatMicroDeg());
assertEquals("decode 8-precision longitude", 5000000, point.getLonMicroDeg());
}
@Test
public void highPrecisionUnicodeAthensAcropolis1() throws Exception {
LOG.info("highPrecisionUnicodeAthensAcropolis1");
final Point point = MapcodeCodec.decode("\u0397\u03a0.\u03982-\u03a62", Territory.GRC);
assertEquals("decodeUnicode latitude", 37971843, point.getLatMicroDeg());
assertEquals("decodeUnicode longitude", 23726223,
point.getLonMicroDeg());
}
@Test
public void highPrecisionUnicodeAthensAcropolis2() throws Exception {
LOG.info("highPrecisionUnicodeAthensAcropolis2");
final Point point = MapcodeCodec.decode("GRC \u0397\u03a0.\u03982-\u03a62");
assertEquals("decodeUnicode latitude", 37971843, point.getLatMicroDeg());
assertEquals("decodeUnicode longitude", 23726223,
point.getLonMicroDeg());
}
@Test
public void unicodeMapcodeAthensAcropolis1() throws Exception {
LOG.info("unicodeMapcodeAthensAcropolis1");
final Point point = MapcodeCodec.decode("\u0397\u03a0.\u03982", Territory.GRC);
assertEquals("decodeUnicode latitude", 37971812, point.getLatMicroDeg());
assertEquals("decodeUnicode longitude", 23726247,
point.getLonMicroDeg());
}
@Test
public void unicodeMapcodeAthensAcropolis2() throws Exception {
LOG.info("unicodeMapcodeAthensAcropolis2");
final Point point = MapcodeCodec.decode("GRC \u0397\u03a0.\u03982");
assertEquals("decodeUnicode latitude", 37971812, point.getLatMicroDeg());
assertEquals("decodeUnicode longitude", 23726247,
point.getLonMicroDeg());
}
@Test
public void unicodeMapcodeAthensAcropolis3() throws Exception {
LOG.info("unicodeMapcodeAthensAcropolis3");
final Point point = MapcodeCodec.decode("\u0393\u03a8\u039e \u0397\u03a0.\u03982");
assertEquals("decodeUnicode latitude", 37971812, point.getLatMicroDeg());
assertEquals("decodeUnicode longitude", 23726247,
point.getLonMicroDeg());
}
@Test
public void unicodeMapcodeTokyoTower1() throws Exception {
LOG.info("unicodeMapcodeTokyoTower1");
final Point point = MapcodeCodec.decode("\u30c1\u30ca.8\u30c1",
Territory.JPN);
assertEquals("decodeUnicode latitude", 35658660, point.getLatMicroDeg());
assertEquals("decodeUnicode longitude", 139745394,
point.getLonMicroDeg());
}
@Test
public void unicodeMapcodeTokyoTower2() throws Exception {
LOG.info("unicodeMapcodeTokyoTower2");
final Point point = MapcodeCodec.decode("JPN \u30c1\u30ca.8\u30c1");
assertEquals("decodeUnicode latitude", 35658660, point.getLatMicroDeg());
assertEquals("decodeUnicode longitude", 139745394,
point.getLonMicroDeg());
}
@Test
public void mapCodeWithZeroGroitzsch() throws Exception {
LOG.info("mapCodeWithZeroGroitzsch");
final Point point = MapcodeCodec.decode("HMVM.3Q0", Territory.DEU);
assertEquals("decodeUnicode latitude", 51154852, point.getLatMicroDeg());
assertEquals("decodeUnicode longitude", 12278574,
point.getLonMicroDeg());
}
@Test
public void validTerritory() throws Exception {
LOG.info("validTerritory");
final Point point0 = MapcodeCodec.decode("NLD 49.4V", null);
assertEquals("decode latitude", 52376514, point0.getLatMicroDeg());
assertEquals("decode longitude", 4908543, point0.getLonMicroDeg());
final Point point1 = MapcodeCodec.decode("NLD 49.4V", Territory.NLD);
assertEquals("decode latitude", 52376514, point1.getLatMicroDeg());
assertEquals("decode longitude", 4908543, point1.getLonMicroDeg());
final Point point2 = MapcodeCodec.decode("NLD 49.4V", Territory.USA);
assertEquals("decode latitude", 52376514, point2.getLatMicroDeg());
assertEquals("decode longitude", 4908543, point2.getLonMicroDeg());
final Point point3 = MapcodeCodec.decode("NLD 49.4V");
assertEquals("decode latitude", 52376514, point3.getLatMicroDeg());
assertEquals("decode longitude", 4908543, point3.getLonMicroDeg());
}
@Test(expected = IllegalArgumentException.class)
public void invalidNoDot() throws Exception {
LOG.info("invalidNoDot");
MapcodeCodec.decode("494V", Territory.NLD);
}
@Test(expected = IllegalArgumentException.class)
public void invalidDotLocation1() throws Exception {
LOG.info("invalidDotLocation1");
MapcodeCodec.decode("4.94V", Territory.NLD);
}
@Test(expected = IllegalArgumentException.class)
public void invalidDotLocation2() throws Exception {
LOG.info("invalidDotLocation2");
MapcodeCodec.decode("494.V", Territory.NLD);
}
@Test(expected = IllegalArgumentException.class)
public void invalidDotLocation3() throws Exception {
LOG.info("invalidDotLocation3");
MapcodeCodec.decode("494V49.4V", Territory.NLD);
}
@Test(expected = UnknownMapcodeException.class)
public void invalidMapcode1() throws Exception {
LOG.info("invalidMapcode1");
MapcodeCodec.decode("494.V49V", Territory.NLD);
}
@Test(expected = UnknownMapcodeException.class)
public void invalidMapcode2() throws Exception {
LOG.info("invalidMapcode2");
MapcodeCodec.decode("NLD L333.333", Territory.NLD);
}
@Test(expected = UnknownMapcodeException.class)
public void invalidMapcode3() throws Exception {
LOG.info("invalidMapcode3");
MapcodeCodec.decode("NLD SHH.HHH", Territory.NLD);
}
@Test(expected = UnknownMapcodeException.class)
public void invalidMapcode4() throws Exception {
LOG.info("invalidMapcode4");
MapcodeCodec.decode("NLD V11N.NZZ", Territory.NLD);
}
@Test(expected = IllegalArgumentException.class)
public void invalidHighPrecisionCharacter() throws Exception {
LOG.info("invalidHighPrecisionCharacter");
MapcodeCodec.decode("49.4V-Z", Territory.NLD);
}
@Test(expected = IllegalArgumentException.class)
public void invalidHighPrecisionCharacter2() throws Exception {
LOG.info("invalidHighPrecisionCharacter2");
MapcodeCodec.decode("49.4V-HZ", Territory.NLD);
}
@Test(expected = IllegalArgumentException.class)
public void invalidHighPrecisionCharacter3() throws Exception {
LOG.info("invalidHighPrecisionCharacter3");
MapcodeCodec.decode("\u0397\u03a0.\u03982-\u0411", Territory.GRC);
}
@Test(expected = IllegalArgumentException.class)
public void invalidHighPrecisionCharacter4() throws Exception {
LOG.info("invalidHighPrecisionCharacter4");
MapcodeCodec.decode("\u0397\u03a0.\u03982-\u0411\u0411", Territory.GRC);
}
@SuppressWarnings("ConstantConditions")
@Test(expected = IllegalArgumentException.class)
public void illegalArgument1() throws Exception {
LOG.info("illegalArgument1");
MapcodeCodec.decode(null, Territory.NLD);
}
@SuppressWarnings("ConstantConditions")
@Test(expected = UnknownMapcodeException.class)
public void illegalArgument2() throws Exception {
LOG.info("illegalArgument2");
MapcodeCodec.decode("494.V49V", null);
}
@SuppressWarnings("ConstantConditions")
@Test(expected = IllegalArgumentException.class)
public void illegalArgument3() throws Exception {
LOG.info("illegalArgument3");
MapcodeCodec.decode(null);
}
}