Changeset 15431 in josm for trunk/test/unit/org/openstreetmap/josm/actions
- Timestamp:
- 2019-10-06T14:47:39+02:00 (5 years ago)
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.