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

Last change on this file since 11241 was 10870, checked in by Don-vip, 8 years ago

fix #13408 - Clean up CustomProjection (patch by michael2402) - gsoc-core

  • Property svn:eol-style set to native
File size: 3.0 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.testutils.JOSMTestRules;
13
14import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15
16/**
17 * Tests for {@link CustomProjection}.
18 * @author Michael Zangl
19 */
20public class CustomProjectionTest {
21 /**
22 * Need pref to load pref.
23 */
24 @Rule
25 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
26 public JOSMTestRules test = new JOSMTestRules().preferences();
27
28 /**
29 * Test {@link CustomProjection#parseAngle(String, String)}
30 * @throws ProjectionConfigurationException in case of error
31 */
32 @Test
33 public void testParseAngle() throws ProjectionConfigurationException {
34 assertEquals(0, CustomProjection.parseAngle("0", "xxx"), 1e-10);
35 assertEquals(1, CustomProjection.parseAngle("1", "xxx"), 1e-10);
36 assertEquals(1.1, CustomProjection.parseAngle("1.1", "xxx"), 1e-10);
37
38 assertEquals(1, CustomProjection.parseAngle("1d", "xxx"), 1e-10);
39 assertEquals(1.1, CustomProjection.parseAngle("1.1d", "xxx"), 1e-10);
40
41 assertEquals(1 / 60.0, CustomProjection.parseAngle("1'", "xxx"), 1e-10);
42 assertEquals(1.1 / 60.0, CustomProjection.parseAngle("1.1'", "xxx"), 1e-10);
43
44 assertEquals(1 / 3600.0, CustomProjection.parseAngle("1\"", "xxx"), 1e-10);
45 assertEquals(1.1 / 3600.0, CustomProjection.parseAngle("1.1\"", "xxx"), 1e-10);
46
47 // negate
48 assertEquals(-1.1, CustomProjection.parseAngle("-1.1", "xxx"), 1e-10);
49 assertEquals(1.1, CustomProjection.parseAngle("1.1N", "xxx"), 1e-10);
50 assertEquals(1.1, CustomProjection.parseAngle("1.1E", "xxx"), 1e-10);
51 assertEquals(-1.1, CustomProjection.parseAngle("1.1S", "xxx"), 1e-10);
52 assertEquals(-1.1, CustomProjection.parseAngle("1.1W", "xxx"), 1e-10);
53 assertEquals(-1.1, CustomProjection.parseAngle("-1.1N", "xxx"), 1e-10);
54 assertEquals(-1.1, CustomProjection.parseAngle("-1.1E", "xxx"), 1e-10);
55 assertEquals(1.1, CustomProjection.parseAngle("-1.1S", "xxx"), 1e-10);
56 assertEquals(1.1, CustomProjection.parseAngle("-1.1W", "xxx"), 1e-10);
57
58 // combine
59 assertEquals(1.1 + 3 / 60.0 + 5.2 / 3600.0, CustomProjection.parseAngle("1.1d3'5.2\"", "xxx"), 1e-10);
60
61 // fail
62 Stream.of("", "-", "-N", "N", "1.1 ", "x", "1.1d1.1d", "1.1e", "1.1.1", ".1", "1.1d3\"5.2'").forEach(
63 s -> {
64 try {
65 CustomProjection.parseAngle(s, "xxxx");
66 fail("Expected exception for " + s);
67 } catch (ProjectionConfigurationException e) {
68 // good!
69 assertTrue(e.getMessage().contains("xxx"));
70 }
71 });
72 }
73}
Note: See TracBrowser for help on using the repository browser.