Changeset 7097 in josm for trunk/test/unit/org
- Timestamp:
- 2014-05-10T19:21:46+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/DefaultNameFormatterTest.java
r7096 r7097 2 2 package org.openstreetmap.josm.gui; 3 3 4 import static org.junit.Assert. assertTrue;4 import static org.junit.Assert.fail; 5 5 6 6 import java.io.FileInputStream; … … 9 9 import java.util.ArrayList; 10 10 import java.util.Arrays; 11 import java.util.Collection;12 import java.util.Collections;13 11 import java.util.Comparator; 14 import java.util.List;15 12 16 13 import org.junit.BeforeClass; … … 25 22 import org.openstreetmap.josm.io.IllegalDataException; 26 23 import org.openstreetmap.josm.io.OsmReader; 24 import org.xml.sax.SAXException; 27 25 28 26 /** … … 44 42 * @throws IllegalDataException 45 43 * @throws IOException 44 * @throws SAXException 46 45 */ 47 46 @Test 48 public void testTicket9632() throws IllegalDataException, IOException { 49 Collection<String> sources = new ArrayList<>(); 50 sources.add("resource://data/defaultpresets.xml"); 51 sources.add("http://josm.openstreetmap.de/josmfile?page=Presets/BicycleJunction&preset"); 52 TaggingPresetPreference.taggingPresets = TaggingPresetReader.readAll(sources, true); 47 public void testTicket9632() throws IllegalDataException, IOException, SAXException { 48 String source = "http://josm.openstreetmap.de/josmfile?page=Presets/BicycleJunction&preset"; 49 TaggingPresetPreference.taggingPresets = TaggingPresetReader.readAll(source, true); 53 50 54 51 Comparator<Relation> comparator = DefaultNameFormatter.getInstance().getRelationComparator(); … … 56 53 try (InputStream is = new FileInputStream(TestUtils.getTestDataRoot() + "regress/9632/data.osm.zip")) { 57 54 DataSet ds = OsmReader.parseDataSet(Compression.ZIP.getUncompressedInputStream(is), null); 58 List<Relation> relations = new ArrayList<>(ds.getRelations());59 System.out.println(Arrays.toString(relations .toArray()));55 Relation[] relations = new ArrayList<>(ds.getRelations()).toArray(new Relation[0]); 56 System.out.println(Arrays.toString(relations)); 60 57 // Check each compare possibility 61 for (int i=0; i<relations.size(); i++) { 62 long start = System.currentTimeMillis(); 63 Relation r1 = relations.get(i); 64 String r1s = r1.toString(); 65 for (int j=i; j<relations.size(); j++) { 66 Relation r2 = relations.get(j); 67 String r2s = r2.toString(); 58 for (int i=0; i<relations.length; i++) { 59 Relation r1 = relations[i]; 60 for (int j=i; j<relations.length; j++) { 61 Relation r2 = relations[j]; 68 62 int a = comparator.compare(r1, r2); 69 63 int b = comparator.compare(r2, r1); 70 String msg = "Compared\nr1: "+r1s+"\nr2: "+r2s+"gave: "+a+"/"+b;71 64 if (i==j || a==b) { 72 assertTrue(msg, a == 0 && b == 0); 65 if (a != 0 || b != 0) { 66 fail(getFailMessage(r1, r2, a, b)); 67 } 73 68 } else { 74 assertTrue(msg, a == -b); 69 if (a != -b) { 70 fail(getFailMessage(r1, r2, a, b)); 71 } 75 72 } 76 for (int k=j; k<relations.size(); k++) { 77 Relation r3 = relations.get(k); 78 String r3s = r3.toString(); 73 for (int k=j; k<relations.length; k++) { 74 Relation r3 = relations[k]; 79 75 int c = comparator.compare(r1, r3); 80 76 int d = comparator.compare(r2, r3); 81 String msg2 = msg + "\nCompared\nr1: "+r1s+"\nr3: "+r3s+"gave: "+c+"Compared\nr2: "+r2s+"\nr3: "+r3s+"gave: "+d;82 77 if (a > 0 && d > 0) { 83 assertTrue(msg2, c > 0); 78 if (c <= 0) { 79 fail(getFailMessage(r1, r2, r3, a, b, c, d)); 80 } 84 81 } else if (a == 0 && d == 0) { 85 assertTrue(msg2, c == 0); 82 if (c != 0) { 83 fail(getFailMessage(r1, r2, r3, a, b, c, d)); 84 } 86 85 } else if (a < 0 && d < 0) { 87 assertTrue(msg2, c < 0); 86 if (c >= 0) { 87 fail(getFailMessage(r1, r2, r3, a, b, c, d)); 88 } 88 89 } 89 90 } 90 91 } 91 long end = System.currentTimeMillis();92 System.out.println(i+"-> "+(end-start)+" ms");93 92 } 94 // Sort relation list95 Collections.sort(relations, comparator);93 // Sort relation array 94 Arrays.sort(relations, comparator); 96 95 } 97 96 } 97 98 private static String getFailMessage(Relation r1, Relation r2, int a, int b) { 99 return new StringBuilder("Compared\nr1: ").append(r1).append("\nr2: ") 100 .append(r2).append("\ngave: ").append(a).append("/").append(b) 101 .toString(); 102 } 103 104 private static String getFailMessage(Relation r1, Relation r2, Relation r3, int a, int b, int c, int d) { 105 return new StringBuilder(getFailMessage(r1, r2, a, b)) 106 .append("\nCompared\nr1: ").append(r1).append("\nr3: ").append(r3).append("\ngave: ").append(c) 107 .append("\nCompared\nr2: ").append(r2).append("\nr3: ").append(r3).append("\ngave: ").append(d) 108 .toString(); 109 } 98 110 }
Note:
See TracChangeset
for help on using the changeset viewer.