Changeset 18961 in josm for trunk


Ignore:
Timestamp:
2024-01-30T10:28:35+01:00 (11 months ago)
Author:
GerdP
Message:

see #23397: Improve the results of partial validations

  • correct last minute change so that it doesn't use empty collection to filter irrelevant warnings
  • correct usage of isPrimitiveUsable() so that CrossingWays.Boundaries works again (old unit test failed)
  • add unit tests to check partial validation of DuplicateWay and CrossingWays gives expected results
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/CrossingWays.java

    r18960 r18961  
    317317            DataSet ds = OsmDataManager.getInstance().getActiveDataSet();
    318318            if (ds != null) {
    319                 for (Way w: waysToTest) {
    320                     selection.addAll(ds.searchWays(w.getBBox()));
     319                for (Way wt : waysToTest) {
     320                    selection.addAll(ds.searchWays(wt.getBBox()).stream()
     321                            .filter(w -> !w.isDeleted() && isPrimitiveUsable(w)).collect(Collectors.toList()));
     322                    if (this instanceof CrossingWays.Boundaries) {
     323                        List<Relation> relations = ds.searchRelations(wt.getBBox()).stream()
     324                                .filter(p -> isPrimitiveUsable(p)).collect(Collectors.toList());
     325                        for (Relation r: relations) {
     326                            for (Way w : r.getMemberPrimitives(Way.class)) {
     327                                if (!w.isIncomplete())
     328                                    selection.add(w);
     329                            }
     330                        }
     331                    }
    321332                }
    322333            }
    323334        }
    324335        for (Way w : selection) {
    325             if (!w.isDeleted() && isPrimitiveUsable(w)) {
    326                 testWay(w);
    327             }
     336            testWay(w);
    328337        }
    329338        // free storage
    330339        cellSegments.clear();
    331340        seenWays.clear();
    332         waysToTest.clear();
    333341        if (partialSelection)
    334342            removeIrrelevantErrors(waysToTest);
     343        waysToTest.clear();
    335344        super.endTest();
    336345    }
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/CrossingWaysTest.java

    r18870 r18961  
    1010import java.util.HashMap;
    1111import java.util.List;
     12import java.util.stream.Collectors;
    1213
    1314import org.junit.jupiter.api.Test;
     
    1718import org.openstreetmap.josm.data.osm.DataSet;
    1819import org.openstreetmap.josm.data.osm.Node;
     20import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1921import org.openstreetmap.josm.data.osm.Way;
    2022import org.openstreetmap.josm.data.osm.WaySegment;
     
    2325import org.openstreetmap.josm.data.validation.tests.CrossingWays.SelfCrossing;
    2426import org.openstreetmap.josm.data.validation.tests.CrossingWays.Ways;
     27import org.openstreetmap.josm.gui.MainApplication;
     28import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2529import org.openstreetmap.josm.io.OsmReader;
    2630import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     
    200204        crossingWays.endTest();
    201205
     206        assertEquals(109, crossingWays.getErrors().size());
    202207        for (TestError e : crossingWays.getErrors()) {
    203208            // we don't report self crossing ways in this test
     
    220225    }
    221226
     227    /**
     228     * Check if partial selection find crossings with unselected objects.
     229     * @throws Exception if an error occurs
     230     */
     231    @Test
     232    void testPartial() throws Exception {
     233
     234        DataSet ds = OsmReader.parseDataSet(
     235                Files.newInputStream(Paths.get(TestUtils.getTestDataRoot(), "crossingWays.osm")), null);
     236        MainApplication.getLayerManager().addLayer(new OsmDataLayer(ds, null, null));
     237
     238        CrossingWays crossingWays = new CrossingWays.Ways();
     239        List<OsmPrimitive> partialSelection = ds.getWays().stream().filter(w -> w.hasTag("testsel", "horizontal"))
     240                .collect(Collectors.toList());
     241
     242        crossingWays.setPartialSelection(true);
     243        crossingWays.startTest(null);
     244        crossingWays.visit(partialSelection);
     245        crossingWays.endTest();
     246
     247        assertEquals(109, crossingWays.getErrors().size());
     248        for (TestError e : crossingWays.getErrors()) {
     249            // we don't report self crossing ways in this test
     250            assertEquals(2, e.getPrimitives().size(), e.getPrimitives().toString());
     251            // see #20121: crossing water areas should not be reported
     252            assertFalse(e.getPrimitives().stream().filter(Way.class::isInstance).allMatch(CrossingWays::isWaterArea));
     253        }
     254
     255        CrossingWays crossingBoundaries = new CrossingWays.Boundaries();
     256        crossingBoundaries.setPartialSelection(true);
     257        crossingBoundaries.startTest(null);
     258        crossingBoundaries.visit(ds.allPrimitives());
     259        crossingBoundaries.endTest();
     260        assertEquals(2, crossingBoundaries.getErrors().size());
     261    }
    222262}
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/DuplicateWayTest.java

    r18853 r18961  
    3535    private static void doTest(int code, String tags1, String tags2, boolean fixable) {
    3636        performTest(code, buildDataSet(tags1, tags2), fixable);
     37        performPartialTest(code, buildDataSet(tags1, tags2), fixable);
    3738    }
    3839
    3940    private static void performTest(int code, DataSet ds, boolean fixable) {
     41        TEST.setPartialSelection(false);
    4042        TEST.startTest(NullProgressMonitor.INSTANCE);
    4143        TEST.visit(ds.allPrimitives());
     44        TEST.endTest();
     45
     46        assertEquals(1, TEST.getErrors().size());
     47        TestError error = TEST.getErrors().iterator().next();
     48        assertEquals(code, error.getCode());
     49        assertEquals(fixable, error.isFixable());
     50    }
     51
     52    private static void performPartialTest(int code, DataSet ds, boolean fixable) {
     53        ds.setSelected(ds.getWays().iterator().next());
     54        TEST.setPartialSelection(true);
     55        TEST.startTest(NullProgressMonitor.INSTANCE);
     56        TEST.visit(ds.getSelectedWays().iterator().next());
    4257        TEST.endTest();
    4358
Note: See TracChangeset for help on using the changeset viewer.