Changeset 19197 in josm for trunk/test/unit/org
- Timestamp:
- 2024-08-16T15:58:12+02:00 (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/command/SplitWayCommandTest.java
r18870 r19197 468 468 dataSet.setSelected(splitNode); 469 469 // Sanity check (preconditions -- the route should be well-formed already) 470 WayConnectionTypeCalculator connectionTypeCalculator = new WayConnectionTypeCalculator(); 471 List<WayConnectionType> links = connectionTypeCalculator.updateLinks(route, route.getMembers()); 472 assertAll("All links should be connected (forward)", 473 links.subList(0, links.size() - 2).stream().map(link -> () -> assertTrue(link.linkNext))); 474 assertAll("All links should be connected (backward)", 475 links.subList(1, links.size() - 1).stream().map(link -> () -> assertTrue(link.linkPrev))); 470 assertWellFormedRoute(route); 476 471 final Optional<SplitWayCommand> result = SplitWayCommand.splitWay( 477 472 splitWay, … … 479 474 new ArrayList<>(), 480 475 Strategy.keepLongestChunk(), 481 // This split requires additional downloads but problem occur ed before the download476 // This split requires additional downloads but problem occurred before the download 482 477 SplitWayCommand.WhenRelationOrderUncertain.SPLIT_ANYWAY 483 478 ); … … 485 480 result.get().executeCommand(); 486 481 // Actual check 487 connectionTypeCalculator = new WayConnectionTypeCalculator(); 488 links = connectionTypeCalculator.updateLinks(route, route.getMembers()); 482 assertWellFormedRoute(route); 483 } 484 485 @Test 486 void testTicket21856DoublePoints() { 487 final Way incomplete = new Way(1082474948, 10); 488 final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(47.9971473, 8.1274441)), 489 new Node(new LatLon(48.0011535, 8.1363531))); 490 final Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(48.0012294, 8.136414)), 491 new Node(new LatLon(48.0042513, 8.1378392))); 492 final Way splitWay = TestUtils.newWay("highway=residential", new Node(new LatLon(48.0011817, 8.1363763)), 493 new Node(new LatLon(48.0012086, 8.1363974))); 494 final Relation ptRelation = TestUtils.newRelation("type=route route=bus public_transport:version=2", 495 new RelationMember("", incomplete), new RelationMember("", way1), 496 new RelationMember("", splitWay), new RelationMember("", splitWay), 497 new RelationMember("", way1), new RelationMember("", incomplete)); 498 final List<Node> splitLocations = splitWay.getNodes(); 499 final DataSet ds = new DataSet(); 500 way1.setOsmId(289122842, 10); 501 way2.setOsmId(30239125, 18); 502 splitWay.setOsmId(1082474946, 1); 503 ds.addPrimitiveRecursive(way1); 504 ds.addPrimitiveRecursive(way2); 505 ds.addPrimitiveRecursive(splitWay); 506 ds.addPrimitiveRecursive(incomplete); 507 ds.addPrimitive(ptRelation); 508 splitWay.addNode(0, way1.lastNode()); 509 splitWay.addNode(way2.firstNode()); 510 511 ds.setSelected(splitLocations); 512 assertWellFormedRoute(ptRelation); 513 final Optional<SplitWayCommand> result = SplitWayCommand.splitWay( 514 splitWay, 515 SplitWayCommand.buildSplitChunks(splitWay, splitLocations), 516 new ArrayList<>(), 517 Strategy.keepLongestChunk(), 518 SplitWayCommand.WhenRelationOrderUncertain.SPLIT_ANYWAY 519 ); 520 assertTrue(result.isPresent()); 521 result.get().executeCommand(); 522 // Actual check 523 assertWellFormedRoute(ptRelation); 524 } 525 526 @Test 527 void testTicket21856DoublePointsRouteMiddle() { 528 final Way incomplete = new Way(1082474948, 10); 529 final Way way1 = TestUtils.newWay("highway=residential", new Node(new LatLon(47.9971473, 8.1274441)), 530 new Node(new LatLon(48.0011535, 8.1363531))); 531 final Way way2 = TestUtils.newWay("highway=residential", new Node(new LatLon(48.0012294, 8.136414)), 532 new Node(new LatLon(48.0042513, 8.1378392))); 533 final Way splitWay = TestUtils.newWay("highway=residential", new Node(new LatLon(48.0011817, 8.1363763)), 534 new Node(new LatLon(48.0012086, 8.1363974))); 535 final Relation ptRelation = TestUtils.newRelation("type=route route=bus public_transport:version=2", 536 new RelationMember("", incomplete), new RelationMember("", way1), 537 new RelationMember("", splitWay), new RelationMember("", way2), 538 new RelationMember("", way2), new RelationMember("", splitWay), 539 new RelationMember("", way1), new RelationMember("", incomplete)); 540 final List<Node> splitLocations = splitWay.getNodes(); 541 final DataSet ds = new DataSet(); 542 way1.setOsmId(289122842, 10); 543 way2.setOsmId(30239125, 18); 544 splitWay.setOsmId(1082474946, 1); 545 ds.addPrimitiveRecursive(way1); 546 ds.addPrimitiveRecursive(way2); 547 ds.addPrimitiveRecursive(splitWay); 548 ds.addPrimitiveRecursive(incomplete); 549 ds.addPrimitive(ptRelation); 550 splitWay.addNode(0, way1.lastNode()); 551 splitWay.addNode(way2.firstNode()); 552 553 ds.setSelected(splitLocations); 554 assertWellFormedRoute(ptRelation); 555 final Optional<SplitWayCommand> result = SplitWayCommand.splitWay( 556 splitWay, 557 SplitWayCommand.buildSplitChunks(splitWay, splitLocations), 558 new ArrayList<>(), 559 Strategy.keepLongestChunk(), 560 SplitWayCommand.WhenRelationOrderUncertain.SPLIT_ANYWAY 561 ); 562 assertTrue(result.isPresent()); 563 result.get().executeCommand(); 564 // Actual check 565 assertWellFormedRoute(ptRelation); 566 } 567 568 569 private static void assertWellFormedRoute(Relation route) { 570 WayConnectionTypeCalculator connectionTypeCalculator = new WayConnectionTypeCalculator(); 571 List<WayConnectionType> links = connectionTypeCalculator.updateLinks(route, route.getMembers()); 572 // NONE is the default, and is most often found on incomplete ways 573 links.removeIf(link -> link.direction == WayConnectionType.Direction.NONE); 489 574 assertAll("All links should be connected (forward)", 490 575 links.subList(0, links.size() - 2).stream().map(link -> () -> assertTrue(link.linkNext)));
Note:
See TracChangeset
for help on using the changeset viewer.