mod common;
#[test]
fn branch_point_api() {
let road_network = common::create_t_shape_road_network(true);
let road_geometry = road_network.road_geometry();
let branch_point_id = String::from("2");
let branch_point = road_geometry.get_branch_point(&branch_point_id).unwrap();
assert_eq!(branch_point.id(), branch_point_id);
assert_eq!(branch_point.road_geometry().id(), road_geometry.id());
let invalid_branch_point_id = String::from("invalid_id");
let invalid_branch_point = road_geometry.get_branch_point(&invalid_branch_point_id);
assert!(invalid_branch_point.is_none());
let lane_end_set = branch_point.get_a_side();
assert_eq!(lane_end_set.size(), 1);
let lane_end = lane_end_set.get(0).unwrap();
let confluent_branches = branch_point.get_confluent_branches(&lane_end).unwrap();
assert_eq!(confluent_branches.size(), 1);
let ongoing_branches = branch_point.get_ongoing_branches(&lane_end).unwrap();
assert_eq!(ongoing_branches.size(), 2);
let ongoing_branches_id_lane_end = ongoing_branches.to_lane_map();
assert_eq!(ongoing_branches_id_lane_end.len(), 2);
assert!(ongoing_branches_id_lane_end.contains_key("5_0_-1"));
assert!(ongoing_branches_id_lane_end.contains_key("9_0_-1"));
let lane_end_5 = ongoing_branches_id_lane_end.get("5_0_-1").unwrap();
let lane_end_9 = ongoing_branches_id_lane_end.get("9_0_-1").unwrap();
assert!(matches!(lane_end_5, maliput::api::LaneEnd::Start(_)));
assert!(matches!(lane_end_9, maliput::api::LaneEnd::Start(_)));
let lane_end_set = branch_point.get_b_side();
assert_eq!(lane_end_set.size(), 2);
let lane_end_set = branch_point.get_a_side();
let invalid_lane_end = lane_end_set.get(123);
assert!(invalid_lane_end.is_err());
let other_branch_point_id = String::from("1");
let other_branch_point = road_geometry.get_branch_point(&other_branch_point_id).unwrap();
let confluent_branches = other_branch_point.get_confluent_branches(&lane_end);
assert!(confluent_branches.is_err());
let ongoing_branches = other_branch_point.get_ongoing_branches(&lane_end);
assert!(ongoing_branches.is_err());
let default_lane_end = branch_point.get_default_branch(&lane_end);
assert!(default_lane_end.is_some());
match default_lane_end.unwrap() {
maliput::api::LaneEnd::Start(l) | maliput::api::LaneEnd::Finish(l) => assert_eq!(l.id(), "5_0_-1"),
}
let the_other_lane_end = match lane_end {
maliput::api::LaneEnd::Start(l) => maliput::api::LaneEnd::Finish(l),
maliput::api::LaneEnd::Finish(l) => maliput::api::LaneEnd::Start(l),
};
let default_branch = branch_point.get_default_branch(&the_other_lane_end);
assert!(default_branch.is_none());
}