1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.projection;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
6 | import static org.junit.jupiter.api.Assertions.fail;
|
---|
7 |
|
---|
8 | import java.util.stream.Stream;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
11 | import org.openstreetmap.josm.data.projection.CustomProjection.Polarity;
|
---|
12 | import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
---|
13 |
|
---|
14 | import org.junit.jupiter.api.Test;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Tests for {@link CustomProjection}.
|
---|
18 | * @author Michael Zangl
|
---|
19 | */
|
---|
20 | // Need pref to load pref
|
---|
21 | @BasicPreferences
|
---|
22 | class CustomProjectionTest {
|
---|
23 | /**
|
---|
24 | * Test {@link CustomProjection#parseAngle(String, String)}
|
---|
25 | * @throws ProjectionConfigurationException in case of error
|
---|
26 | */
|
---|
27 | @Test
|
---|
28 | void testParseAngle() throws ProjectionConfigurationException {
|
---|
29 | assertEquals(0, CustomProjection.parseAngle("0", "xxx"), 1e-10);
|
---|
30 | assertEquals(1, CustomProjection.parseAngle("1", "xxx"), 1e-10);
|
---|
31 | assertEquals(1.1, CustomProjection.parseAngle("1.1", "xxx"), 1e-10);
|
---|
32 |
|
---|
33 | assertEquals(1, CustomProjection.parseAngle("1d", "xxx"), 1e-10);
|
---|
34 | assertEquals(1.1, CustomProjection.parseAngle("1.1d", "xxx"), 1e-10);
|
---|
35 |
|
---|
36 | assertEquals(1 / 60.0, CustomProjection.parseAngle("1'", "xxx"), 1e-10);
|
---|
37 | assertEquals(1.1 / 60.0, CustomProjection.parseAngle("1.1'", "xxx"), 1e-10);
|
---|
38 |
|
---|
39 | assertEquals(1 / 3600.0, CustomProjection.parseAngle("1\"", "xxx"), 1e-10);
|
---|
40 | assertEquals(1.1 / 3600.0, CustomProjection.parseAngle("1.1\"", "xxx"), 1e-10);
|
---|
41 |
|
---|
42 | // negate
|
---|
43 | assertEquals(-1.1, CustomProjection.parseAngle("-1.1", "xxx"), 1e-10);
|
---|
44 | assertEquals(1.1, CustomProjection.parseAngle("1.1N", "xxx"), 1e-10);
|
---|
45 | assertEquals(1.1, CustomProjection.parseAngle("1.1E", "xxx"), 1e-10);
|
---|
46 | assertEquals(-1.1, CustomProjection.parseAngle("1.1S", "xxx"), 1e-10);
|
---|
47 | assertEquals(-1.1, CustomProjection.parseAngle("1.1W", "xxx"), 1e-10);
|
---|
48 | assertEquals(-1.1, CustomProjection.parseAngle("-1.1N", "xxx"), 1e-10);
|
---|
49 | assertEquals(-1.1, CustomProjection.parseAngle("-1.1E", "xxx"), 1e-10);
|
---|
50 | assertEquals(1.1, CustomProjection.parseAngle("-1.1S", "xxx"), 1e-10);
|
---|
51 | assertEquals(1.1, CustomProjection.parseAngle("-1.1W", "xxx"), 1e-10);
|
---|
52 |
|
---|
53 | // combine
|
---|
54 | assertEquals(1.1 + 3 / 60.0 + 5.2 / 3600.0, CustomProjection.parseAngle("1.1d3'5.2\"", "xxx"), 1e-10);
|
---|
55 |
|
---|
56 | assertEquals(1.1, CustomProjection.parseAngle("1.1dN", "xxx"), 1e-10);
|
---|
57 | assertEquals(-1.1, CustomProjection.parseAngle("1.1dS", "xxx"), 1e-10);
|
---|
58 | assertEquals(1.1, CustomProjection.parseAngle("1.1dE", "xxx"), 1e-10);
|
---|
59 | assertEquals(-1.1, CustomProjection.parseAngle("1.1dW", "xxx"), 1e-10);
|
---|
60 |
|
---|
61 | assertEquals(49.5, CustomProjection.parseAngle("49d30'N", "xxx"), 1e-10);
|
---|
62 | assertEquals(-120.8333333333, CustomProjection.parseAngle("120.0d50'W", "xxx"), 1e-10);
|
---|
63 |
|
---|
64 | // fail
|
---|
65 | Stream.of("", "-", "-N", "N", "1.1 ", "x", "1.1d1.1d", "1.1e", "1.1.1", ".1", "1.1d3\"5.2'").forEach(
|
---|
66 | s -> {
|
---|
67 | try {
|
---|
68 | CustomProjection.parseAngle(s, "xxxx");
|
---|
69 | fail("Expected exception for " + s);
|
---|
70 | } catch (ProjectionConfigurationException e) {
|
---|
71 | // good!
|
---|
72 | assertTrue(e.getMessage().contains("xxx"));
|
---|
73 | }
|
---|
74 | });
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Test {@link CustomProjection.Polarity}.
|
---|
79 | */
|
---|
80 | @Test
|
---|
81 | void testPolarity() {
|
---|
82 | assertEquals(LatLon.NORTH_POLE, Polarity.NORTH.getLatLon());
|
---|
83 | assertEquals(LatLon.SOUTH_POLE, Polarity.SOUTH.getLatLon());
|
---|
84 | }
|
---|
85 | }
|
---|