Skip to content

Commit a0bf8f7

Browse files
committed
test: enhance OpenDriveMap tests with routing checks and improve readability
1 parent 82c2dd9 commit a0bf8f7

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

tests/test.cpp

+36-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
#include "OpenDriveMap.h"
22
#include <catch2/catch_test_macros.hpp>
3+
#include <catch2/matchers/catch_matchers_vector.hpp>
34
#include <iostream>
45

5-
TEST_CASE("Basic OpenDriveMap check", "[xodr]")
6+
TEST_CASE("basic map check", "[xodr]")
67
{
78
odr::OpenDriveMap odr_map("test.xodr");
89
REQUIRE(odr_map.xml_parse_result);
910
REQUIRE(!odr_map.get_roads().empty());
1011

11-
// test routing
12-
auto graph = odr_map.get_routing_graph();
13-
auto path = graph.shortest_path(odr::LaneKey("43", 0.0, 1), odr::LaneKey("41", 0.0, 1));
14-
REQUIRE(path.size() == 15);
15-
1612
for (const odr::Road& road : odr_map.get_roads())
1713
{
1814
INFO("road: " << road.id << ", length: " << road.length);
@@ -30,4 +26,38 @@ TEST_CASE("Basic OpenDriveMap check", "[xodr]")
3026
}
3127
}
3228
}
29+
}
30+
31+
TEST_CASE("routing check", "[routing]")
32+
{
33+
odr::OpenDriveMap odr_map("test.xodr");
34+
35+
const odr::RoutingGraph graph = odr_map.get_routing_graph();
36+
37+
std::vector<odr::LaneKey> path, expected_path;
38+
const odr::LaneKey posA("43", 0.0, 1);
39+
const odr::LaneKey posB("41", 0.0, 1);
40+
const odr::LaneKey posC("13", 0.0, -1);
41+
const odr::LaneKey posNaN("no-exists", 0.0, 1);
42+
43+
path = graph.shortest_path(posA, posB);
44+
REQUIRE(path.size() == 15);
45+
REQUIRE(path.front() == posA);
46+
REQUIRE(path.back() == posB);
47+
48+
path = graph.shortest_path(posA, posA);
49+
REQUIRE(path.size() == 1);
50+
REQUIRE(path.front() == posA);
51+
52+
path = graph.shortest_path(posC, posB);
53+
expected_path = {posC,
54+
odr::LaneKey("405", 0.0, -1),
55+
odr::LaneKey("405", 14.0521019230889283591068306122906506061553955078125, -1),
56+
odr::LaneKey("16", 0.0, -1),
57+
odr::LaneKey("17", 0.0, -1),
58+
odr::LaneKey("18", 0.0, -1),
59+
odr::LaneKey("747", 0.0, -1),
60+
odr::LaneKey("747", 1.76237248299736393164494074881076812744140625, -1),
61+
posB};
62+
REQUIRE_THAT(path, Catch::Matchers::Equals(expected_path));
3363
}

0 commit comments

Comments
 (0)