source: josm/trunk/test/unit/org/openstreetmap/josm/data/projection/CustomProjectionTest.java@ 11931

Last change on this file since 11931 was 11931, checked in by Don-vip, 7 years ago

improve unit test coverage

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.projection;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6import static org.junit.Assert.fail;
7
8import java.util.stream.Stream;
9
10import org.junit.Rule;
11import org.junit.Test;
12import org.openstreetmap.josm.data.coor.LatLon;
13import org.openstreetmap.josm.data.projection.CustomProjection.Polarity;
14import org.openstreetmap.josm.testutils.JOSMTestRules;
15
16import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
17
18/**
19 * Tests for {@link CustomProjection}.
20 * @author Michael Zangl
21 */
22public class CustomProjectionTest {
23 /**
24 * Need pref to load pref.
25 */
26 @Rule
27 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
28 public JOSMTestRules test = new JOSMTestRules().preferences();
29
30 /**
31 * Test {@link CustomProjection#parseAngle(String, String)}
32 * @throws ProjectionConfigurationException in case of error
33 */
34 @Test
35 public void testParseAngle() throws ProjectionConfigurationException {
36 assertEquals(0, CustomProjection.parseAngle("0", "xxx"), 1e-10);
37 assertEquals(1, CustomProjection.parseAngle("1", "xxx"), 1e-10);
38 assertEquals(1.1, CustomProjection.parseAngle("1.1", "xxx"), 1e-10);
39
40 assertEquals(1, CustomProjection.parseAngle("1d", "xxx"), 1e-10);
41 assertEquals(1.1, CustomProjection.parseAngle("1.1d", "xxx"), 1e-10);
42
43 assertEquals(1 / 60.0, CustomProjection.parseAngle("1'", "xxx"), 1e-10);
44 assertEquals(1.1 / 60.0, CustomProjection.parseAngle("1.1'", "xxx"), 1e-10);
45
46 assertEquals(1 / 3600.0, CustomProjection.parseAngle("1\"", "xxx"), 1e-10);
47 assertEquals(1.1 / 3600.0, CustomProjection.parseAngle("1.1\"", "xxx"), 1e-10);
48
49 // negate
50 assertEquals(-1.1, CustomProjection.parseAngle("-1.1", "xxx"), 1e-10);
51 assertEquals(1.1, CustomProjection.parseAngle("1.1N", "xxx"), 1e-10);
52 assertEquals(1.1, CustomProjection.parseAngle("1.1E", "xxx"), 1e-10);
53 assertEquals(-1.1, CustomProjection.parseAngle("1.1S", "xxx"), 1e-10);
54 assertEquals(-1.1, CustomProjection.parseAngle("1.1W", "xxx"), 1e-10);
55 assertEquals(-1.1, CustomProjection.parseAngle("-1.1N", "xxx"), 1e-10);
56 assertEquals(-1.1, CustomProjection.parseAngle("-1.1E", "xxx"), 1e-10);
57 assertEquals(1.1, CustomProjection.parseAngle("-1.1S", "xxx"), 1e-10);
58 assertEquals(1.1, CustomProjection.parseAngle("-1.1W", "xxx"), 1e-10);
59
60 // combine
61 assertEquals(1.1 + 3 / 60.0 + 5.2 / 3600.0, CustomProjection.parseAngle("1.1d3'5.2\"", "xxx"), 1e-10);
62
63 // fail
64 Stream.of("", "-", "-N", "N", "1.1 ", "x", "1.1d1.1d", "1.1e", "1.1.1", ".1", "1.1d3\"5.2'").forEach(
65 s -> {
66 try {
67 CustomProjection.parseAngle(s, "xxxx");
68 fail("Expected exception for " + s);
69 } catch (ProjectionConfigurationException e) {
70 // good!
71 assertTrue(e.getMessage().contains("xxx"));
72 }
73 });
74 }
75
76 /**
77 * Test {@link CustomProjection.Polarity}.
78 */
79 @Test
80 public void testPolarity() {
81 assertEquals(LatLon.NORTH_POLE, Polarity.NORTH.getLatLon());
82 assertEquals(LatLon.SOUTH_POLE, Polarity.SOUTH.getLatLon());
83 }
84}
Note: See TracBrowser for help on using the repository browser.