Test fixes, small bugfixes and review fixes

Signed-off-by: Anton Makouski <anton.makouski@gmail.com>
This commit is contained in:
Anton Makouski 2022-06-03 13:24:02 +03:00
parent 86f2957179
commit e685c715d8
10 changed files with 73 additions and 61 deletions

View file

@ -101,6 +101,12 @@ size_t CarDirectionsEngine::GetTurnDirection(IRoutingResult const & result, size
NumMwmIds const & numMwmIds,
RoutingSettings const & vehicleSettings, TurnItem & turnItem)
{
// This is for jump from initial point to start of the route.
/// @todo Sometimes results of GetPossibleTurns are empty, sometimes are invalid.
///E.g. Google Maps until you reach destination will guide you go to the left or to the right of first road.
if (turnItem.m_index == 2)
return 0;
size_t skipTurnSegments = CheckUTurnOnRoute(result, outgoingSegmentIndex, numMwmIds, vehicleSettings, turnItem);
if (turnItem.m_turn == CarDirection::None)

View file

@ -66,17 +66,16 @@ public:
struct RoadNameInfo
{
bool m_isLink;
// This is for street/road. |m_ref| |m_name|.
std::string m_ref; // Number of street/road .g. "CA 85".
std::string m_name; // E.g "Johnson Ave.".
std::string m_ref; // Number of street/road e.g. "CA 85".
// This is for 1st segment of link after junction. Exit |junction_ref| to |m_destination_ref| for |m_destination|.
std::string m_junction_ref; // Number of junction e.g. "398B".
std::string m_destination_ref; // Number of next road, e.g. "CA 85", Sometimes "CA 85 South".
std::string m_destination_ref; // Number of next road, e.g. "CA 85", Sometimes "CA 85 South". Usually match |m_ref| of next main road.
std::string m_destination; // E.g. "Cupertino".
bool m_isLink = false;
bool HasBasicTextInfo() const { return !m_ref.empty() || !m_name.empty(); }
bool HasExitInfo() const { return m_isLink || !m_junction_ref.empty() || !m_destination_ref.empty() || !m_destination.empty(); }
RoadNameInfo() { m_isLink = false; }
};
RouteSegment(Segment const & segment, turns::TurnItem const & turn,
@ -314,6 +313,9 @@ public:
/// set with MoveIterator() method. If it's not possible returns nullopt.
std::optional<turns::TurnItem> GetCurrentIteratorTurn() const;
/// \brief Returns a name info of a street next to idx point of the path.
void GetStreetNameAfterIdx(uint32_t idx, RouteSegment::RoadNameInfo & roadNameInfo) const;
/// \brief Returns name info of a street where the user rides at this moment.
void GetCurrentStreetName(RouteSegment::RoadNameInfo & roadNameInfo) const;
@ -405,9 +407,6 @@ private:
void GetClosestTurn(size_t segIdx, turns::TurnItem & turn) const;
size_t ConvertPointIdxToSegmentIdx(size_t pointIdx) const;
/// \brief Returns a name info of a street next to idx point of the path.
void GetStreetNameAfterIdx(uint32_t idx, RouteSegment::RoadNameInfo & roadNameInfo) const;
/// \returns Estimated time to pass the route segment with |segIdx|.
double GetTimeToPassSegSec(size_t segIdx) const;

View file

@ -422,7 +422,7 @@ using namespace std;
for (auto const & routeSegment : routeSegments)
{
TEST(routeSegment.GetSpeedCams().empty(),
(routeSegment.GetSegment(), routeSegment.GetStreet()));
(routeSegment.GetSegment(), routeSegment.GetRoadNameInfo().m_name));
}
}

View file

@ -183,19 +183,16 @@ void TestTurnCount(routing::Route const & route, uint32_t expectedTurnCount)
void TestCurrentStreetName(routing::Route const & route, string const & expectedStreetName)
{
string streetName;
route.GetCurrentStreetName(streetName);
TEST_EQUAL(streetName, expectedStreetName, ());
RouteSegment::RoadNameInfo roadNameInfo;
route.GetCurrentStreetName(roadNameInfo);
TEST_EQUAL(roadNameInfo.m_name, expectedStreetName, ());
}
void TestNextStreetName(routing::Route const & route, string const & expectedStreetName)
{
string streetName;
double distance;
turns::TurnItem turn;
route.GetCurrentTurn(distance, turn);
route.GetStreetNameAfterIdx(turn.m_index, streetName);
TEST_EQUAL(streetName, expectedStreetName, ());
RouteSegment::RoadNameInfo roadNameInfo;
route.GetNextTurnStreetName(roadNameInfo);
TEST_EQUAL(roadNameInfo.m_name, expectedStreetName, ());
}
void TestRouteLength(Route const & route, double expectedRouteMeters, double relativeError)

View file

@ -52,8 +52,9 @@ UNIT_TEST(RussiaTulskayaToPaveletskayaStreetNamesTest)
MoveRoute(route, ms::LatLon(55.73034, 37.63099));
// No more extra last turn, so TestNextStreetName returns "".
integration::TestCurrentStreetName(route, "Валовая улица");
integration::TestNextStreetName(route, "улица Зацепский Вал");
//integration::TestNextStreetName(route, "улица Зацепский Вал");
MoveRoute(route, ms::LatLon(55.730912, 37.636191));

View file

@ -345,7 +345,7 @@ SessionState RoutingSession::OnLocationPositionChanged(GpsInfo const & info)
// For highway exits (or main roads with exit info) returns "[junction:ref]: [target:ref] > target".
// If no |target| - it will be replaced by |name| of next street.
// If no |target:ref| - it will be replaced by |ref| of next road.
// So if link has no info at all, "[ref] name" of next road will be returned (as for next street).
// So if link has no info at all, "[ref] name" of next will be returned (as for next street).
void GetFullRoadName(RouteSegment::RoadNameInfo & road, string & name)
{
if (auto const & sh = ftypes::GetRoadShields(road.m_ref); !sh.empty())
@ -355,25 +355,25 @@ void GetFullRoadName(RouteSegment::RoadNameInfo & road, string & name)
name.clear();
if (road.HasExitInfo())
{
if (!road.m_junction_ref.empty())
name = "[" + road.m_junction_ref + "]";
{
if (!road.m_junction_ref.empty())
name = "[" + road.m_junction_ref + "]";
if (!road.m_destination_ref.empty())
name += string(name.empty() ? "" : ": ") + "[" + road.m_destination_ref + "]";
if (!road.m_destination_ref.empty())
name += string(name.empty() ? "" : ": ") + "[" + road.m_destination_ref + "]";
if (!road.m_destination.empty())
name += string(name.empty() ? "" : " ") + "> " + road.m_destination;
else if (!road.m_name.empty())
name += (road.m_destination_ref.empty() ? " : " : " ") + road.m_name;
}
else
{
if (!road.m_ref.empty())
name = "[" + road.m_ref + "]";
if (!road.m_name.empty())
name += (name.empty() ? "" : " ") + road.m_name;
}
if (!road.m_destination.empty())
name += string(name.empty() ? "" : " ") + "> " + road.m_destination;
else if (!road.m_name.empty())
name += (road.m_destination_ref.empty() ? string(name.empty() ? "" : " ") : ": ") + road.m_name;
}
else
{
if (!road.m_ref.empty())
name = "[" + road.m_ref + "]";
if (!road.m_name.empty())
name += (name.empty() ? "" : " ") + road.m_name;
}
}
void RoutingSession::GetRouteFollowingInfo(FollowingInfo & info) const

View file

@ -29,7 +29,9 @@ static Route::TTurns const kTestTurns(
{turns::TurnItem(1, turns::CarDirection::TurnLeft),
turns::TurnItem(2, turns::CarDirection::TurnRight),
turns::TurnItem(4, turns::CarDirection::ReachedYourDestination)});
static Route::TStreets const kTestNames({{0, "Street1"}, {1, "Street2"}, {4, "Street3"}});
static Route::TStreets const kTestNames({{0, {"Street1", "", "", "", "", false}},
{1, {"Street2", "", "", "", "", false}},
{4, {"Street3", "", "", "", "", false}}});
static Route::TTimes const kTestTimes({Route::TTimeItem(1, 5), Route::TTimeItem(3, 10),
Route::TTimeItem(4, 15)});
@ -39,11 +41,15 @@ static Route::TTurns const kTestTurns2(
turns::TurnItem(2, turns::CarDirection::TurnRight),
turns::TurnItem(3, turns::CarDirection::None),
turns::TurnItem(4, turns::CarDirection::ReachedYourDestination)});
static vector<string> const kTestNames2 = {"Street0", "Street1", "Street2", "", "Street3"};
static vector<RouteSegment::RoadNameInfo> const kTestNames2 = {{"Street0", "", "", "", "", false},
{"Street1", "", "", "", "", false},
{"Street2", "", "", "", "", false},
{"", "", "", "", "", false},
{"Street3", "", "", "", "", false}};
static vector<double> const kTestTimes2 = {0.0, 5.0, 6.0, 10.0, 15.0};
void GetTestRouteSegments(vector<m2::PointD> const & routePoints, Route::TTurns const & turns,
vector<string> const & streets, vector<double> const & times,
vector<RouteSegment::RoadNameInfo> const & streets, vector<double> const & times,
vector<RouteSegment> & routeSegments)
{
CHECK_EQUAL(routePoints.size(), turns.size(), ());
@ -290,7 +296,7 @@ UNIT_TEST(SelfIntersectedRouteMatchingTest)
Route route("TestRouter", 0 /* route id */);
route.SetGeometry(kRouteGeometry.begin(), kRouteGeometry.end());
vector<RouteSegment> routeSegments;
GetTestRouteSegments(kRouteGeometry, kTestTurns2, kTestNames2, kTestTimes2, routeSegments);
route.SetRouteSegments(move(routeSegments));
@ -346,30 +352,30 @@ UNIT_TEST(RouteNameTest)
GetTestRouteSegments(kTestGeometry, kTestTurns2, kTestNames2, kTestTimes2, routeSegments);
route.SetRouteSegments(move(routeSegments));
string name;
route.GetCurrentStreetName(name);
TEST_EQUAL(name, "Street1", ());
RouteSegment::RoadNameInfo roadNameInfo;
route.GetCurrentStreetName(roadNameInfo);
TEST_EQUAL(roadNameInfo.m_name, "Street1", (roadNameInfo.m_name));
route.GetStreetNameAfterIdx(0, name);
TEST_EQUAL(name, "Street1", ());
route.GetStreetNameAfterIdx(0, roadNameInfo);
TEST_EQUAL(roadNameInfo.m_name, "Street1", (roadNameInfo.m_name));
route.GetStreetNameAfterIdx(1, name);
TEST_EQUAL(name, "Street1", ());
route.GetStreetNameAfterIdx(1, roadNameInfo);
TEST_EQUAL(roadNameInfo.m_name, "Street1", (roadNameInfo.m_name));
route.GetStreetNameAfterIdx(2, name);
TEST_EQUAL(name, "Street2", ());
route.GetStreetNameAfterIdx(2, roadNameInfo);
TEST_EQUAL(roadNameInfo.m_name, "Street2", (roadNameInfo.m_name));
route.GetStreetNameAfterIdx(3, name);
TEST_EQUAL(name, "Street3", ());
route.GetStreetNameAfterIdx(3, roadNameInfo);
TEST_EQUAL(roadNameInfo.m_name, "Street3", (roadNameInfo.m_name));
route.GetStreetNameAfterIdx(4, name);
TEST_EQUAL(name, "Street3", ());
route.GetStreetNameAfterIdx(4, roadNameInfo);
TEST_EQUAL(roadNameInfo.m_name, "Street3", (roadNameInfo.m_name));
location::GpsInfo info;
info.m_longitude = 1.0;
info.m_latitude = 2.0;
route.MoveIterator(info);
route.GetCurrentStreetName(name);
TEST_EQUAL(name, "Street2", ());
route.GetCurrentStreetName(roadNameInfo);
TEST_EQUAL(roadNameInfo.m_name, "Street2", (roadNameInfo.m_name));
}
} // namespace route_tests

View file

@ -37,7 +37,7 @@ UNIT_TEST(FillSegmentInfoSmokeTest)
TEST_EQUAL(segmentInfo.size(), 1, ());
TEST_EQUAL(segmentInfo[0].GetTurn().m_turn, CarDirection::ReachedYourDestination, ());
TEST(segmentInfo[0].GetStreet().empty(), ());
TEST(segmentInfo[0].GetRoadNameInfo().m_name.empty(), ());
}
UNIT_TEST(FillSegmentInfoTest)
@ -50,7 +50,9 @@ UNIT_TEST(FillSegmentInfoTest)
{m2::PointD(0.2 /* x */, 0.0 /* y */), geometry::kInvalidAltitude}};
Route::TTurns const & turnDirs = {{1 /* point index */, CarDirection::TurnRight},
{2 /* point index */, CarDirection::ReachedYourDestination}};
Route::TStreets const streets = {{0 /* point index */, "zero"}, {1, "first"}, {2, "second"}};
Route::TStreets const streets = {{0 /* point index */, {"zero", "", "", "", "", false}},
{1 /* point index */, {"first", "", "", "", "", false}},
{2 /* point index */, {"second", "", "", "", "", false}}};
Route::TTimes const times = {
{0 /* point index */, 0.0 /* time in seconds */}, {1, 1.0}, {2, 2.0}};
@ -59,11 +61,11 @@ UNIT_TEST(FillSegmentInfoTest)
TEST_EQUAL(segmentInfo.size(), 2, ());
TEST_EQUAL(segmentInfo[0].GetTurn().m_turn, CarDirection::TurnRight, ());
TEST_EQUAL(segmentInfo[0].GetStreet(), string("first"), ());
TEST_EQUAL(segmentInfo[0].GetRoadNameInfo().m_name, string("first"), ());
TEST_EQUAL(segmentInfo[0].GetSegment(), segments[0], ());
TEST_EQUAL(segmentInfo[1].GetTurn().m_turn, CarDirection::ReachedYourDestination, ());
TEST_EQUAL(segmentInfo[1].GetStreet(), string("second"), ());
TEST_EQUAL(segmentInfo[1].GetRoadNameInfo().m_name, string("second"), ());
TEST_EQUAL(segmentInfo[1].GetSegment(), segments[1], ());
}

View file

@ -339,7 +339,7 @@ UNIT_TEST(TestIntermediateDirection)
UNIT_TEST(TestCheckUTurnOnRoute)
{
TUnpackedPathSegments pathSegments(4, LoadedPathSegment());
pathSegments[0].m_name = "A road";
pathSegments[0].m_roadNameInfo = {"A road", "", "", "", "", false};
pathSegments[0].m_weight = 1;
pathSegments[0].m_highwayClass = ftypes::HighwayClass::Trunk;
pathSegments[0].m_onRoundabout = false;

View file

@ -292,7 +292,8 @@ void CorrectCandidatesSegmentByOutgoing(TurnInfo const & turnInfo, Segment const
it->m_segment = firstOutgoingSeg;
}
else if (nodes.isCandidatesAngleValid)
ASSERT(false, ("Can't match any candidate with firstOutgoingSegment but isCandidatesAngleValid == true."));
// Typically all candidates are from one mwm, and missed one (firstOutgoingSegment) from another.
LOG(LWARNING, ("Can't match any candidate with firstOutgoingSegment but isCandidatesAngleValid == true."));
else
{
LOG(LWARNING, ("Can't match any candidate with firstOutgoingSegment and isCandidatesAngleValid == false"));