source: josm/trunk/test/unit/org/openstreetmap/josm/data/osm/NodeGraphTest.java

Last change on this file was 18853, checked in by taylor.smock, 7 months ago

See #16567: Update to JUnit 5

This removes new JOSMTestRules() with no additional setup and most
JOSMFixture calls.

Removing the bare JOSMTestRules speeds up the test suite since there are two
fewer System.gc() calls per test.

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertTrue;
6
7import java.util.Arrays;
8import java.util.Collections;
9import java.util.List;
10
11import org.junit.jupiter.api.Test;
12
13/**
14 * Unit tests of the {@code NodeGraph} class.
15 */
16class NodeGraphTest {
17 /**
18 * Unit test of {@link NodeGraph#buildNodePairs} and {@link NodeGraph#eliminateDuplicateNodePairs}
19 */
20 @Test
21 void testNodePairs() {
22 assertTrue(NodeGraph.buildNodePairs(Collections.emptyList(), true).isEmpty());
23 assertTrue(NodeGraph.buildNodePairs(Collections.emptyList(), false).isEmpty());
24
25 Way w1 = new Way(1);
26 Way w2 = new Way(2);
27
28 Node n1 = new Node(1);
29 Node n2 = new Node(2);
30 Node n3 = new Node(3);
31
32 Node n4 = new Node(4);
33 Node n5 = new Node(5);
34 Node n6 = new Node(6);
35
36 w1.setNodes(Arrays.asList(n1, n2, n3));
37 w2.setNodes(Arrays.asList(n4, n5, n6, n4));
38
39 w1.setIncomplete(false);
40 w2.setIncomplete(false);
41
42 List<Way> ways = Arrays.asList(w1, w2);
43
44 List<NodePair> l1 = NodeGraph.buildNodePairs(ways, true);
45 List<NodePair> l2 = NodeGraph.buildNodePairs(ways, false);
46
47 assertEquals(Arrays.asList(
48 new NodePair(n1, n2),
49 new NodePair(n2, n3),
50 new NodePair(n4, n5),
51 new NodePair(n5, n6),
52 new NodePair(n6, n4)
53 ), l1);
54
55 assertEquals(l1, NodeGraph.eliminateDuplicateNodePairs(l1));
56
57 assertEquals(Arrays.asList(
58 new NodePair(n1, n2), new NodePair(n2, n1),
59 new NodePair(n2, n3), new NodePair(n3, n2),
60 new NodePair(n4, n5), new NodePair(n5, n4),
61 new NodePair(n5, n6), new NodePair(n6, n5),
62 new NodePair(n6, n4), new NodePair(n4, n6)
63 ), l2);
64
65 assertEquals(l1, NodeGraph.eliminateDuplicateNodePairs(l2));
66 }
67}
Note: See TracBrowser for help on using the repository browser.