Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp>
  • Loading branch information
soblin committed Mar 6, 2025
1 parent 0b12536 commit bbff5c6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
9 changes: 4 additions & 5 deletions common/autoware_lanelet2_utility/src/topology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <autoware_lanelet2_utility/topology.hpp>
#include <range/v3/all.hpp>
#include <rclcpp/logging.hpp>

#include <lanelet2_core/primitives/Lanelet.h>
Expand Down Expand Up @@ -256,10 +257,8 @@ lanelet::ConstLanelets sibling_lanelets(
lanelet::ConstLanelets from_ids(
const lanelet::LaneletMapConstPtr lanelet_map, const std::vector<lanelet::Id> & ids)
{
lanelet::ConstLanelets lanelets;
for (const auto id : ids) {
lanelets.push_back(lanelet_map->laneletLayer.get(id));
}
return lanelets;
return ids |
ranges::view::transform([&](const auto id) { return lanelet_map->laneletLayer.get(id); }) |
ranges::to<std::vector>();
}
} // namespace autoware::lanelet2_utility
35 changes: 33 additions & 2 deletions common/autoware_lanelet2_utility/test/topology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,20 @@ TEST_F(TestWithIntersectionCrossingMap, right_lanelet_with_lc_permission)
EXPECT_EQ(lane.value().id(), 2245);
}

TEST_F(TestWithIntersectionCrossingMap, right_opposite_lanelet)
TEST_F(TestWithIntersectionCrossingMap, right_opposite_lanelet_valid)
{
const auto lane = lanelet2_utility::right_opposite_lanelet(
lanelet_map_ptr_->laneletLayer.get(2288), lanelet_map_ptr_);
EXPECT_EQ(lane.value().id(), 2311);
}

TEST_F(TestWithIntersectionCrossingMap, right_opposite_lanelet_null)
{
const auto lane = lanelet2_utility::right_opposite_lanelet(
lanelet_map_ptr_->laneletLayer.get(2260), lanelet_map_ptr_);
EXPECT_EQ(lane.has_value(), false);
}

TEST_F(TestWithIntersectionCrossingMap, leftmost_lanelet_valid)
{
const auto lane = lanelet2_utility::leftmost_lanelet(
Expand Down Expand Up @@ -177,6 +184,15 @@ TEST_F(TestWithIntersectionCrossingMap, right_lanelets_with_opposite)
EXPECT_EQ(rights[3].id(), 2312);
}

TEST_F(TestWithIntersectionCrossingMap, right_lanelets_with_opposite_without_actual_opposites)
{
const auto rights = lanelet2_utility::right_lanelets(
lanelet_map_ptr_->laneletLayer.get(2259), lanelet_map_ptr_, routing_graph_ptr_,
true /* include opposite */);
EXPECT_EQ(rights.size(), 1);
EXPECT_EQ(rights[0].id(), 2260);
}

TEST_F(TestWithIntersectionCrossingMap, following_lanelets)
{
const auto following = lanelet2_utility::following_lanelets(
Expand Down Expand Up @@ -240,13 +256,20 @@ class TestWithIntersectionCrossingInverseMap : public ::testing::Test
}
};

TEST_F(TestWithIntersectionCrossingInverseMap, left_opposite_lanelet)
TEST_F(TestWithIntersectionCrossingInverseMap, left_opposite_lanelet_valid)
{
const auto lane = lanelet2_utility::left_opposite_lanelet(
lanelet_map_ptr_->laneletLayer.get(2311), lanelet_map_ptr_);
EXPECT_EQ(lane.value().id(), 2288);
}

TEST_F(TestWithIntersectionCrossingInverseMap, left_opposite_lanelet_null)
{
const auto lane = lanelet2_utility::left_opposite_lanelet(
lanelet_map_ptr_->laneletLayer.get(2252), lanelet_map_ptr_);
EXPECT_EQ(lane.has_value(), false);
}

TEST_F(TestWithIntersectionCrossingInverseMap, left_lanelets_with_opposite)
{
const auto lefts = lanelet2_utility::left_lanelets(
Expand All @@ -258,6 +281,14 @@ TEST_F(TestWithIntersectionCrossingInverseMap, left_lanelets_with_opposite)
EXPECT_EQ(lefts[3].id(), 2286);
}

TEST_F(TestWithIntersectionCrossingInverseMap, left_lanelets_with_opposite_without_actual_opposites)
{
const auto lefts = lanelet2_utility::left_lanelets(
lanelet_map_ptr_->laneletLayer.get(2251), lanelet_map_ptr_, routing_graph_ptr_, true);
EXPECT_EQ(lefts.size(), 1);
EXPECT_EQ(lefts[0].id(), 2252);
}

} // namespace autoware

int main(int argc, char ** argv)
Expand Down

0 comments on commit bbff5c6

Please sign in to comment.