Changeset 15431 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2019-10-06T14:47:39+02:00 (5 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/actions/SimplifyWayActionTest.java
r15419 r15431 4 4 import static org.junit.Assert.assertEquals; 5 5 import static org.junit.Assert.assertNotNull; 6 import static org.junit.Assert.assertTrue;7 6 7 import java.io.IOException; 8 import java.nio.file.Files; 9 import java.nio.file.Paths; 10 import java.util.ArrayList; 8 11 import java.util.Collection; 9 12 import java.util.Collections; 13 import java.util.Comparator; 14 import java.util.List; 15 import java.util.stream.Collectors; 10 16 import java.util.stream.Stream; 11 17 … … 13 19 import org.junit.Rule; 14 20 import org.junit.Test; 21 import org.openstreetmap.josm.TestUtils; 15 22 import org.openstreetmap.josm.command.DeleteCommand; 16 23 import org.openstreetmap.josm.command.SequenceCommand; … … 20 27 import org.openstreetmap.josm.data.osm.Way; 21 28 import org.openstreetmap.josm.gui.MainApplication; 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 29 import org.openstreetmap.josm.io.IllegalDataException; 30 import org.openstreetmap.josm.io.OsmReader; 23 31 import org.openstreetmap.josm.testutils.JOSMTestRules; 24 32 import org.openstreetmap.josm.tools.Utils; … … 52 60 } 53 61 54 private static Way createWaySelected(DataSet ds, double latStart) { 55 Node n1 = new Node(new LatLon(latStart, 1.0)); 56 ds.addPrimitive(n1); 57 Node n2 = new Node(new LatLon(latStart+1.0, 1.0)); 58 ds.addPrimitive(n2); 59 Way w = new Way(); 60 w.addNode(n1); 61 w.addNode(n2); 62 ds.addPrimitive(w); 63 ds.addSelected(w); 64 return w; 62 private DataSet getDs(String file) throws IllegalDataException, IOException { 63 return OsmReader.parseDataSet(Files.newInputStream(Paths.get(TestUtils.getTestDataRoot(), "tracks/" + file + ".osm")), null); 65 64 } 66 65 67 66 /** 68 * Test without any selection. 67 * Tests simplification 68 * @throws IOException 69 * @throws IllegalDataException 69 70 */ 70 71 @Test 71 public void testSelectionEmpty() { 72 DataSet ds = new DataSet(); 73 OsmDataLayer layer = new OsmDataLayer(ds, "", null); 74 try { 75 MainApplication.getLayerManager().addLayer(layer); 76 assertTrue(ds.getSelected().isEmpty()); 77 action.actionPerformed(null); 78 } finally { 79 MainApplication.getLayerManager().removeLayer(layer); 80 } 81 } 82 83 /** 84 * Test with a single way. 85 */ 86 @Test 87 public void testSingleWay() { 88 DataSet ds = new DataSet(); 89 createWaySelected(ds, 0.0); 90 OsmDataLayer layer = new OsmDataLayer(ds, "", null); 91 try { 92 MainApplication.getLayerManager().addLayer(layer); 93 assertEquals(1, ds.getSelected().size()); 94 action.actionPerformed(null); 95 } finally { 96 MainApplication.getLayerManager().removeLayer(layer); 97 } 98 } 99 100 /** 101 * Test with more than 10 ways. 102 */ 103 @Test 104 public void testMoreThanTenWays() { 105 DataSet ds = new DataSet(); 106 for (int i = 0; i < 11; i++) { 107 createWaySelected(ds, i); 108 } 109 OsmDataLayer layer = new OsmDataLayer(ds, "", null); 110 try { 111 MainApplication.getLayerManager().addLayer(layer); 112 assertEquals(11, ds.getSelected().size()); 113 action.actionPerformed(null); 114 } finally { 115 MainApplication.getLayerManager().removeLayer(layer); 116 } 72 public void testSimplify() throws IllegalDataException, IOException { 73 DataSet DsSimplify = getDs("tracks"); 74 DataSet DsExpected = getDs("tracks-simplify15"); 75 SimplifyWayAction.simplifyWays(new ArrayList<>(DsSimplify.getWays()), 15); 76 DsSimplify.cleanupDeletedPrimitives(); 77 //compare sorted Coordinates and total amount of primitives, because IDs and order will vary after reload 78 List<LatLon> CoorSimplify = DsSimplify.getNodes().stream() 79 .map(Node::getCoor) 80 .sorted(Comparator.comparing(LatLon::hashCode)) 81 .collect(Collectors.toList()); 82 List<LatLon> CoorExpected = DsExpected.getNodes().stream() 83 .map(Node::getCoor) 84 .sorted(Comparator.comparing(LatLon::hashCode)) 85 .collect(Collectors.toList()); 86 assertEquals(CoorExpected, CoorSimplify); 87 assertEquals(DsExpected.allPrimitives().size(), DsSimplify.allPrimitives().size()); 117 88 } 118 89 -
trunk/test/unit/org/openstreetmap/josm/data/gpx/GpxImageCorrelationTest.java
r14797 r15431 52 52 public void testMatchGpxTrack() throws Exception { 53 53 IPreferences s = Config.getPref(); 54 final GpxData gpx = GpxReaderTest.parseGpxData(TestUtils.getTestDataRoot() + " ImageCorrelationTest.gpx");54 final GpxData gpx = GpxReaderTest.parseGpxData(TestUtils.getTestDataRoot() + "tracks/tracks.gpx"); 55 55 assertEquals(5, gpx.tracks.size()); 56 56 assertEquals(1, gpx.tracks.iterator().next().getSegments().size()); -
trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerActionTest.java
r14129 r15431 6 6 7 7 import java.io.IOException; 8 import java.nio.file.Files; 9 import java.nio.file.Paths; 10 import java.util.Arrays; 11 import java.util.Comparator; 12 import java.util.List; 13 import java.util.Map; 14 import java.util.Objects; 15 import java.util.stream.Collectors; 8 16 9 17 import org.junit.Rule; 10 18 import org.junit.Test; 11 19 import org.openstreetmap.josm.TestUtils; 20 import org.openstreetmap.josm.data.coor.LatLon; 12 21 import org.openstreetmap.josm.data.gpx.GpxData; 13 22 import org.openstreetmap.josm.data.osm.DataSet; 23 import org.openstreetmap.josm.data.osm.Node; 14 24 import org.openstreetmap.josm.data.osm.TagMap; 25 import org.openstreetmap.josm.gui.layer.GpxLayer; 15 26 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 16 27 import org.openstreetmap.josm.io.GpxReaderTest; 28 import org.openstreetmap.josm.io.IllegalDataException; 29 import org.openstreetmap.josm.io.OsmReader; 30 import org.openstreetmap.josm.spi.preferences.Config; 17 31 import org.openstreetmap.josm.testutils.JOSMTestRules; 18 32 import org.xml.sax.SAXException; … … 47 61 48 62 /** 63 * Tests conversions from GPX tracks to OSM datasets 64 * @throws Exception if the parsing fails 65 */ 66 @Test 67 public void testFromTrack() throws Exception { 68 Config.getPref().put("gpx.convert-tags", "no"); 69 testFromTrack("tracks"); 70 71 Config.getPref().put("gpx.convert-tags", "yes"); 72 testFromTrack("tracks-ele-time"); 73 74 Config.getPref().put("gpx.convert-tags", "list"); 75 Config.getPref().putList("gpx.convert-tags.list.yes", Arrays.asList("ele")); 76 Config.getPref().putList("gpx.convert-tags.list.no", Arrays.asList("time")); 77 testFromTrack("tracks-ele"); 78 79 80 Config.getPref().putList("gpx.convert-tags.list.yes", Arrays.asList("time")); 81 Config.getPref().putList("gpx.convert-tags.list.no", Arrays.asList("ele")); 82 testFromTrack("tracks-time"); 83 } 84 85 private class genericNode { 86 public genericNode(Node n) { 87 coor = n.getCoor().getRoundedToOsmPrecision(); 88 tags = n.getKeys(); 89 } 90 public LatLon coor; 91 public Map<String, String> tags; 92 @Override 93 public boolean equals(Object obj) { 94 if (!(obj instanceof genericNode)) { 95 return false; 96 } 97 genericNode other = (genericNode) obj; 98 return coor.equals(other.coor) && tags.equals(other.tags); 99 } 100 @Override 101 public int hashCode() { 102 return Objects.hash(coor, tags); 103 } 104 } 105 106 private void testFromTrack(String expected) throws IOException, SAXException, IllegalDataException { 107 final GpxData data = GpxReaderTest.parseGpxData(TestUtils.getTestDataRoot() + "tracks/tracks.gpx"); 108 final DataSet osmExpected = OsmReader.parseDataSet(Files.newInputStream(Paths.get(TestUtils.getTestDataRoot(), "tracks/" + expected + ".osm")), null); 109 final GpxLayer layer = new GpxLayer(data); 110 final DataSet osm = new ConvertFromGpxLayerAction(layer).convert(); 111 //compare sorted coordinates/tags and total amount of primitives, because IDs and order will vary after reload 112 113 List<genericNode> nodes = osm.getNodes().stream() 114 .map(genericNode::new) 115 .sorted(Comparator.comparing(g -> g.coor.hashCode())) 116 .collect(Collectors.toList()); 117 118 List<genericNode> nodesExpected = osmExpected.getNodes().stream() 119 .map(genericNode::new) 120 .sorted(Comparator.comparing(g -> g.coor.hashCode())) 121 .collect(Collectors.toList()); 122 123 assertEquals(nodesExpected, nodes); 124 assertEquals(osmExpected.allPrimitives().size(), osm.allPrimitives().size()); 125 } 126 127 /** 49 128 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/14275">#14275</a> 50 129 * @throws IOException if an error occurs during reading
Note:
See TracChangeset
for help on using the changeset viewer.