source: josm/trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxDistanceTest.java@ 15038

Last change on this file since 15038 was 15038, checked in by GerdP, 5 years ago

see #17616: adapt unit test

  • Property svn:eol-style set to native
File size: 4.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.gpx;
3
4import static org.junit.Assert.assertEquals;
5
6import org.junit.Rule;
7import org.junit.Test;
8import org.openstreetmap.josm.data.coor.EastNorth;
9import org.openstreetmap.josm.data.coor.LatLon;
10import org.openstreetmap.josm.data.osm.Node;
11import org.openstreetmap.josm.data.osm.Way;
12import org.openstreetmap.josm.testutils.JOSMTestRules;
13
14import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15
16/**
17 * Unit tests for class {@link GpxDistance}.
18 */
19public class GpxDistanceTest {
20
21 /**
22 * Setup test.
23 */
24 @Rule
25 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
26 public JOSMTestRules test = new JOSMTestRules().projection();
27
28 /**
29 * Unit test of method {@link GpxDistance#getDistanceWay}.
30 */
31 @Test
32 public void testGetDistanceWay() {
33 Node node1 = new Node();
34 Node node2 = new Node();
35 Way way = new Way();
36 node1.setCoor(new LatLon(0.5, 0));
37 node2.setCoor(new LatLon(-0.5, 0));
38 way.addNode(node1);
39 way.addNode(node2);
40
41 WayPoint waypoint = new WayPoint(new LatLon(0, 1));
42
43 double distance = GpxDistance.getDistanceWay(null, waypoint);
44 assertEquals(Double.MAX_VALUE, distance, 0.1);
45
46 distance = GpxDistance.getDistanceWay(way, null);
47 assertEquals(Double.MAX_VALUE, distance, 0.1);
48
49 distance = GpxDistance.getDistanceWay(null, null);
50 assertEquals(Double.MAX_VALUE, distance, 0.1);
51
52 distance = GpxDistance.getDistanceWay(way, waypoint);
53 /* 111319.49077 uses the WGS84/NAD38/GRS80 model for
54 * the distance between (0, 0) and (0, 1) */
55 assertEquals(111319.49077, distance, 0.1);
56 }
57
58 /**
59 * Unit test of method {@link GpxDistance#getDistanceNode}.
60 */
61 @Test
62 public void testGetDistanceNode() {
63 double distance = GpxDistance.getDistanceNode(null, null);
64 assertEquals(Double.MAX_VALUE, distance, 0.1);
65
66 Node node = new Node();
67 node.setCoor(new LatLon(0, 0));
68 distance = GpxDistance.getDistanceNode(node, null);
69 assertEquals(Double.MAX_VALUE, distance, 0.1);
70
71 WayPoint waypoint = new WayPoint(new LatLon(0, 0));
72 distance = GpxDistance.getDistanceNode(node, waypoint);
73 assertEquals(0.0, distance, 0.0001); // should be zero delta
74
75 distance = GpxDistance.getDistanceNode(null, waypoint);
76 assertEquals(Double.MAX_VALUE, distance, 0.1);
77
78 node.setCoor(new LatLon(1, 0));
79 distance = GpxDistance.getDistanceNode(node, waypoint);
80 /* 111319.49077 uses the WGS84/NAD38/GRS80 model for
81 * the distance between (0, 0) and (0, 1) */
82 assertEquals(111319.49077, distance, 0.1);
83 }
84
85 /**
86 * Unit test of method {@link GpxDistance#getDistanceEastNorth}.
87 */
88 @Test
89 public void testGetDistanceEastNorth() {
90 double distance = GpxDistance.getDistanceEastNorth(null, null);
91 assertEquals(Double.MAX_VALUE, distance, 0.1);
92
93 EastNorth en = new EastNorth(0, 0);
94 distance = GpxDistance.getDistanceEastNorth(en, null);
95 assertEquals(Double.MAX_VALUE, distance, 0.1);
96
97 WayPoint waypoint = new WayPoint(new LatLon(0, 0));
98 distance = GpxDistance.getDistanceEastNorth(en, waypoint);
99 assertEquals(0.0, distance, 0.0001); // should be zero delta
100
101 distance = GpxDistance.getDistanceEastNorth(null, waypoint);
102 assertEquals(Double.MAX_VALUE, distance, 0.1);
103
104 en = new EastNorth(0, 1);
105 distance = GpxDistance.getDistanceEastNorth(en, waypoint);
106 assertEquals(1, distance, 0.000001);
107 }
108
109
110 /**
111 * Unit test of method {@link GpxDistance#getDistanceLatLon}.
112 */
113 @Test
114 public void testGetDistanceLatLon() {
115 double distance = GpxDistance.getDistanceLatLon(null, null);
116 assertEquals(Double.MAX_VALUE, distance, 0.1);
117
118 LatLon ll = new LatLon(0, 0);
119 distance = GpxDistance.getDistanceLatLon(ll, null);
120 assertEquals(Double.MAX_VALUE, distance, 0.1);
121
122 WayPoint waypoint = new WayPoint(ll);
123 distance = GpxDistance.getDistanceLatLon(ll, waypoint);
124 assertEquals(0.0, distance, 0.0001); // should be zero delta
125
126 distance = GpxDistance.getDistanceLatLon(null, waypoint);
127 assertEquals(Double.MAX_VALUE, distance, 0.1);
128
129 ll = new LatLon(0, 1);
130 distance = GpxDistance.getDistanceLatLon(ll, waypoint);
131 /* 111319.49077 uses the WGS84/NAD38/GRS80 model for
132 * the distance between (0, 0) and (0, 1) */
133 assertEquals(111319.49077, distance, 0.1);
134 }
135}
Note: See TracBrowser for help on using the repository browser.