Skip to content

Commit

Permalink
Add single node unit test for DistributeAction
Browse files Browse the repository at this point in the history
It is failing, since the DistributeAction works that way by design, but it can cause overlapping way issues. Not sure what to do.
  • Loading branch information
gabortim committed Oct 8, 2023
1 parent 4e8bef4 commit 5face9f
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/unit/org/openstreetmap/josm/actions/DistributeActionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5face9f

Please sign in to comment.