source: josm/trunk/test/unit/org/openstreetmap/josm/data/projection/EllipsoidTest.java@ 17360

Last change on this file since 17360 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.projection;
3
4import java.security.SecureRandom;
5import java.util.Random;
6
7import org.junit.Assert;
8import org.junit.jupiter.api.Test;
9import org.openstreetmap.josm.data.coor.LatLon;
10
11/**
12 * Unit tests for class {@link Ellipsoid}.
13 */
14class EllipsoidTest {
15
16 private static final double EPSILON = 1e-8;
17
18 /**
19 * convert latlon to cartesian coordinates back and forth
20 */
21 @Test
22 void testLatLon2Cart2LatLon() {
23 Random r = new SecureRandom();
24 double maxErrLat = 0, maxErrLon = 0;
25 Ellipsoid ellips = Ellipsoid.WGS84;
26 for (int num = 0; num < 1000; ++num) {
27
28 double lat = r.nextDouble() * 180.0 - 90.0;
29 double lon = r.nextDouble() * 360.0 - 180.0;
30 LatLon ll = new LatLon(lat, lon);
31
32 for (int i = 0; i < 1000; ++i) {
33 double[] cart = ellips.latLon2Cart(ll);
34 ll = ellips.cart2LatLon(cart);
35
36 if (!(Math.abs(lat - ll.lat()) < EPSILON && Math.abs(lon - ll.lon()) < EPSILON)) {
37 String error = String.format("point: %s iterations: %s current: %s errorLat: %s errorLon %s",
38 new LatLon(lat, lon), i, ll, Math.abs(lat - ll.lat()), Math.abs(lon - ll.lon()));
39 System.err.println(error);
40 Assert.fail();
41 }
42 }
43
44 maxErrLat = Math.max(maxErrLat, Math.abs(lat - ll.lat()));
45 maxErrLon = Math.max(maxErrLon, Math.abs(lon - ll.lon()));
46 }
47 }
48}
Note: See TracBrowser for help on using the repository browser.