1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.vector;
|
---|
3 |
|
---|
4 | import org.junit.jupiter.api.Test;
|
---|
5 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
6 | import org.openstreetmap.josm.data.osm.BBox;
|
---|
7 | import org.openstreetmap.josm.data.osm.INode;
|
---|
8 | import org.openstreetmap.josm.data.osm.IRelation;
|
---|
9 | import org.openstreetmap.josm.data.osm.IWay;
|
---|
10 | import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
11 | import org.openstreetmap.josm.data.osm.visitor.PrimitiveVisitor;
|
---|
12 |
|
---|
13 | import java.util.ArrayList;
|
---|
14 | import java.util.Arrays;
|
---|
15 | import java.util.Collections;
|
---|
16 | import java.util.List;
|
---|
17 |
|
---|
18 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
19 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
---|
20 | import static org.junit.jupiter.api.Assertions.assertNull;
|
---|
21 | import static org.junit.jupiter.api.Assertions.assertSame;
|
---|
22 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
23 | import static org.junit.jupiter.api.Assertions.fail;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Test class for {@link VectorWay}
|
---|
27 | * @author Taylor Smock
|
---|
28 | * @since 17862
|
---|
29 | */
|
---|
30 | class VectorWayTest {
|
---|
31 | @Test
|
---|
32 | void testBBox() {
|
---|
33 | VectorNode node1 = new VectorNode("test");
|
---|
34 | VectorWay way = new VectorWay("test");
|
---|
35 | way.setNodes(Collections.singletonList(node1));
|
---|
36 | node1.setCoor(new LatLon(-5, 1));
|
---|
37 | assertTrue(node1.getBBox().bboxIsFunctionallyEqual(way.getBBox(), 0.0));
|
---|
38 |
|
---|
39 | VectorNode node2 = new VectorNode("test");
|
---|
40 | node2.setCoor(new LatLon(-10, 2));
|
---|
41 |
|
---|
42 | way.setNodes(Arrays.asList(node1, node2));
|
---|
43 | assertTrue(way.getBBox().bboxIsFunctionallyEqual(new BBox(2, -10, 1, -5), 0.0));
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Test
|
---|
47 | void testIdGenerator() {
|
---|
48 | assertSame(new VectorWay("test").getIdGenerator(), new VectorWay("test").getIdGenerator());
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Test
|
---|
52 | void testNodes() {
|
---|
53 | VectorNode node1 = new VectorNode("test");
|
---|
54 | VectorNode node2 = new VectorNode("test");
|
---|
55 | VectorNode node3 = new VectorNode("test");
|
---|
56 | node1.setId(1);
|
---|
57 | node2.setId(2);
|
---|
58 | node3.setId(3);
|
---|
59 | VectorWay way = new VectorWay("test");
|
---|
60 | assertNull(way.firstNode());
|
---|
61 | assertNull(way.lastNode());
|
---|
62 | assertFalse(way.isClosed());
|
---|
63 | assertFalse(way.isFirstLastNode(node1));
|
---|
64 | assertFalse(way.isInnerNode(node2));
|
---|
65 | way.setNodes(Arrays.asList(node1, node2, node3));
|
---|
66 | assertEquals(3, way.getNodesCount());
|
---|
67 | assertEquals(node1, way.getNode(0));
|
---|
68 | assertEquals(node2, way.getNode(1));
|
---|
69 | assertEquals(node3, way.getNode(2));
|
---|
70 | assertTrue(way.isFirstLastNode(node1));
|
---|
71 | assertTrue(way.isFirstLastNode(node3));
|
---|
72 | assertFalse(way.isFirstLastNode(node2));
|
---|
73 | assertTrue(way.isInnerNode(node2));
|
---|
74 | assertFalse(way.isInnerNode(node1));
|
---|
75 | assertFalse(way.isInnerNode(node3));
|
---|
76 |
|
---|
77 | assertEquals(1, way.getNodeIds().get(0));
|
---|
78 | assertEquals(2, way.getNodeIds().get(1));
|
---|
79 | assertEquals(3, way.getNodeIds().get(2));
|
---|
80 | assertEquals(1, way.getNodeId(0));
|
---|
81 | assertEquals(2, way.getNodeId(1));
|
---|
82 | assertEquals(3, way.getNodeId(2));
|
---|
83 |
|
---|
84 | assertFalse(way.isClosed());
|
---|
85 | assertEquals(OsmPrimitiveType.WAY, way.getType());
|
---|
86 | List<VectorNode> nodes = new ArrayList<>(way.getNodes());
|
---|
87 | nodes.add(nodes.get(0));
|
---|
88 | way.setNodes(nodes);
|
---|
89 | assertTrue(way.isClosed());
|
---|
90 | assertEquals(OsmPrimitiveType.CLOSEDWAY, way.getType());
|
---|
91 | }
|
---|
92 |
|
---|
93 | @Test
|
---|
94 | void testAccept() {
|
---|
95 | VectorWay way = new VectorWay("test");
|
---|
96 | List<VectorWay> visited = new ArrayList<>(1);
|
---|
97 | way.accept(new PrimitiveVisitor() {
|
---|
98 | @Override
|
---|
99 | public void visit(INode n) {
|
---|
100 | fail("No nodes should be visited");
|
---|
101 | }
|
---|
102 |
|
---|
103 | @Override
|
---|
104 | public void visit(IWay<?> w) {
|
---|
105 | visited.add((VectorWay) w);
|
---|
106 | }
|
---|
107 |
|
---|
108 | @Override
|
---|
109 | public void visit(IRelation<?> r) {
|
---|
110 | fail("No relations should be visited");
|
---|
111 | }
|
---|
112 | });
|
---|
113 |
|
---|
114 | assertEquals(1, visited.size());
|
---|
115 | assertSame(way, visited.get(0));
|
---|
116 | }
|
---|
117 | }
|
---|