1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.util.Arrays;
|
---|
5 |
|
---|
6 | import org.junit.Assert;
|
---|
7 | import org.junit.Before;
|
---|
8 | import org.junit.Test;
|
---|
9 | import org.openstreetmap.josm.JOSMFixture;
|
---|
10 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Unit tests of the {@code WaySegment} class.
|
---|
14 | */
|
---|
15 | public class WaySegmentTest {
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Setup test.
|
---|
19 | */
|
---|
20 | @Before
|
---|
21 | public void setUp() {
|
---|
22 | JOSMFixture.createUnitTestFixture().init();
|
---|
23 | }
|
---|
24 |
|
---|
25 | @Test
|
---|
26 | public void testForNodePair() throws Exception {
|
---|
27 | final DataSet ds = new DataSet();
|
---|
28 | final Node n1 = new Node(LatLon.ZERO);
|
---|
29 | final Node n2 = new Node(new LatLon(1, 0));
|
---|
30 | final Node n3 = new Node(new LatLon(2, 0));
|
---|
31 | final Node n4 = new Node(new LatLon(3, 0));
|
---|
32 | final Way w = new Way();
|
---|
33 | for (OsmPrimitive p : Arrays.asList(n1, n2, n3, n4, w)) {
|
---|
34 | ds.addPrimitive(p);
|
---|
35 | }
|
---|
36 | w.addNode(n1);
|
---|
37 | w.addNode(n2);
|
---|
38 | w.addNode(n1);
|
---|
39 | w.addNode(n3);
|
---|
40 | w.addNode(n1);
|
---|
41 | w.addNode(n4);
|
---|
42 | w.addNode(n1);
|
---|
43 | Assert.assertEquals(WaySegment.forNodePair(w, n1, n2).lowerIndex, 0);
|
---|
44 | Assert.assertEquals(WaySegment.forNodePair(w, n1, n3).lowerIndex, 2);
|
---|
45 | Assert.assertEquals(WaySegment.forNodePair(w, n1, n4).lowerIndex, 4);
|
---|
46 | Assert.assertEquals(WaySegment.forNodePair(w, n4, n1).lowerIndex, 5);
|
---|
47 | try {
|
---|
48 | Assert.assertEquals(WaySegment.forNodePair(w, n3, n4).lowerIndex, 5);
|
---|
49 | throw new IllegalStateException("Expecting IllegalArgumentException");
|
---|
50 | } catch (IllegalArgumentException expected) {
|
---|
51 | System.out.println("Expected exception: " + expected.getMessage());
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|