Ignore:
Timestamp:
2012-05-12T23:27:39+02:00 (12 years ago)
Author:
bastiK
Message:
  • removed offset option from UTM which is probably rarely used. (custom projection can be used for this now, e.g. +proj=tmerc +lon_0=-3 +k_0=0.9996 +x_0=3500000 or +init=epsg:32630 +x_0=3500000)
  • fixed tests
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  
    1212import java.util.LinkedHashMap;
    1313import java.util.List;
     14import java.util.Map;
    1415import java.util.Map.Entry;
    1516
     
    1718import org.openstreetmap.josm.data.coor.EastNorth;
    1819import org.openstreetmap.josm.data.coor.LatLon;
     20import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice;
     21import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
    1922import org.openstreetmap.josm.tools.Utils;
    2023
     
    2932
    3033    /**
    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
    3235     * @param args
    3336     */
    3437    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);
    4745            }
    4846        }
     
    5149        }
    5250    }
    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 
    6352    @Test
    6453    public void test() throws IOException, FileNotFoundException {
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java

    r5073 r5236  
    22package org.openstreetmap.josm.data.projection;
    33
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    54
    65import java.io.BufferedReader;
     
    1211import java.io.IOException;
    1312import java.util.ArrayList;
    14 import java.util.Arrays;
    1513import java.util.Collection;
    16 import java.util.Collections;
    1714import java.util.HashMap;
    1815import java.util.HashSet;
    19 import java.util.LinkedHashMap;
     16import java.util.LinkedHashSet;
    2017import java.util.List;
    2118import java.util.Map;
     
    3128import org.openstreetmap.josm.data.coor.EastNorth;
    3229import org.openstreetmap.josm.data.coor.LatLon;
    33 import org.openstreetmap.josm.tools.Utils;
     30import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice;
     31import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
    3432import org.openstreetmap.josm.tools.Pair;
    3533
     
    5856    public static void main(String[] args) throws IOException, FileNotFoundException {
    5957        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);
    7266            }
    7367        }
     
    7771            prevData = readData();
    7872        }
    79         Map<String,TestData> prevCodes = new HashMap<String,TestData>();
     73        Map<String,TestData> prevCodesMap = new HashMap<String,TestData>();
    8074        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            }
    8288        }
    8389
     
    8692        out.write("# Data for test/unit/org/openstreetmap/josm/data/projection/ProjectionRegressionTest.java\n");
    8793        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);
    9098            Bounds b = proj.getWorldBoundsLatLon();
    9199            double lat, lon;
    92             TestData prev = prevCodes.get(proj.toCode());
     100            TestData prev = prevCodesMap.get(proj.toCode());
    93101            if (prev != null) {
    94102                lat = prev.ll.lat();
     
    103111        }
    104112        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         }
    114113    }
    115114
     
    163162        StringBuilder fail = new StringBuilder();
    164163
    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()) {
    174166               if (!dataCodes.contains(code)) {
    175167                    fail.append("Did not find projection "+code+" in test data!\n");
  • trunk/test/unit/org/openstreetmap/josm/data/projection/ProjectionTest.java

    r4837 r5236  
    22package org.openstreetmap.josm.data.projection;
    33
    4 import java.util.Collections;
    54import java.util.Random;
    65
     
    3029        }
    3130
    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));
    3633        }
    3734
    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));
    4237        }
    4338
    4439        testProj(new SwissGrid());
    4540
    46         UTM utm = new UTM();
    4741        for (int i=0; i<=6; ++i) {
    4842            int zone;
    4943            if (i==0) {
    50                 zone = 0;
     44                zone = 1;
    5145            } else if (i==6) {
    52                 zone = 59;
     46                zone = 60;
    5347            } else {
    54                 zone = rand.nextInt(60);
     48                zone = rand.nextInt(60) + 1;
    5549            }
    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));
    5952        }
    6053
    6154        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));
    6657            }
    6758        }
    6859
    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));
    7362        }
    7463
Note: See TracChangeset for help on using the changeset viewer.