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

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

sonar - squid:S3578 - Test methods should comply with a naming convention

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