Branch data Line data Source code
1 : : // ----------------- BEGIN LICENSE BLOCK ---------------------------------
2 : : //
3 : : // Copyright (C) 2018-2021 Intel Corporation
4 : : //
5 : : // SPDX-License-Identifier: MIT
6 : : //
7 : : // ----------------- END LICENSE BLOCK -----------------------------------
8 : :
9 : : #include <ad/map/access/Operation.hpp>
10 : : #include <ad/map/landmark/LandmarkOperation.hpp>
11 : : #include <ad/map/lane/LaneOperation.hpp>
12 : : #include <ad/map/point/Operation.hpp>
13 : : #include <gtest/gtest.h>
14 : :
15 : : using namespace ::ad;
16 : : using namespace ::ad::map;
17 : :
18 : : struct TrafficLightTests : ::testing::Test
19 : : {
20 : 1 : virtual void SetUp()
21 : : {
22 : 1 : access::cleanup();
23 [ + - + - : 1 : ASSERT_TRUE(access::init("test_files/TPK_PFZ.adm.txt"));
- + - - -
- - - -
- ]
24 : : }
25 : :
26 : 1 : virtual void TearDown()
27 : : {
28 : 1 : access::cleanup();
29 : 1 : }
30 : : };
31 : :
32 : 10 : landmark::ENULandmark make_landmark(uint64_t id, double x, double y, double heading)
33 : : {
34 : 10 : landmark::ENULandmark landmark;
35 : 10 : landmark.id = landmark::LandmarkId(id);
36 : 10 : landmark.position.x = point::ENUCoordinate(x);
37 : 10 : landmark.position.y = point::ENUCoordinate(y);
38 : 10 : landmark.position.z = point::ENUCoordinate(3.);
39 : 10 : landmark.heading = point::ENUHeading(heading);
40 : 10 : return landmark;
41 : : }
42 : :
43 : 2 : TEST_F(TrafficLightTests, validate_trafficLights_access)
44 : : {
45 : 1 : double const maxError{0.01};
46 : :
47 : : auto const laneGeoPosition
48 : 1 : = point::createGeoPoint(point::Longitude(8.4365541), point::Latitude(49.0159383), point::Altitude(0.));
49 [ + - ]: 1 : auto const laneId = lane::uniqueLaneId(laneGeoPosition);
50 [ + - ]: 1 : access::setENUReferencePoint(laneGeoPosition);
51 : :
52 [ + - + - : 2 : EXPECT_THROW(landmark::getVisibleTrafficLights(lane::LaneId(1000)), std::invalid_argument);
+ - - + -
+ - - - -
- - - - ]
53 : :
54 [ + - ]: 1 : auto const mapTrafficLights = landmark::getVisibleTrafficLights(laneId);
55 : :
56 : 1 : std::vector<landmark::ENULandmark> expectedLandmarks{make_landmark(21, -21.4540, -40.1775, -1.1057),
57 : 1 : make_landmark(22, -14.2869, -36.6020, -1.1057),
58 : 1 : make_landmark(17, -14.7092, -16.3109, 0.5676),
59 : 1 : make_landmark(18, -19.0267, -9.5788, 0.5676),
60 : 1 : make_landmark(13, 166.9595, 119.0969, 0.7017),
61 : 1 : make_landmark(14, 161.7771, 125.1920, 0.7017),
62 : 1 : make_landmark(19, -49.2998, -37.6138, -2.6007),
63 : 1 : make_landmark(20, -45.1647, -44.4588, -2.6007),
64 : 1 : make_landmark(15, 157.9260, 109.0071, -2.4645),
65 [ + - ]: 1 : make_landmark(16, 162.9555, 102.7860, -2.4645)};
66 : :
67 [ + - - + : 1 : ASSERT_EQ(mapTrafficLights.size(), expectedLandmarks.size());
- - - - -
- ]
68 : :
69 [ + + ]: 11 : for (auto mapTrafficLightId : mapTrafficLights)
70 : : {
71 [ + - ]: 10 : auto const mapTrafficLight = getENULandmark(mapTrafficLightId);
72 : 10 : auto expectedIter = expectedLandmarks.begin();
73 : 28 : do
74 : : {
75 : : // we cannot compare the traffic light id's since these may change in the map, but the positions
76 : : // have to be constant
77 [ + - ]: 38 : if ((std::fabs(static_cast<double>(expectedIter->position.x - mapTrafficLight.position.x)) <= maxError)
78 [ + - + - ]: 10 : && (std::fabs(static_cast<double>(expectedIter->position.y - mapTrafficLight.position.y)) <= maxError)
79 [ + - + - ]: 10 : && (std::fabs(static_cast<double>(expectedIter->position.z - mapTrafficLight.position.z)) <= maxError)
80 [ + + + - : 48 : && (fmod(static_cast<double>(expectedIter->heading - mapTrafficLight.heading), 2 * M_PI) <= maxError))
+ - + + ]
81 : : {
82 : 10 : break;
83 : : }
84 : 28 : expectedIter++;
85 [ + - ]: 28 : } while (expectedIter != expectedLandmarks.end());
86 : :
87 [ + - - + : 10 : ASSERT_NE(expectedIter, expectedLandmarks.end());
- - - - -
- ]
88 [ + - ]: 10 : expectedLandmarks.erase(expectedIter);
89 : : }
90 : : }
|