Changeset 19065 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2024-04-28T09:37:20+02:00 (6 months ago)
Author:
GerdP
Message:

see #21881 Add a check for loops in directional waterways
Fix code in WaySegment and IWaySegment

  • change text in Exception to "Node pair is not a single segment of the way!" and move it to constant IWaySegment.NOT_A_SEGMENT
  • fix error in WaySegment.forNodePair and IWaySegment.forNodePair
  • add unit test for further invalid node pairs
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/osm/WaySegmentTest.java

    r19064 r19065  
    2121        final Node n3 = new Node(new LatLon(2, 0));
    2222        final Node n4 = new Node(new LatLon(3, 0));
    23         final Way w = new Way();
    24         for (OsmPrimitive p : Arrays.asList(n1, n2, n3, n4, w)) {
     23        final Way w1 = new Way();
     24        final Way w2 = new Way();
     25        for (OsmPrimitive p : Arrays.asList(n1, n2, n3, n4, w1, w2)) {
    2526            ds.addPrimitive(p);
    2627        }
    27         w.addNode(n1);
    28         w.addNode(n2);
    29         w.addNode(n1);
    30         w.addNode(n3);
    31         w.addNode(n1);
    32         w.addNode(n4);
    33         w.addNode(n1);
    34         assertEquals(WaySegment.forNodePair(w, n1, n2).getLowerIndex(), 0);
    35         assertEquals(WaySegment.forNodePair(w, n1, n3).getLowerIndex(), 2);
    36         assertEquals(WaySegment.forNodePair(w, n1, n4).getLowerIndex(), 4);
    37         assertEquals(WaySegment.forNodePair(w, n4, n1).getLowerIndex(), 5);
    38         IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> WaySegment.forNodePair(w, n3, n4));
    39         assertEquals("The node pair is not consecutive part of the way!", iae.getMessage());
     28        w1.addNode(n1);
     29        w1.addNode(n2);
     30        w1.addNode(n1);
     31        w1.addNode(n3);
     32        w1.addNode(n1);
     33        w1.addNode(n4);
     34        w1.addNode(n1);
     35
     36        w2.addNode(n1);
     37        w2.addNode(n2);
     38        w2.addNode(n3);
     39
     40        assertEquals(0, WaySegment.forNodePair(w1, n1, n2).getLowerIndex());
     41        assertEquals(2, WaySegment.forNodePair(w1, n1, n3).getLowerIndex());
     42        assertEquals(4, WaySegment.forNodePair(w1, n1, n4).getLowerIndex());
     43        assertEquals(5, WaySegment.forNodePair(w1, n4, n1).getLowerIndex());
     44        // two segments between n3 and n4
     45        IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> WaySegment.forNodePair(w1, n3, n4));
     46        assertEquals(IWaySegment.NOT_A_SEGMENT, iae.getMessage());
     47        // wrong order
     48        iae = assertThrows(IllegalArgumentException.class, () -> WaySegment.forNodePair(w2, n2, n1));
     49        assertEquals(IWaySegment.NOT_A_SEGMENT, iae.getMessage());
     50        // node is not in way
     51        iae = assertThrows(IllegalArgumentException.class, () -> WaySegment.forNodePair(w2, n1, n4));
     52        assertEquals(IWaySegment.NOT_A_SEGMENT, iae.getMessage());
    4053    }
    4154}
Note: See TracChangeset for help on using the changeset viewer.