Changeset 5236 in josm for trunk/test/unit
- Timestamp:
- 2012-05-12T23:27:39+02:00 (13 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/data/projection
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRefTest.java
r4277 r5236 12 12 import java.util.LinkedHashMap; 13 13 import java.util.List; 14 import java.util.Map; 14 15 import java.util.Map.Entry; 15 16 … … 17 18 import org.openstreetmap.josm.data.coor.EastNorth; 18 19 import org.openstreetmap.josm.data.coor.LatLon; 20 import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice; 21 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 19 22 import org.openstreetmap.josm.tools.Utils; 20 23 … … 29 32 30 33 /** 31 * create a list of epsg codes and bounds to be used by 34 * create a list of epsg codes and bounds to be used by the perl script 32 35 * @param args 33 36 */ 34 37 public static void main(String[] args) { 35 HashMap<String, Projection> allCodes = new LinkedHashMap<String, Projection>(); 36 List<Projection> projs = Projections.getProjections(); 37 for (Projection p: projs) { 38 if (p instanceof ProjectionSubPrefs) { 39 for (String code : ((ProjectionSubPrefs)p).allCodes()) { 40 ProjectionSubPrefs projSub = recreateProj((ProjectionSubPrefs)p); 41 Collection<String> prefs = projSub.getPreferencesFromCode(code); 42 projSub.setPreferences(prefs); 43 allCodes.put(code, projSub); 44 } 45 } else { 46 allCodes.put(p.toCode(), p); 38 Map<String, Projection> allCodes = new HashMap<String, Projection>(); 39 for (ProjectionChoice pc : ProjectionPreference.getProjectionChoices()) { 40 for (String code : pc.allCodes()) { 41 Collection<String> pref = pc.getPreferencesFromCode(code); 42 pc.setPreferences(pref); 43 Projection p = pc.getProjection(); 44 allCodes.put(code, p); 47 45 } 48 46 } … … 51 49 } 52 50 } 53 54 private static ProjectionSubPrefs recreateProj(ProjectionSubPrefs proj) { 55 try { 56 return proj.getClass().newInstance(); 57 } catch (Exception e) { 58 throw new IllegalStateException( 59 tr("Cannot instantiate projection ''{0}''", proj.getClass().toString()), e); 60 } 61 } 62 51 63 52 @Test 64 53 public void test() throws IOException, FileNotFoundException { -
trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java
r5073 r5236 2 2 package org.openstreetmap.josm.data.projection; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 4 6 5 import java.io.BufferedReader; … … 12 11 import java.io.IOException; 13 12 import java.util.ArrayList; 14 import java.util.Arrays;15 13 import java.util.Collection; 16 import java.util.Collections;17 14 import java.util.HashMap; 18 15 import java.util.HashSet; 19 import java.util.LinkedHash Map;16 import java.util.LinkedHashSet; 20 17 import java.util.List; 21 18 import java.util.Map; … … 31 28 import org.openstreetmap.josm.data.coor.EastNorth; 32 29 import org.openstreetmap.josm.data.coor.LatLon; 33 import org.openstreetmap.josm.tools.Utils; 30 import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice; 31 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 34 32 import org.openstreetmap.josm.tools.Pair; 35 33 … … 58 56 public static void main(String[] args) throws IOException, FileNotFoundException { 59 57 setUp(); 60 Map<String, Projection> allCodes = new LinkedHashMap<String, Projection>(); 61 List<Projection> projs = Projections.getProjections(); 62 for (Projection p: projs) { 63 if (p instanceof ProjectionSubPrefs) { 64 for (String code : ((ProjectionSubPrefs)p).allCodes()) { 65 ProjectionSubPrefs projSub = recreateProj((ProjectionSubPrefs)p); 66 Collection<String> prefs = projSub.getPreferencesFromCode(code); 67 projSub.setPreferences(prefs); 68 allCodes.put(code, projSub); 69 } 70 } else { 71 allCodes.put(p.toCode(), p); 58 59 Map<String, Projection> supportedCodesMap = new HashMap<String, Projection>(); 60 for (ProjectionChoice pc : ProjectionPreference.getProjectionChoices()) { 61 for (String code : pc.allCodes()) { 62 Collection<String> pref = pc.getPreferencesFromCode(code); 63 pc.setPreferences(pref); 64 Projection p = pc.getProjection(); 65 supportedCodesMap.put(code, p); 72 66 } 73 67 } … … 77 71 prevData = readData(); 78 72 } 79 Map<String,TestData> prevCodes = new HashMap<String,TestData>();73 Map<String,TestData> prevCodesMap = new HashMap<String,TestData>(); 80 74 for (TestData data : prevData) { 81 prevCodes.put(data.code, data); 75 prevCodesMap.put(data.code, data); 76 } 77 78 Set<String> codesToWrite = new LinkedHashSet<String>(); 79 for (TestData data : prevData) { 80 if (supportedCodesMap.containsKey(data.code)) { 81 codesToWrite.add(data.code); 82 } 83 } 84 for (String code : supportedCodesMap.keySet()) { 85 if (!codesToWrite.contains(code)) { 86 codesToWrite.add(code); 87 } 82 88 } 83 89 … … 86 92 out.write("# Data for test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java\n"); 87 93 out.write("# Format: 1. Projection code; 2. lat/lon; 3. lat/lon projected -> east/north; 4. east/north (3.) inverse projected\n"); 88 for (Entry<String, Projection> e : allCodes.entrySet()) { 89 Projection proj = e.getValue(); 94 for (Entry<String, Projection> e : supportedCodesMap.entrySet()) { 95 } 96 for (String code : codesToWrite) { 97 Projection proj = supportedCodesMap.get(code); 90 98 Bounds b = proj.getWorldBoundsLatLon(); 91 99 double lat, lon; 92 TestData prev = prevCodes .get(proj.toCode());100 TestData prev = prevCodesMap.get(proj.toCode()); 93 101 if (prev != null) { 94 102 lat = prev.ll.lat(); … … 103 111 } 104 112 out.close(); 105 }106 107 private static ProjectionSubPrefs recreateProj(ProjectionSubPrefs proj) {108 try {109 return proj.getClass().newInstance();110 } catch (Exception e) {111 throw new IllegalStateException(112 tr("Cannot instantiate projection ''{0}''", proj.getClass().toString()), e);113 }114 113 } 115 114 … … 163 162 StringBuilder fail = new StringBuilder(); 164 163 165 List<Projection> projs = Projections.getProjections(); 166 for (Projection p: projs) { 167 Collection<String> codes = null; 168 if (p instanceof ProjectionSubPrefs) { 169 codes = Arrays.asList(((ProjectionSubPrefs)p).allCodes()); 170 } else { 171 codes = Collections.singleton(p.toCode()); 172 } 173 for (String code : codes) { 164 for (ProjectionChoice pc : ProjectionPreference.getProjectionChoices()) { 165 for (String code : pc.allCodes()) { 174 166 if (!dataCodes.contains(code)) { 175 167 fail.append("Did not find projection "+code+" in test data!\n"); -
trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionTest.java
r4837 r5236 2 2 package org.openstreetmap.josm.data.projection; 3 3 4 import java.util.Collections;5 4 import java.util.Random; 6 5 … … 30 29 } 31 30 32 Lambert lam = new Lambert(); 33 for (int zone=1; zone<=4; ++zone) { 34 lam.setPreferences(Collections.singletonList(Integer.toString(zone))); 35 testProj(lam); 31 for (int i=0; i<=3; ++i) { 32 testProj(new Lambert(i)); 36 33 } 37 34 38 Puwg puwg = new Puwg(); 39 for (PuwgData pd : Puwg.Zones) { 40 puwg.setPreferences(Collections.singletonList(pd.toCode())); 41 testProj(puwg); 35 for (int i=0; i<=4; ++i) { 36 testProj(new Puwg(i)); 42 37 } 43 38 44 39 testProj(new SwissGrid()); 45 40 46 UTM utm = new UTM();47 41 for (int i=0; i<=6; ++i) { 48 42 int zone; 49 43 if (i==0) { 50 zone = 0;44 zone = 1; 51 45 } else if (i==6) { 52 zone = 59;46 zone = 60; 53 47 } else { 54 zone = rand.nextInt(60) ;48 zone = rand.nextInt(60) + 1; 55 49 } 56 utm.setPreferences(Collections.singletonList(Integer.toString(zone))); 57 testProj(utm); 58 50 UTM.Hemisphere hem = rand.nextBoolean() ? UTM.Hemisphere.North : UTM.Hemisphere.South; 51 testProj(new UTM(zone, hem)); 59 52 } 60 53 61 54 if (!"yes".equals(System.getProperty("suppressPermanentFailure"))) { 62 UTM_France_DOM utmFr = new UTM_France_DOM(); 63 for (int zone=1; zone<=5; ++zone) { 64 utmFr.setPreferences(Collections.singletonList(Integer.toString(zone))); 65 testProj(utmFr); 55 for (int i=0; i<=4; ++i) { 56 testProj(new UTM_France_DOM(i)); 66 57 } 67 58 } 68 59 69 LambertCC9Zones lamCC9 = new LambertCC9Zones(); 70 for (int i=1; i<=9; ++i) { 71 lamCC9.setPreferences(Collections.singletonList(Integer.toString(i))); 72 testProj(lamCC9); 60 for (int i=0; i<=8; ++i) { 61 testProj(new LambertCC9Zones(i)); 73 62 } 74 63
Note:
See TracChangeset
for help on using the changeset viewer.