From 5face9f08d1105005b3ba5750e82fe5ec7199097 Mon Sep 17 00:00:00 2001 From: gaben <23311361+gabortim@users.noreply.github.com> Date: Sun, 8 Oct 2023 16:49:00 +0200 Subject: [PATCH] Add single node unit test for DistributeAction It is failing, since the DistributeAction works that way by design, but it can cause overlapping way issues. Not sure what to do. --- .../josm/actions/DistributeActionTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/unit/org/openstreetmap/josm/actions/DistributeActionTest.java b/test/unit/org/openstreetmap/josm/actions/DistributeActionTest.java index 03c0db4a425..9203394fb7a 100644 --- a/test/unit/org/openstreetmap/josm/actions/DistributeActionTest.java +++ b/test/unit/org/openstreetmap/josm/actions/DistributeActionTest.java @@ -76,6 +76,51 @@ void testWholeWayAlignment() { } } + @Test + void testNodesAlignment() { + Way way = new Way(); + final int totalNodeCount = 11; // should be in range [2,180]! + final int innerNodeCount = totalNodeCount - 2; + final int lastLon = totalNodeCount - 1; + + // add first node + Node n = new Node(new LatLon(LatLon.ZERO)); + ds.addPrimitive(n); + way.addNode(n); + + // add interim nodes + for (int i = 0; i < innerNodeCount; i++) { + n = new Node(new LatLon(0, getRandomDoubleInRange(0, lastLon))); + ds.addPrimitive(n); + way.addNode(n); + } + + // add last node + n = new Node(new LatLon(0, lastLon)); + ds.addPrimitive(n); + way.addNode(n); + ds.addPrimitive(way); + + + OsmDataLayer layer = new OsmDataLayer(ds, "", null); + MainApplication.getLayerManager().addLayer(layer); + assertNotNull(MainApplication.getLayerManager().getActiveLayer()); + + // select all nodes on the way + layer.getDataSet().setSelected(way.getNodes()); + assertEquals(way.getNodes().size(), layer.getDataSet().getSelected().size()); + + new DistributeAction().actionPerformed(null); + + for (int i = 0; i < totalNodeCount; i++) { + assertEquals( + (double) (1 / lastLon) + i, + way.getNode(i).lon(), + 1e-7 + ); + } + } + @Test void testSingleNodeAlignment() { Way way = new Way();