1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
---|
6 |
|
---|
7 | import java.util.Arrays;
|
---|
8 |
|
---|
9 | import org.junit.jupiter.api.Test;
|
---|
10 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Unit tests of the {@code WaySegment} class.
|
---|
14 | */
|
---|
15 | class WaySegmentTest {
|
---|
16 | @Test
|
---|
17 | void testForNodePair() {
|
---|
18 | final DataSet ds = new DataSet();
|
---|
19 | final Node n1 = new Node(LatLon.ZERO);
|
---|
20 | final Node n2 = new Node(new LatLon(1, 0));
|
---|
21 | final Node n3 = new Node(new LatLon(2, 0));
|
---|
22 | final Node n4 = new Node(new LatLon(3, 0));
|
---|
23 | final Way w = new Way();
|
---|
24 | for (OsmPrimitive p : Arrays.asList(n1, n2, n3, n4, w)) {
|
---|
25 | ds.addPrimitive(p);
|
---|
26 | }
|
---|
27 | w.addNode(n1);
|
---|
28 | w.addNode(n2);
|
---|
29 | w.addNode(n1);
|
---|
30 | w.addNode(n3);
|
---|
31 | w.addNode(n1);
|
---|
32 | w.addNode(n4);
|
---|
33 | w.addNode(n1);
|
---|
34 | assertEquals(WaySegment.forNodePair(w, n1, n2).getLowerIndex(), 0);
|
---|
35 | assertEquals(WaySegment.forNodePair(w, n1, n3).getLowerIndex(), 2);
|
---|
36 | assertEquals(WaySegment.forNodePair(w, n1, n4).getLowerIndex(), 4);
|
---|
37 | assertEquals(WaySegment.forNodePair(w, n4, n1).getLowerIndex(), 5);
|
---|
38 | IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> WaySegment.forNodePair(w, n3, n4));
|
---|
39 | assertEquals("Node pair is not part of way!", iae.getMessage());
|
---|
40 | }
|
---|
41 | }
|
---|