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
205 lines (177 loc) · 8.04 KB
/
Copy pathDecoderTest.java
File metadata and controls
205 lines (177 loc) · 8.04 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
/*
* Copyright (C) 2014 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 decodeTomTomOffice1() throws Exception {
LOG.info("decodeTomTomOffice1");
final Point point = MapcodeCodec.decode("49.4V", Territory.NLD);
assertEquals("decodeTomTomOffice latitude", 52376514, point.getLatMicroDeg());
assertEquals("decodeTomTomOffice longitude", 4908542, point.getLonMicroDeg());
}
@Test
public void decodeTomTomOffice2() throws Exception {
LOG.info("decodeTomTomOffice2");
final Point point = MapcodeCodec.decode("NLD 49.4V");
assertEquals("decodeTomTomOffice latitude", 52376514, point.getLatMicroDeg());
assertEquals("decodeTomTomOffice longitude", 4908542, point.getLonMicroDeg());
}
@Test
public void highPrecisionTomTomOffice1() throws Exception {
LOG.info("highPrecisionTomTomOffice1");
final Point point = MapcodeCodec.decode("49.4V-K2", Territory.NLD);
assertEquals("decodeTomTomOffice hi-precision latitude", 52376512, point.getLatMicroDeg());
assertEquals("decodeTomTomOffice hi-precision longitude", 4908540, point.getLonMicroDeg());
}
@Test
public void highPrecisionTomTomOffice2() throws Exception {
LOG.info("highPrecisionTomTomOffice2");
final Point point = MapcodeCodec.decode("NLD 49.4V-K2");
assertEquals("decodeTomTomOffice hi-precision latitude", 52376512, point.getLatMicroDeg());
assertEquals("decodeTomTomOffice hi-precision longitude", 4908540, 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", 37971844, 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", 37971844, 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 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(expected = IllegalArgumentException.class)
public void invalidTerritory() throws Exception {
LOG.info("invalidTerritory");
MapcodeCodec.decode("NLD 49.4V", Territory.NLD);
}
@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.V494V", 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 = IllegalArgumentException.class)
public void illegalArgument2() throws Exception {
LOG.info("illegalArgument2");
MapcodeCodec.decode("494.V494V", null);
}
@SuppressWarnings("ConstantConditions")
@Test(expected = IllegalArgumentException.class)
public void illegalArgument3() throws Exception {
LOG.info("illegalArgument3");
MapcodeCodec.decode(null);
}
}