1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import java.io.FileInputStream;
|
---|
7 | import java.io.IOException;
|
---|
8 | import java.io.InputStream;
|
---|
9 | import java.util.HashSet;
|
---|
10 | import java.util.List;
|
---|
11 | import java.util.Set;
|
---|
12 |
|
---|
13 | import org.junit.BeforeClass;
|
---|
14 | import org.junit.Test;
|
---|
15 | import org.openstreetmap.josm.JOSMFixture;
|
---|
16 | import org.openstreetmap.josm.TestUtils;
|
---|
17 | import org.openstreetmap.josm.actions.CombineWayAction.NodeGraph;
|
---|
18 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
19 | import org.openstreetmap.josm.data.osm.Node;
|
---|
20 | import org.openstreetmap.josm.io.IllegalDataException;
|
---|
21 | import org.openstreetmap.josm.io.OsmReader;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Unit tests for class {@link CombineWayAction}.
|
---|
25 | */
|
---|
26 | public class CombineWayActionTest {
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Setup test.
|
---|
30 | */
|
---|
31 | @BeforeClass
|
---|
32 | public static void setUp() {
|
---|
33 | JOSMFixture.createUnitTestFixture().init();
|
---|
34 | }
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Non-regression test for bug #11957.
|
---|
38 | * @throws IOException if any I/O error occurs
|
---|
39 | * @throws IllegalDataException if OSM parsing fails
|
---|
40 | */
|
---|
41 | @Test
|
---|
42 | public void testTicket11957() throws IOException, IllegalDataException {
|
---|
43 | try (InputStream is = new FileInputStream(TestUtils.getRegressionDataFile(11957, "data.osm"))) {
|
---|
44 | DataSet ds = OsmReader.parseDataSet(is, null);
|
---|
45 | NodeGraph graph = NodeGraph.createNearlyUndirectedGraphFromNodeWays(ds.getWays());
|
---|
46 | List<Node> path = graph.buildSpanningPath();
|
---|
47 | assertEquals(10, path.size());
|
---|
48 | Set<Long> firstAndLastObtained = new HashSet<>();
|
---|
49 | firstAndLastObtained.add(path.get(0).getId());
|
---|
50 | firstAndLastObtained.add(path.get(path.size()-1).getId());
|
---|
51 | Set<Long> firstAndLastExpected = new HashSet<>();
|
---|
52 | firstAndLastExpected.add(1618969016L);
|
---|
53 | firstAndLastExpected.add(35213705L);
|
---|
54 | assertEquals(firstAndLastExpected, firstAndLastObtained);
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|