|
1 | 1 | package mil.nga.mgrs; |
2 | 2 |
|
3 | 3 | import static org.junit.Assert.assertEquals; |
| 4 | +import static org.junit.Assert.assertFalse; |
| 5 | +import static org.junit.Assert.assertNotNull; |
| 6 | +import static org.junit.Assert.assertNull; |
4 | 7 | import static org.junit.Assert.assertTrue; |
| 8 | +import static org.junit.Assert.fail; |
5 | 9 |
|
6 | 10 | import java.text.ParseException; |
7 | 11 |
|
8 | 12 | import org.junit.Test; |
9 | 13 |
|
10 | 14 | import mil.nga.mgrs.features.Point; |
11 | 15 | import mil.nga.mgrs.grid.GridType; |
| 16 | +import mil.nga.mgrs.gzd.GridRange; |
| 17 | +import mil.nga.mgrs.gzd.GridZone; |
12 | 18 | import mil.nga.mgrs.utm.UTM; |
13 | 19 |
|
14 | 20 | /** |
@@ -315,6 +321,114 @@ public void testCoordinate() throws ParseException { |
315 | 321 |
|
316 | 322 | } |
317 | 323 |
|
| 324 | + /** |
| 325 | + * Test parsing GZD coordinates |
| 326 | + * |
| 327 | + * @throws ParseException |
| 328 | + * upon failure to parse |
| 329 | + */ |
| 330 | + @Test |
| 331 | + public void testGZDParse() throws ParseException { |
| 332 | + |
| 333 | + GridRange gridRange = new GridRange(); |
| 334 | + |
| 335 | + for (GridZone zone : gridRange) { |
| 336 | + |
| 337 | + int zoneNumber = zone.getNumber(); |
| 338 | + char bandLetter = zone.getLetter(); |
| 339 | + |
| 340 | + String gzd = String.valueOf(zoneNumber) + bandLetter; |
| 341 | + assertTrue(MGRS.isMGRS(gzd)); |
| 342 | + MGRS mgrs = MGRS.parse(gzd); |
| 343 | + assertNotNull(mgrs); |
| 344 | + assertEquals(zoneNumber, mgrs.getZone()); |
| 345 | + assertEquals(bandLetter, mgrs.getBand()); |
| 346 | + |
| 347 | + Point point = mgrs.toPoint(); |
| 348 | + Point southwest = zone.getBounds().getSouthwest(); |
| 349 | + |
| 350 | + assertEquals(point.getLongitude(), southwest.getLongitude(), |
| 351 | + 0.0001); |
| 352 | + assertEquals(point.getLatitude(), southwest.getLatitude(), 0.0001); |
| 353 | + |
| 354 | + } |
| 355 | + |
| 356 | + } |
| 357 | + |
| 358 | + /** |
| 359 | + * Test parsing a Svalbard MGRS string values |
| 360 | + * |
| 361 | + * @throws ParseException |
| 362 | + * upon failure to parse |
| 363 | + */ |
| 364 | + @Test |
| 365 | + public void testSvalbardParse() throws ParseException { |
| 366 | + |
| 367 | + assertTrue(MGRS.isMGRS("31X")); |
| 368 | + assertNotNull(MGRS.parse("31X")); |
| 369 | + assertFalse(MGRS.isMGRS("32X")); |
| 370 | + try { |
| 371 | + assertNull(MGRS.parse("32X")); |
| 372 | + fail("Expected parse exception"); |
| 373 | + } catch (ParseException e) { |
| 374 | + } |
| 375 | + assertFalse(MGRS.isMGRS("32XMH")); |
| 376 | + try { |
| 377 | + MGRS.parse("32XMH"); |
| 378 | + fail("Expected parse exception"); |
| 379 | + } catch (ParseException e) { |
| 380 | + } |
| 381 | + assertFalse(MGRS.isMGRS("32XMH11")); |
| 382 | + try { |
| 383 | + MGRS.parse("32XMH11"); |
| 384 | + fail("Expected parse exception"); |
| 385 | + } catch (ParseException e) { |
| 386 | + } |
| 387 | + assertFalse(MGRS.isMGRS("32XMH1111")); |
| 388 | + try { |
| 389 | + MGRS.parse("32XMH1111"); |
| 390 | + fail("Expected parse exception"); |
| 391 | + } catch (ParseException e) { |
| 392 | + } |
| 393 | + assertFalse(MGRS.isMGRS("32XMH111111")); |
| 394 | + try { |
| 395 | + MGRS.parse("32XMH111111"); |
| 396 | + fail("Expected parse exception"); |
| 397 | + } catch (ParseException e) { |
| 398 | + } |
| 399 | + assertFalse(MGRS.isMGRS("32XMH11111111")); |
| 400 | + try { |
| 401 | + MGRS.parse("32XMH11111111"); |
| 402 | + fail("Expected parse exception"); |
| 403 | + } catch (ParseException e) { |
| 404 | + } |
| 405 | + assertFalse(MGRS.isMGRS("32XMH111111111")); |
| 406 | + try { |
| 407 | + MGRS.parse("32XMH111111111"); |
| 408 | + fail("Expected parse exception"); |
| 409 | + } catch (ParseException e) { |
| 410 | + } |
| 411 | + assertTrue(MGRS.isMGRS("33X")); |
| 412 | + assertNotNull(MGRS.parse("33X")); |
| 413 | + assertFalse(MGRS.isMGRS("34X")); |
| 414 | + try { |
| 415 | + assertNull(MGRS.parse("34X")); |
| 416 | + fail("Expected parse exception"); |
| 417 | + } catch (ParseException e) { |
| 418 | + } |
| 419 | + assertTrue(MGRS.isMGRS("35X")); |
| 420 | + assertNotNull(MGRS.parse("35X")); |
| 421 | + assertFalse(MGRS.isMGRS("36X")); |
| 422 | + try { |
| 423 | + assertNull(MGRS.parse("36X")); |
| 424 | + fail("Expected parse exception"); |
| 425 | + } catch (ParseException e) { |
| 426 | + } |
| 427 | + assertTrue(MGRS.isMGRS("37X")); |
| 428 | + assertNotNull(MGRS.parse("37X")); |
| 429 | + |
| 430 | + } |
| 431 | + |
318 | 432 | /** |
319 | 433 | * Test the WGS84 coordinate with expected MGSR coordinate |
320 | 434 | * |
|
0 commit comments