1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include "testing/testing.hpp"
#include "map/framework.hpp"
#include "map/routing_mark.hpp"
#include <algorithm>
#include <vector>
namespace routing_manager_tests
{
namespace
{
RouteMarkData MakeRoutePoint(RouteMarkType type, size_t intermediateIndex, double coord)
{
RouteMarkData data;
data.m_pointType = type;
data.m_intermediateIndex = intermediateIndex;
data.m_position = m2::PointD(coord, coord);
return data;
}
size_t GetIntermediatePointsCount(std::vector<RouteMarkData> const & points)
{
return std::count_if(points.begin(), points.end(),
[](RouteMarkData const & d) { return d.m_pointType == RouteMarkType::Intermediate; });
}
} // namespace
UNIT_TEST(RoutingManager_ContinueRouteToPointAtLimitKeepsFinish)
{
Framework framework(FrameworkParams(false /* m_enableDiffs */));
auto & routingManager = framework.GetRoutingManager();
routingManager.AddRoutePoint(MakeRoutePoint(RouteMarkType::Start, 0, 0.0));
for (size_t i = 0; i < RoutePointsLayout::kMaxIntermediatePointsCount; ++i)
routingManager.AddRoutePoint(MakeRoutePoint(RouteMarkType::Intermediate, i, static_cast<double>(i + 1)),
false /* reorderIntermediatePoints */);
routingManager.AddRoutePoint(MakeRoutePoint(RouteMarkType::Finish, 0, 101.0));
auto const pointsBefore = routingManager.GetRoutePoints();
TEST_EQUAL(pointsBefore.size(), RoutePointsLayout::kMaxRoutePointsCount, ());
TEST_EQUAL(GetIntermediatePointsCount(pointsBefore), RoutePointsLayout::kMaxIntermediatePointsCount, ());
TEST(pointsBefore.back().m_pointType == RouteMarkType::Finish, ());
auto newFinish = MakeRoutePoint(RouteMarkType::Finish, 0, 102.0);
TEST(!routingManager.ContinueRouteToPoint(std::move(newFinish)), ());
auto const pointsAfter = routingManager.GetRoutePoints();
TEST_EQUAL(pointsAfter.size(), pointsBefore.size(), ());
TEST_EQUAL(GetIntermediatePointsCount(pointsAfter), RoutePointsLayout::kMaxIntermediatePointsCount, ());
TEST(pointsAfter.back().m_pointType == RouteMarkType::Finish, ());
TEST_EQUAL(pointsAfter.back().m_position.x, pointsBefore.back().m_position.x, ());
TEST_EQUAL(pointsAfter.back().m_position.y, pointsBefore.back().m_position.y, ());
}
// If route marks are wiped between IsRoutingActive() and ContinueRouteToPoint(),
// the latter must return false without mutating the (empty) layout.
UNIT_TEST(RoutingManager_ContinueRouteToPointWithoutFinishFailsCleanly)
{
Framework framework(FrameworkParams(false /* m_enableDiffs */));
auto & routingManager = framework.GetRoutingManager();
TEST_EQUAL(routingManager.GetRoutePointsCount(), 0, ());
auto newFinish = MakeRoutePoint(RouteMarkType::Finish, 0, 1.0);
TEST(!routingManager.ContinueRouteToPoint(std::move(newFinish)), ());
TEST_EQUAL(routingManager.GetRoutePointsCount(), 0, ());
}
} // namespace routing_manager_tests
|