source: josm/trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionTest.java@ 5556

Last change on this file since 5556 was 5556, checked in by Don-vip, 11 years ago

see #8172 - fix JUnit tests

  • Property svn:eol-style set to native
File size: 3.2 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.Bounds;
9import org.openstreetmap.josm.data.coor.EastNorth;
10import org.openstreetmap.josm.data.coor.LatLon;
11
12public class ProjectionTest {
13
14 private static final boolean debug = false;
15 private static Random rand = new Random(System.currentTimeMillis());
16
17 boolean error;
18 String text;
19
20 @Test
21 public void proj() {
22 error = false;
23 text = "";
24
25 testProj(Projections.getProjectionByCode("EPSG:4326")); // WGS 84
26 testProj(Projections.getProjectionByCode("EPSG:3857")); // Mercator
27 if (!"yes".equals(System.getProperty("suppressPermanentFailure"))) {
28 testProj(Projections.getProjectionByCode("EPSG:3301")); // Lambert EST
29 }
30
31 for (int i=0; i<=3; ++i) {
32 testProj(Projections.getProjectionByCode("EPSG:"+Integer.toString(27561+i))); // Lambert 4 Zones France
33 }
34
35 for (int i=0; i<=4; ++i) {
36 testProj(Projections.getProjectionByCode("EPSG:"+Integer.toString(2176+i))); // PUWG Poland
37 }
38
39 testProj(Projections.getProjectionByCode("EPSG:21781")); // Swiss grid
40
41 for (int i=0; i<=60; ++i) {
42 testProj(Projections.getProjectionByCode("EPSG:"+Integer.toString(32601+i))); // UTM North
43 testProj(Projections.getProjectionByCode("EPSG:"+Integer.toString(32701+i))); // UTM South
44 }
45
46 if (!"yes".equals(System.getProperty("suppressPermanentFailure"))) {
47 for (int i=0; i<=4; ++i) {
48 testProj(Projections.getProjectionByCode("EPSG:"+Integer.toString(2969+i))); // UTM France DOM
49 }
50 }
51
52 for (int i=0; i<=8; ++i) {
53 testProj(Projections.getProjectionByCode("EPSG:"+Integer.toString(3942+i))); // Lambert CC9 Zones France
54 }
55
56 if (error) {
57 System.err.println(text);
58 Assert.fail();
59 }
60 }
61
62 private void testProj(Projection p) {
63 if (p != null) {
64 double maxErrLat = 0, maxErrLon = 0;
65 Bounds b = p.getWorldBoundsLatLon();
66
67 text += String.format("*** %s %s\n", p.toString(), p.toCode());
68 for (int num=0; num < 1000; ++num) {
69
70 double lat = rand.nextDouble() * (b.getMax().lat() - b.getMin().lat()) + b.getMin().lat();
71 double lon = rand.nextDouble() * (b.getMax().lon() - b.getMin().lon()) + b.getMin().lon();
72
73 LatLon ll = new LatLon(lat, lon);
74
75 for (int i=0; i<10; ++i) {
76 EastNorth en = p.latlon2eastNorth(ll);
77 ll = p.eastNorth2latlon(en);
78 }
79 maxErrLat = Math.max(maxErrLat, Math.abs(lat - ll.lat()));
80 maxErrLon = Math.max(maxErrLon, Math.abs(lon - ll.lon()));
81 }
82
83 String mark = "";
84 if (maxErrLat + maxErrLon > 1e-5) {
85 mark = "--FAILED-- ";
86 error = true;
87 }
88 text += String.format("%s errorLat: %s errorLon: %s\n", mark, maxErrLat, maxErrLon);
89 }
90 }
91}
Note: See TracBrowser for help on using the repository browser.