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.assertTrue;
|
---|
6 |
|
---|
7 | import java.util.Arrays;
|
---|
8 | import java.util.Collections;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
12 | import org.junit.jupiter.api.Test;
|
---|
13 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
14 |
|
---|
15 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Unit tests of the {@code NodeGraph} class.
|
---|
19 | */
|
---|
20 | class NodeGraphTest {
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Setup test.
|
---|
24 | */
|
---|
25 | @RegisterExtension
|
---|
26 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
27 | public JOSMTestRules test = new JOSMTestRules();
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Unit test of {@link NodeGraph#buildNodePairs} and {@link NodeGraph#eliminateDuplicateNodePairs}
|
---|
31 | */
|
---|
32 | @Test
|
---|
33 | void testNodePairs() {
|
---|
34 | assertTrue(NodeGraph.buildNodePairs(Collections.emptyList(), true).isEmpty());
|
---|
35 | assertTrue(NodeGraph.buildNodePairs(Collections.emptyList(), false).isEmpty());
|
---|
36 |
|
---|
37 | Way w1 = new Way(1);
|
---|
38 | Way w2 = new Way(2);
|
---|
39 |
|
---|
40 | Node n1 = new Node(1);
|
---|
41 | Node n2 = new Node(2);
|
---|
42 | Node n3 = new Node(3);
|
---|
43 |
|
---|
44 | Node n4 = new Node(4);
|
---|
45 | Node n5 = new Node(5);
|
---|
46 | Node n6 = new Node(6);
|
---|
47 |
|
---|
48 | w1.setNodes(Arrays.asList(n1, n2, n3));
|
---|
49 | w2.setNodes(Arrays.asList(n4, n5, n6, n4));
|
---|
50 |
|
---|
51 | w1.setIncomplete(false);
|
---|
52 | w2.setIncomplete(false);
|
---|
53 |
|
---|
54 | List<Way> ways = Arrays.asList(w1, w2);
|
---|
55 |
|
---|
56 | List<NodePair> l1 = NodeGraph.buildNodePairs(ways, true);
|
---|
57 | List<NodePair> l2 = NodeGraph.buildNodePairs(ways, false);
|
---|
58 |
|
---|
59 | assertEquals(Arrays.asList(
|
---|
60 | new NodePair(n1, n2),
|
---|
61 | new NodePair(n2, n3),
|
---|
62 | new NodePair(n4, n5),
|
---|
63 | new NodePair(n5, n6),
|
---|
64 | new NodePair(n6, n4)
|
---|
65 | ), l1);
|
---|
66 |
|
---|
67 | assertEquals(l1, NodeGraph.eliminateDuplicateNodePairs(l1));
|
---|
68 |
|
---|
69 | assertEquals(Arrays.asList(
|
---|
70 | new NodePair(n1, n2), new NodePair(n2, n1),
|
---|
71 | new NodePair(n2, n3), new NodePair(n3, n2),
|
---|
72 | new NodePair(n4, n5), new NodePair(n5, n4),
|
---|
73 | new NodePair(n5, n6), new NodePair(n6, n5),
|
---|
74 | new NodePair(n6, n4), new NodePair(n4, n6)
|
---|
75 | ), l2);
|
---|
76 |
|
---|
77 | assertEquals(l1, NodeGraph.eliminateDuplicateNodePairs(l2));
|
---|
78 | }
|
---|
79 | }
|
---|