source: josm/trunk/test/unit/org/openstreetmap/josm/data/validation/tests/CycleDetectorTest.java

Last change on this file was 19062, checked in by GerdP, 9 months ago

fix #21881: Add a check for loops in directional waterways
Patch by gaben, slightly modified

  • implements Tarjan algorithm to find strongly connected components
  • new preference validator.CycleDetector.directionalWaterways contains the list of waterway values which should be checked
File size: 1.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.validation.tests;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5
6import org.junit.jupiter.api.Test;
7import org.openstreetmap.josm.TestUtils;
8import org.openstreetmap.josm.data.osm.DataSet;
9import org.openstreetmap.josm.io.OsmReader;
10import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
11
12/**
13 * JUnit test for {@link CycleDetector} validation test.
14 */
15@BasicPreferences
16class CycleDetectorTest {
17
18 @Test
19 void testCycleDetection() throws Exception {
20 CycleDetector cycleDetector = new CycleDetector();
21 DataSet ds = OsmReader.parseDataSet(TestUtils.getRegressionDataStream(21881, "CycleDetector_test_wikipedia.osm"), null);
22 cycleDetector.startTest(null);
23 cycleDetector.visit(ds.allPrimitives());
24 cycleDetector.endTest();
25
26 // we have 4 cycles in the test file
27 assertEquals(4, cycleDetector.getErrors().size());
28 }
29
30 @Test
31 void testNotConsecutive() throws Exception {
32 CycleDetector cycleDetector = new CycleDetector();
33 DataSet ds = OsmReader.parseDataSet(TestUtils.getRegressionDataStream(21881, "not_consecutive.osm"), null);
34 cycleDetector.startTest(null);
35 cycleDetector.visit(ds.allPrimitives());
36 cycleDetector.endTest();
37
38 // we have 1 cycles in the test file
39 assertEquals(1, cycleDetector.getErrors().size());
40 }
41}
Note: See TracBrowser for help on using the repository browser.