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

Last change on this file was 18690, checked in by taylor.smock, 14 months ago

See #16567: Convert all assertion calls to JUnit 5 (patch by gaben, modified)

The modifications are as follows:

  • Merge DomainValidatorTest.testIDN and DomainValidatorTest.testIDNJava6OrLater
  • Update some tests to use @ParameterizedTest (DomainValidatorTest)
  • Replace various exception blocks with assertThrows. These typically looked like
        try {
            // Something that should throw an exception here
            fail("An exception should have been thrown");
        } catch (Exception e) {
            // Verify the exception matches expectations here
        }
    
  • Replace assertTrue(val instanceof Clazz) with assertInstanceOf
  • Replace JUnit 4 @Suite with JUnit 5 @Suite

Both the original patch and the modified patch fix various lint issues.

  • 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 static org.junit.jupiter.api.Assertions.fail;
5
6import java.security.SecureRandom;
7import java.util.Random;
8
9import org.junit.jupiter.api.Test;
10import org.openstreetmap.josm.data.coor.LatLon;
11
12/**
13 * Unit tests for class {@link Ellipsoid}.
14 */
15class EllipsoidTest {
16
17 private static final double EPSILON = 1.5e-8;
18
19 /**
20 * convert latlon to cartesian coordinates back and forth
21 */
22 @Test
23 void testLatLon2Cart2LatLon() {
24 Random r = new SecureRandom();
25 double maxErrLat = 0, maxErrLon = 0;
26 Ellipsoid ellips = Ellipsoid.WGS84;
27 for (int num = 0; num < 1000; ++num) {
28
29 double lat = r.nextDouble() * 180.0 - 90.0;
30 double lon = r.nextDouble() * 360.0 - 180.0;
31 LatLon ll = new LatLon(lat, lon);
32
33 for (int i = 0; i < 1000; ++i) {
34 double[] cart = ellips.latLon2Cart(ll);
35 ll = ellips.cart2LatLon(cart);
36
37 if (!(Math.abs(lat - ll.lat()) < EPSILON && Math.abs(lon - ll.lon()) < EPSILON)) {
38 String error = String.format("point: %s iterations: %s current: %s errorLat: %s errorLon %s",
39 new LatLon(lat, lon), i, ll, Math.abs(lat - ll.lat()), Math.abs(lon - ll.lon()));
40 fail(error);
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.