Format all C++ and Java code via clang-format

Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
Konstantin Pastbin
2025-08-17 14:32:37 +07:00
parent 9f0290c0ec
commit bfffa1fff4
2169 changed files with 56441 additions and 64188 deletions

View File

@@ -128,8 +128,7 @@ UNIT_CLASS_TEST(ApplyingTrafficTest, XXGraph_EmptyTrafficColoring)
TEST(!GetTrafficStash()->Has(kTestNumMwmId), ());
unique_ptr<WorldGraph> graph = BuildXXGraph(GetEstimator());
auto const start =
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2.0, -1.0), *graph);
auto const start = MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2.0, -1.0), *graph);
auto const finish = MakeFakeEnding(6, 0, m2::PointD(3.0, 3.0), *graph);
auto starter = MakeStarter(start, finish, *graph);
vector<m2::PointD> const expectedGeom = {{2 /* x */, -1 /* y */}, {2, 0}, {1, 1}, {2, 2}, {3, 3}};
@@ -140,13 +139,11 @@ UNIT_CLASS_TEST(ApplyingTrafficTest, XXGraph_EmptyTrafficColoring)
UNIT_CLASS_TEST(ApplyingTrafficTest, XXGraph_G0onF3)
{
TrafficInfo::Coloring const coloring = {
{{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection},
SpeedGroup::G0}};
{{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::G0}};
SetTrafficColoring(make_shared<TrafficInfo::Coloring const>(coloring));
unique_ptr<WorldGraph> graph = BuildXXGraph(GetEstimator());
auto const start =
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2.0, -1.0), *graph);
auto const start = MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2.0, -1.0), *graph);
auto const finish = MakeFakeEnding(6, 0, m2::PointD(3.0, 3.0), *graph);
auto starter = MakeStarter(start, finish, *graph);
vector<m2::PointD> const expectedGeom = {{2 /* x */, -1 /* y */}, {2, 0}, {3, 0}, {3, 1}, {2, 2}, {3, 3}};
@@ -157,13 +154,11 @@ UNIT_CLASS_TEST(ApplyingTrafficTest, XXGraph_G0onF3)
UNIT_CLASS_TEST(ApplyingTrafficTest, XXGraph_TempBlockonF3)
{
TrafficInfo::Coloring const coloring = {
{{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection},
SpeedGroup::TempBlock}};
{{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::TempBlock}};
SetTrafficColoring(make_shared<TrafficInfo::Coloring const>(coloring));
unique_ptr<WorldGraph> graph = BuildXXGraph(GetEstimator());
auto const start =
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2.0, -1.0), *graph);
auto const start = MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2.0, -1.0), *graph);
auto const finish = MakeFakeEnding(6, 0, m2::PointD(3.0, 3.0), *graph);
auto starter = MakeStarter(start, finish, *graph);
vector<m2::PointD> const expectedGeom = {{2 /* x */, -1 /* y */}, {2, 0}, {3, 0}, {3, 1}, {2, 2}, {3, 3}};
@@ -174,13 +169,11 @@ UNIT_CLASS_TEST(ApplyingTrafficTest, XXGraph_TempBlockonF3)
UNIT_CLASS_TEST(ApplyingTrafficTest, XXGraph_G0onF3ReverseDir)
{
TrafficInfo::Coloring const coloring = {
{{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kReverseDirection},
SpeedGroup::G0}};
{{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kReverseDirection}, SpeedGroup::G0}};
SetTrafficColoring(make_shared<TrafficInfo::Coloring const>(coloring));
unique_ptr<WorldGraph> graph = BuildXXGraph(GetEstimator());
auto const start =
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2.0, -1.0), *graph);
auto const start = MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2.0, -1.0), *graph);
auto const finish = MakeFakeEnding(6, 0, m2::PointD(3.0, 3.0), *graph);
auto starter = MakeStarter(start, finish, *graph);
vector<m2::PointD> const expectedGeom = {{2 /* x */, -1 /* y */}, {2, 0}, {1, 1}, {2, 2}, {3, 3}};
@@ -191,19 +184,14 @@ UNIT_CLASS_TEST(ApplyingTrafficTest, XXGraph_G0onF3ReverseDir)
UNIT_CLASS_TEST(ApplyingTrafficTest, XXGraph_G0onF3andF6andG4onF8andF4)
{
TrafficInfo::Coloring const coloring = {
{{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection},
SpeedGroup::G0},
{{6 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection},
SpeedGroup::G0},
{{8 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection},
SpeedGroup::G4},
{{7 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection},
SpeedGroup::G4}};
{{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::G0},
{{6 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::G0},
{{8 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::G4},
{{7 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::G4}};
SetTrafficColoring(make_shared<TrafficInfo::Coloring const>(coloring));
unique_ptr<WorldGraph> graph = BuildXXGraph(GetEstimator());
auto const start =
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2.0, -1.0), *graph);
auto const start = MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2.0, -1.0), *graph);
auto const finish = MakeFakeEnding(6, 0, m2::PointD(3.0, 3.0), *graph);
auto starter = MakeStarter(start, finish, *graph);
vector<m2::PointD> const expectedGeom = {{2 /* x */, -1 /* y */}, {2, 0}, {3, 0}, {3, 1}, {2, 2}, {3, 3}};
@@ -217,8 +205,7 @@ UNIT_CLASS_TEST(ApplyingTrafficTest, XXGraph_ChangingTraffic)
TEST(!GetTrafficStash()->Has(kTestNumMwmId), ());
unique_ptr<WorldGraph> graph = BuildXXGraph(GetEstimator());
auto const start =
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2.0, -1.0), *graph);
auto const start = MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2.0, -1.0), *graph);
auto const finish = MakeFakeEnding(6, 0, m2::PointD(3.0, 3.0), *graph);
auto starter = MakeStarter(start, finish, *graph);
vector<m2::PointD> const noTrafficGeom = {{2 /* x */, -1 /* y */}, {2, 0}, {1, 1}, {2, 2}, {3, 3}};
@@ -228,8 +215,7 @@ UNIT_CLASS_TEST(ApplyingTrafficTest, XXGraph_ChangingTraffic)
// Heavy traffic (SpeedGroup::G0) on F3.
TrafficInfo::Coloring const coloringHeavyF3 = {
{{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection},
SpeedGroup::G0}};
{{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::G0}};
SetTrafficColoring(make_shared<TrafficInfo::Coloring const>(coloringHeavyF3));
{
vector<m2::PointD> const heavyF3Geom = {{2 /* x */, -1 /* y */}, {2, 0}, {3, 0}, {3, 1}, {2, 2}, {3, 3}};
@@ -238,16 +224,11 @@ UNIT_CLASS_TEST(ApplyingTrafficTest, XXGraph_ChangingTraffic)
// Overloading traffic jam on F3. Middle traffic (SpeedGroup::G3) on F1, F3, F4, F7 and F8.
TrafficInfo::Coloring const coloringMiddleF1F3F4F7F8 = {
{{1 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection},
SpeedGroup::G3},
{{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection},
SpeedGroup::G3},
{{4 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection},
SpeedGroup::G3},
{{7 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection},
SpeedGroup::G3},
{{8 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection},
SpeedGroup::G3}};
{{1 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::G3},
{{3 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::G3},
{{4 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::G3},
{{7 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::G3},
{{8 /* feature id */, 0 /* segment id */, TrafficInfo::RoadSegmentId::kForwardDirection}, SpeedGroup::G3}};
SetTrafficColoring(make_shared<TrafficInfo::Coloring const>(coloringMiddleF1F3F4F7F8));
{
TestRouteGeometry(*starter, Algorithm::Result::OK, noTrafficGeom);

View File

@@ -65,9 +65,8 @@ UNIT_TEST(AStarAlgorithm_CheckLength)
auto checkLength = [](double weight) { return weight < 23; };
Algorithm algo;
Algorithm::ParamsForTests<decltype(checkLength)> params(
graph, 0u /* startVertex */, 4u /* finishVertex */,
std::move(checkLength));
Algorithm::ParamsForTests<decltype(checkLength)> params(graph, 0u /* startVertex */, 4u /* finishVertex */,
std::move(checkLength));
RoutingResult<unsigned /* Vertex */, double /* Weight */> routingResult;
Algorithm::Result result = algo.FindPath(params, routingResult);
@@ -96,8 +95,8 @@ UNIT_TEST(AdjustRoute)
auto checkLength = [](double weight) { return weight <= 1.0; };
Algorithm algo;
Algorithm::ParamsForTests<decltype(checkLength)> params(
graph, 6 /* startVertex */, {} /* finishVertex */, std::move(checkLength));
Algorithm::ParamsForTests<decltype(checkLength)> params(graph, 6 /* startVertex */, {} /* finishVertex */,
std::move(checkLength));
RoutingResult<unsigned /* Vertex */, double /* Weight */> result;
auto const code = algo.AdjustRoute(params, prevRoute, result);
@@ -120,8 +119,8 @@ UNIT_TEST(AdjustRouteNoPath)
auto checkLength = [](double weight) { return weight <= 1.0; };
Algorithm algo;
Algorithm::ParamsForTests<decltype(checkLength)> params(
graph, 6 /* startVertex */, {} /* finishVertex */, std::move(checkLength));
Algorithm::ParamsForTests<decltype(checkLength)> params(graph, 6 /* startVertex */, {} /* finishVertex */,
std::move(checkLength));
RoutingResult<unsigned /* Vertex */, double /* Weight */> result;
auto const code = algo.AdjustRoute(params, prevRoute, result);
@@ -143,8 +142,8 @@ UNIT_TEST(AdjustRouteOutOfLimit)
auto checkLength = [](double weight) { return weight <= 1.0; };
Algorithm algo;
Algorithm::ParamsForTests<decltype(checkLength)> params(
graph, 6 /* startVertex */, {} /* finishVertex */, std::move(checkLength));
Algorithm::ParamsForTests<decltype(checkLength)> params(graph, 6 /* startVertex */, {} /* finishVertex */,
std::move(checkLength));
RoutingResult<unsigned /* Vertex */, double /* Weight */> result;
auto const code = algo.AdjustRoute(params, prevRoute, result);

View File

@@ -19,9 +19,7 @@ UNIT_TEST(DirectedAStarProgressCheck)
TEST_GREATER(progress.UpdateProgress(middle, finish), 49.0, ());
static auto constexpr kEps = 0.001;
TEST_GREATER(progress.UpdateProgress(finish, finish),
AStarProgress::kMaxPercent - kEps,
());
TEST_GREATER(progress.UpdateProgress(finish, finish), AStarProgress::kMaxPercent - kEps, ());
progress.PushAndDropLastSubProgress();
}
@@ -79,4 +77,4 @@ UNIT_TEST(BidirectedAStarProgressCheck)
progress.PushAndDropLastSubProgress();
}
} // namespace routing_test
} // namespace routing_test

View File

@@ -4,8 +4,8 @@
#include "routing/routing_tests/routing_algorithm.hpp"
#include "routing/features_road_graph.hpp"
#include "routing/route.hpp"
#include "routing/road_graph.hpp"
#include "routing/route.hpp"
#include "routing/router_delegate.hpp"
#include "indexer/classificator_loader.hpp"
@@ -25,8 +25,7 @@ using namespace routing;
using namespace routing_test;
using namespace std;
void TestAStarRouterMock(geometry::PointWithAltitude const & startPos,
geometry::PointWithAltitude const & finalPos,
void TestAStarRouterMock(geometry::PointWithAltitude const & startPos, geometry::PointWithAltitude const & finalPos,
vector<geometry::PointWithAltitude> const & expected)
{
classificator::Load();
@@ -36,8 +35,7 @@ void TestAStarRouterMock(geometry::PointWithAltitude const & startPos,
RoutingResult<geometry::PointWithAltitude, double /* Weight */> result;
TestAStarBidirectionalAlgo algorithm;
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK,
algorithm.CalculateRoute(graph, startPos, finalPos, result), ());
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK, algorithm.CalculateRoute(graph, startPos, finalPos, result), ());
TEST_EQUAL(expected, result.m_path, ());
}
@@ -55,37 +53,31 @@ void AddRoad(RoadGraphMockSource & graph, initializer_list<m2::PointD> const & p
UNIT_TEST(AStarRouter_Graph2_Simple1)
{
geometry::PointWithAltitude const startPos =
geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 0));
geometry::PointWithAltitude const finalPos =
geometry::MakePointWithAltitudeForTesting(m2::PointD(80, 55));
geometry::PointWithAltitude const startPos = geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 0));
geometry::PointWithAltitude const finalPos = geometry::MakePointWithAltitudeForTesting(m2::PointD(80, 55));
vector<geometry::PointWithAltitude> const expected = {
geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 0)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(5, 10)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(5, 40)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(18, 55)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(39, 55)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(80, 55))};
vector<geometry::PointWithAltitude> const expected = {geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 0)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(5, 10)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(5, 40)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(18, 55)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(39, 55)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(80, 55))};
TestAStarRouterMock(startPos, finalPos, expected);
}
UNIT_TEST(AStarRouter_Graph2_Simple2)
{
geometry::PointWithAltitude const startPos =
geometry::MakePointWithAltitudeForTesting(m2::PointD(80, 55));
geometry::PointWithAltitude const finalPos =
geometry::MakePointWithAltitudeForTesting(m2::PointD(80, 0));
geometry::PointWithAltitude const startPos = geometry::MakePointWithAltitudeForTesting(m2::PointD(80, 55));
geometry::PointWithAltitude const finalPos = geometry::MakePointWithAltitudeForTesting(m2::PointD(80, 0));
vector<geometry::PointWithAltitude> const expected = {
geometry::MakePointWithAltitudeForTesting(m2::PointD(80, 55)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(39, 55)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(37, 30)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 30)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 10)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 0)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(80, 0))};
vector<geometry::PointWithAltitude> const expected = {geometry::MakePointWithAltitudeForTesting(m2::PointD(80, 55)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(39, 55)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(37, 30)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 30)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 10)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 0)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(80, 0))};
TestAStarRouterMock(startPos, finalPos, expected);
}
@@ -95,28 +87,24 @@ UNIT_TEST(AStarRouter_SimpleGraph_RouteIsFound)
classificator::Load();
RoadGraphMockSource graph;
AddRoad(graph, {m2::PointD(0, 0), m2::PointD(40, 0)}); // feature 0
AddRoad(graph, {m2::PointD(40, 0), m2::PointD(40, 30)}); // feature 1
AddRoad(graph, {m2::PointD(40, 30), m2::PointD(40, 100)}); // feature 2
AddRoad(graph, {m2::PointD(40, 100), m2::PointD(0, 60)}); // feature 3
AddRoad(graph, {m2::PointD(0, 60), m2::PointD(0, 30)}); // feature 4
AddRoad(graph, {m2::PointD(0, 30), m2::PointD(0, 0)}); // feature 5
AddRoad(graph, {m2::PointD(0, 0), m2::PointD(40, 0)}); // feature 0
AddRoad(graph, {m2::PointD(40, 0), m2::PointD(40, 30)}); // feature 1
AddRoad(graph, {m2::PointD(40, 30), m2::PointD(40, 100)}); // feature 2
AddRoad(graph, {m2::PointD(40, 100), m2::PointD(0, 60)}); // feature 3
AddRoad(graph, {m2::PointD(0, 60), m2::PointD(0, 30)}); // feature 4
AddRoad(graph, {m2::PointD(0, 30), m2::PointD(0, 0)}); // feature 5
geometry::PointWithAltitude const startPos =
geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 0));
geometry::PointWithAltitude const finalPos =
geometry::MakePointWithAltitudeForTesting(m2::PointD(40, 100));
geometry::PointWithAltitude const startPos = geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 0));
geometry::PointWithAltitude const finalPos = geometry::MakePointWithAltitudeForTesting(m2::PointD(40, 100));
vector<geometry::PointWithAltitude> const expected = {
geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 0)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 30)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 60)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(40, 100))};
vector<geometry::PointWithAltitude> const expected = {geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 0)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 30)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 60)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(40, 100))};
RoutingResult<geometry::PointWithAltitude, double /* Weight */> result;
TestAStarBidirectionalAlgo algorithm;
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK,
algorithm.CalculateRoute(graph, startPos, finalPos, result), ());
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK, algorithm.CalculateRoute(graph, startPos, finalPos, result), ());
TEST_EQUAL(expected, result.m_path, ());
}
@@ -131,42 +119,34 @@ UNIT_TEST(AStarRouter_SimpleGraph_RoutesInConnectedComponents)
// Roads in the first connected component.
vector<IRoadGraph::RoadInfo> const roadInfo_1 = {
IRoadGraph::RoadInfo(
true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 10)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(90, 10))}), // feature 0
IRoadGraph::RoadInfo(
true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(90, 10)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(90, 90))}), // feature 1
IRoadGraph::RoadInfo(
true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(90, 90)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 90))}), // feature 2
IRoadGraph::RoadInfo(
true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 90)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 10))}), // feature 3
IRoadGraph::RoadInfo(true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 10)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(90, 10))}), // feature 0
IRoadGraph::RoadInfo(true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(90, 10)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(90, 90))}), // feature 1
IRoadGraph::RoadInfo(true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(90, 90)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 90))}), // feature 2
IRoadGraph::RoadInfo(true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 90)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 10))}), // feature 3
};
// Roads in the second connected component.
vector<IRoadGraph::RoadInfo> const roadInfo_2 = {
IRoadGraph::RoadInfo(
true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(30, 30)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 30))}), // feature 4
IRoadGraph::RoadInfo(
true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 30)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 70))}), // feature 5
IRoadGraph::RoadInfo(
true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 70)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(30, 70))}), // feature 6
IRoadGraph::RoadInfo(
true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(30, 70)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(30, 30))}), // feature 7
IRoadGraph::RoadInfo(true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(30, 30)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 30))}), // feature 4
IRoadGraph::RoadInfo(true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 30)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 70))}), // feature 5
IRoadGraph::RoadInfo(true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(70, 70)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(30, 70))}), // feature 6
IRoadGraph::RoadInfo(true /* bidir */, speedKMpH,
{geometry::MakePointWithAltitudeForTesting(m2::PointD(30, 70)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(30, 30))}), // feature 7
};
for (auto const & ri : roadInfo_1)
@@ -203,10 +183,10 @@ UNIT_TEST(AStarRouter_SimpleGraph_RoutesInConnectedComponents)
{
geometry::PointWithAltitude const finalPos = roadInfo_1[j].m_junctions[0];
RoutingResult<geometry::PointWithAltitude, double /* Weight */> result;
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK,
algorithm.CalculateRoute(graph, startPos, finalPos, result), ());
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK,
algorithm.CalculateRoute(graph, finalPos, startPos, result), ());
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK, algorithm.CalculateRoute(graph, startPos, finalPos, result),
());
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK, algorithm.CalculateRoute(graph, finalPos, startPos, result),
());
}
}
@@ -218,10 +198,10 @@ UNIT_TEST(AStarRouter_SimpleGraph_RoutesInConnectedComponents)
{
geometry::PointWithAltitude const finalPos = roadInfo_2[j].m_junctions[0];
RoutingResult<geometry::PointWithAltitude, double /* Weight */> result;
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK,
algorithm.CalculateRoute(graph, startPos, finalPos, result), ());
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK,
algorithm.CalculateRoute(graph, finalPos, startPos, result), ());
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK, algorithm.CalculateRoute(graph, startPos, finalPos, result),
());
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK, algorithm.CalculateRoute(graph, finalPos, startPos, result),
());
}
}
}
@@ -232,13 +212,12 @@ UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad1)
RoadGraphMockSource graph;
AddRoad(graph, 5.0, {m2::PointD(2,1), m2::PointD(2,2), m2::PointD(2,3)});
AddRoad(graph, 5.0, {m2::PointD(10,1), m2::PointD(10,2), m2::PointD(10,3)});
AddRoad(graph, 5.0, {m2::PointD(2,3), m2::PointD(4,3), m2::PointD(6,3), m2::PointD(8,3), m2::PointD(10,3)});
AddRoad(graph, 3.0, {m2::PointD(2,2), m2::PointD(6,2), m2::PointD(10,2)});
AddRoad(graph, 4.0, {m2::PointD(2,1), m2::PointD(10,1)});
AddRoad(graph, 5.0, {m2::PointD(2, 1), m2::PointD(2, 2), m2::PointD(2, 3)});
AddRoad(graph, 5.0, {m2::PointD(10, 1), m2::PointD(10, 2), m2::PointD(10, 3)});
AddRoad(graph, 5.0, {m2::PointD(2, 3), m2::PointD(4, 3), m2::PointD(6, 3), m2::PointD(8, 3), m2::PointD(10, 3)});
AddRoad(graph, 3.0, {m2::PointD(2, 2), m2::PointD(6, 2), m2::PointD(10, 2)});
AddRoad(graph, 4.0, {m2::PointD(2, 1), m2::PointD(10, 1)});
// path1 = 1/5 + 8/5 + 1/5 = 2
// path2 = 8/3 = 2.666(6)
@@ -247,19 +226,17 @@ UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad1)
RoutingResult<geometry::PointWithAltitude, double /* Weight */> result;
TestAStarBidirectionalAlgo algorithm;
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK,
algorithm.CalculateRoute(
graph, geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 2)), result),
algorithm.CalculateRoute(graph, geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 2)), result),
());
TEST_EQUAL(result.m_path,
vector<geometry::PointWithAltitude>(
{geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 3)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(4, 3)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(6, 3)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(8, 3)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 3)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 2))}),
vector<geometry::PointWithAltitude>({geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 3)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(4, 3)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(6, 3)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(8, 3)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 3)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 2))}),
());
TEST(AlmostEqualAbs(result.m_distance, 800451., 1.), ("Distance error:", result.m_distance));
}
@@ -270,12 +247,12 @@ UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad2)
RoadGraphMockSource graph;
AddRoad(graph, 5.0, {m2::PointD(2,1), m2::PointD(2,2), m2::PointD(2,3)});
AddRoad(graph, 5.0, {m2::PointD(10,1), m2::PointD(10,2), m2::PointD(10,3)});
AddRoad(graph, 5.0, {m2::PointD(2, 1), m2::PointD(2, 2), m2::PointD(2, 3)});
AddRoad(graph, 5.0, {m2::PointD(10, 1), m2::PointD(10, 2), m2::PointD(10, 3)});
AddRoad(graph, 5.0, {m2::PointD(2,3), m2::PointD(4,3), m2::PointD(6,3), m2::PointD(8,3), m2::PointD(10,3)});
AddRoad(graph, 4.1, {m2::PointD(2,2), m2::PointD(6,2), m2::PointD(10,2)});
AddRoad(graph, 4.4, {m2::PointD(2,1), m2::PointD(10,1)});
AddRoad(graph, 5.0, {m2::PointD(2, 3), m2::PointD(4, 3), m2::PointD(6, 3), m2::PointD(8, 3), m2::PointD(10, 3)});
AddRoad(graph, 4.1, {m2::PointD(2, 2), m2::PointD(6, 2), m2::PointD(10, 2)});
AddRoad(graph, 4.4, {m2::PointD(2, 1), m2::PointD(10, 1)});
// path1 = 1/5 + 8/5 + 1/5 = 2
// path2 = 8/4.1 = 1.95
@@ -284,15 +261,13 @@ UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad2)
RoutingResult<geometry::PointWithAltitude, double /* Weight */> result;
TestAStarBidirectionalAlgo algorithm;
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK,
algorithm.CalculateRoute(
graph, geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 2)), result),
algorithm.CalculateRoute(graph, geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 2)), result),
());
TEST_EQUAL(result.m_path,
vector<geometry::PointWithAltitude>(
{geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(6, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 2))}),
vector<geometry::PointWithAltitude>({geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(6, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 2))}),
());
TEST(AlmostEqualAbs(result.m_distance, 781458., 1.), ("Distance error:", result.m_distance));
}
@@ -303,12 +278,12 @@ UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad3)
RoadGraphMockSource graph;
AddRoad(graph, 5.0, {m2::PointD(2,1), m2::PointD(2,2), m2::PointD(2,3)});
AddRoad(graph, 5.0, {m2::PointD(10,1), m2::PointD(10,2), m2::PointD(10,3)});
AddRoad(graph, 5.0, {m2::PointD(2, 1), m2::PointD(2, 2), m2::PointD(2, 3)});
AddRoad(graph, 5.0, {m2::PointD(10, 1), m2::PointD(10, 2), m2::PointD(10, 3)});
AddRoad(graph, 4.8, {m2::PointD(2,3), m2::PointD(4,3), m2::PointD(6,3), m2::PointD(8,3), m2::PointD(10,3)});
AddRoad(graph, 3.9, {m2::PointD(2,2), m2::PointD(6,2), m2::PointD(10,2)});
AddRoad(graph, 4.9, {m2::PointD(2,1), m2::PointD(10,1)});
AddRoad(graph, 4.8, {m2::PointD(2, 3), m2::PointD(4, 3), m2::PointD(6, 3), m2::PointD(8, 3), m2::PointD(10, 3)});
AddRoad(graph, 3.9, {m2::PointD(2, 2), m2::PointD(6, 2), m2::PointD(10, 2)});
AddRoad(graph, 4.9, {m2::PointD(2, 1), m2::PointD(10, 1)});
// path1 = 1/5 + 8/4.8 + 1/5 = 2.04
// path2 = 8/3.9 = 2.05
@@ -317,17 +292,15 @@ UNIT_TEST(AStarRouter_SimpleGraph_PickTheFasterRoad3)
RoutingResult<geometry::PointWithAltitude, double /* Weight */> result;
TestAStarBidirectionalAlgo algorithm;
TEST_EQUAL(TestAStarBidirectionalAlgo::Result::OK,
algorithm.CalculateRoute(
graph, geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 2)), result),
algorithm.CalculateRoute(graph, geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 2)), result),
());
TEST_EQUAL(result.m_path,
vector<geometry::PointWithAltitude>(
{geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 1)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 1)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 2))}),
vector<geometry::PointWithAltitude>({geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 2)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(2, 1)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 1)),
geometry::MakePointWithAltitudeForTesting(m2::PointD(10, 2))}),
());
TEST(AlmostEqualAbs(result.m_distance, 814412., 1.), ("Distance error:", result.m_distance));
}
} // namespace astar_router_test
} // namespace astar_router_test

View File

@@ -37,11 +37,9 @@ public:
string GetName() const override { return "Dummy"; }
void SetGuides(GuidesTracks && /* guides */) override {}
RouterResultCode CalculateRoute(Checkpoints const & checkpoints, m2::PointD const & startDirection,
bool adjustToPrevRoute, RouterDelegate const & delegate,
Route & route) override
bool adjustToPrevRoute, RouterDelegate const & delegate, Route & route) override
{
route = Route("dummy", checkpoints.GetPoints().cbegin(), checkpoints.GetPoints().cend(),
0 /* route id */);
route = Route("dummy", checkpoints.GetPoints().cbegin(), checkpoints.GetPoints().cend(), 0 /* route id */);
for (auto const & absent : m_absent)
route.AddAbsentCountry(absent);
@@ -49,8 +47,8 @@ public:
return m_result;
}
bool FindClosestProjectionToRoad(m2::PointD const & point, m2::PointD const & direction,
double radius, EdgeProj & proj) override
bool FindClosestProjectionToRoad(m2::PointD const & point, m2::PointD const & direction, double radius,
EdgeProj & proj) override
{
return false;
}
@@ -95,8 +93,7 @@ struct DummyRoutingCallbacks
{
lock_guard<mutex> calledLock(m_lock);
++m_called;
TEST_LESS_OR_EQUAL(m_called, m_expected,
("The result callback called more times than expected."));
TEST_LESS_OR_EQUAL(m_called, m_expected, ("The result callback called more times than expected."));
}
m_cv.notify_all();
}

View File

@@ -90,14 +90,13 @@ UNIT_TEST(BFS_AllVisit_Undirected)
std::set<uint32_t> visited;
BFS<UndirectedGraph> bfs(graph);
bfs.Run(0 /* start */, true /* isOutgoing */,
[&](BFS<UndirectedGraph>::State const & state)
{
visited.emplace(state.m_vertex);
return true;
});
bfs.Run(0 /* start */, true /* isOutgoing */, [&](BFS<UndirectedGraph>::State const & state)
{
visited.emplace(state.m_vertex);
return true;
});
std::vector<uint32_t> const expectedInVisited = {1, 2, 3, 4 ,5, 6, 7, 8, 9, 10};
std::vector<uint32_t> const expectedInVisited = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for (auto const v : expectedInVisited)
TEST_NOT_EQUAL(visited.count(v), 0, ("vertex =", v, "was not visited."));
}
@@ -109,12 +108,11 @@ UNIT_TEST(BFS_AllVisit_Directed_Forward)
std::set<uint32_t> visited;
BFS<DirectedGraph> bfs(graph);
bfs.Run(0 /* start */, true /* isOutgoing */,
[&](BFS<DirectedGraph>::State const & state)
{
visited.emplace(state.m_vertex);
return true;
});
bfs.Run(0 /* start */, true /* isOutgoing */, [&](BFS<DirectedGraph>::State const & state)
{
visited.emplace(state.m_vertex);
return true;
});
std::vector<uint32_t> const expectedInVisited = {1, 2, 3, 4};
for (auto const v : expectedInVisited)
@@ -128,12 +126,11 @@ UNIT_TEST(BFS_AllVisit_Directed_Backward)
std::set<uint32_t> visited;
BFS<DirectedGraph> bfs(graph);
bfs.Run(2 /* start */, false /* isOutgoing */,
[&](BFS<DirectedGraph>::State const & state)
{
visited.emplace(state.m_vertex);
return true;
});
bfs.Run(2 /* start */, false /* isOutgoing */, [&](BFS<DirectedGraph>::State const & state)
{
visited.emplace(state.m_vertex);
return true;
});
std::vector<uint32_t> expectedInVisited = {0, 3, 4, 5, 7};
for (auto const v : expectedInVisited)
@@ -147,12 +144,11 @@ UNIT_TEST(BFS_AllVisit_DirectedCyclic)
std::set<uint32_t> visited;
BFS<DirectedGraph> bfs(graph);
bfs.Run(0 /* start */, true /* isOutgoing */,
[&](BFS<DirectedGraph>::State const & state)
{
visited.emplace(state.m_vertex);
return true;
});
bfs.Run(0 /* start */, true /* isOutgoing */, [&](BFS<DirectedGraph>::State const & state)
{
visited.emplace(state.m_vertex);
return true;
});
std::vector<uint32_t> expectedInVisited = {1, 2, 3, 4};
for (auto const v : expectedInVisited)
@@ -174,4 +170,4 @@ UNIT_TEST(BFS_ReconstructPathTest)
expected = {2, 1, 0};
TEST_EQUAL(path, expected, ());
}
} // namespace routing_test
} // namespace routing_test

View File

@@ -33,12 +33,15 @@ public:
UNIT_CLASS_TEST(CheckpointPredictorTest, CalculateDeltaMetersTest)
{
TestAlmostEqual(CheckpointPredictor::CalculateDeltaMeters(
{0.0, 0.0} /* from */, {2.0, 0.0} /* to */, {1.0, 0.0} /* between */), 0.0);
TestAlmostEqual(CheckpointPredictor::CalculateDeltaMeters(
{0.0, 0.0} /* from */, {2.0, 0.0} /* to */, {3.0, 0.0} /* between */), 222634.0);
TestAlmostEqual(CheckpointPredictor::CalculateDeltaMeters(
{0.0, 0.0} /* from */, {2.0, 0.0} /* to */, {-1.0, 0.0} /* between */), 222634.0);
TestAlmostEqual(
CheckpointPredictor::CalculateDeltaMeters({0.0, 0.0} /* from */, {2.0, 0.0} /* to */, {1.0, 0.0} /* between */),
0.0);
TestAlmostEqual(
CheckpointPredictor::CalculateDeltaMeters({0.0, 0.0} /* from */, {2.0, 0.0} /* to */, {3.0, 0.0} /* between */),
222634.0);
TestAlmostEqual(
CheckpointPredictor::CalculateDeltaMeters({0.0, 0.0} /* from */, {2.0, 0.0} /* to */, {-1.0, 0.0} /* between */),
222634.0);
}
// Zero intermediate point test.
@@ -52,7 +55,6 @@ UNIT_CLASS_TEST(CheckpointPredictorTest, PredictPositionTest1)
TEST_EQUAL(PredictPosition(intermediatePoints, m2::PointD(5.0, 0.0)), 0, ());
}
// One intermediate point test.
UNIT_CLASS_TEST(CheckpointPredictorTest, PredictPositionTest2)
{

View File

@@ -38,10 +38,8 @@ void TestZigZagUnsigned()
constexpr auto max = std::numeric_limits<T>::max();
constexpr T values[] = {0, 1, 7, max / 2, max - 1, max};
for (T prev : values)
{
for (T current : values)
TestZigZag(prev, current);
}
}
template <typename T>
@@ -53,10 +51,8 @@ void TestZigZagSigned()
constexpr auto max = std::numeric_limits<T>::max();
constexpr T values[] = {min, min + 1, min / 2, -7, -1, 0, 1, 7, max / 2, max - 1, max};
for (T prev : values)
{
for (T current : values)
TestZigZag(prev, current);
}
}
} // namespace
@@ -64,7 +60,8 @@ namespace routing_test
{
UNIT_TEST(ModuleCastTest)
{
ForEachNumber<uint8_t>([](uint8_t number) {
ForEachNumber<uint8_t>([](uint8_t number)
{
auto signedNumber = ModularCast(number);
static_assert(std::is_same<decltype(signedNumber), int8_t>::value, "int8_t expected");
TEST_EQUAL(static_cast<uint8_t>(signedNumber), number, ("signedNumber:", signedNumber));
@@ -73,22 +70,37 @@ UNIT_TEST(ModuleCastTest)
UNIT_TEST(ZigZagUint8)
{
ForEachNumber<uint8_t>([](uint8_t prev) {
ForEachNumber<uint8_t>([&](uint8_t current) { TestZigZag(prev, current); });
});
ForEachNumber<uint8_t>([](uint8_t prev)
{ ForEachNumber<uint8_t>([&](uint8_t current) { TestZigZag(prev, current); }); });
}
UNIT_TEST(ZigZagInt8)
{
ForEachNumber<int8_t>([](int8_t prev) {
ForEachNumber<int8_t>([&](int8_t current) { TestZigZag(prev, current); });
});
ForEachNumber<int8_t>([](int8_t prev) { ForEachNumber<int8_t>([&](int8_t current) { TestZigZag(prev, current); }); });
}
UNIT_TEST(ZigZagUint16) { TestZigZagUnsigned<uint16_t>(); }
UNIT_TEST(ZigZagInt16) { TestZigZagSigned<int16_t>(); }
UNIT_TEST(ZigZagUint32) { TestZigZagUnsigned<uint32_t>(); }
UNIT_TEST(ZigZagInt32) { TestZigZagSigned<int32_t>(); }
UNIT_TEST(ZigZagUint64) { TestZigZagUnsigned<uint64_t>(); }
UNIT_TEST(ZigZagInt64) { TestZigZagSigned<int64_t>(); }
UNIT_TEST(ZigZagUint16)
{
TestZigZagUnsigned<uint16_t>();
}
UNIT_TEST(ZigZagInt16)
{
TestZigZagSigned<int16_t>();
}
UNIT_TEST(ZigZagUint32)
{
TestZigZagUnsigned<uint32_t>();
}
UNIT_TEST(ZigZagInt32)
{
TestZigZagSigned<int32_t>();
}
UNIT_TEST(ZigZagUint64)
{
TestZigZagUnsigned<uint64_t>();
}
UNIT_TEST(ZigZagInt64)
{
TestZigZagSigned<int64_t>();
}
} // namespace routing_test

View File

@@ -38,8 +38,8 @@ void FillGraphWithTestInfo(CrossBorderGraph & gaph, std::shared_ptr<NumMwmIds> n
auto const [p1, id1] = GetCoordInRegion(50.88010, 4.41923, "Belgium_Flemish Brabant", numMwmIds);
auto const [p2, id2] = GetCoordInRegion(50.99043, 5.48125, "Belgium_Limburg", numMwmIds);
auto const [p3, id3] = GetCoordInRegion(50.88751, 5.92378, "Netherlands_Limburg", numMwmIds);
auto const [p4, id4] = GetCoordInRegion(
50.8734, 6.27417, "Germany_North Rhine-Westphalia_Regierungsbezirk Koln_Aachen", numMwmIds);
auto const [p4, id4] =
GetCoordInRegion(50.8734, 6.27417, "Germany_North Rhine-Westphalia_Regierungsbezirk Koln_Aachen", numMwmIds);
double constexpr avgSpeedMpS = 14.0;
@@ -100,14 +100,9 @@ void TestEqualSegments(CrossBorderSegments const & s1, CrossBorderSegments const
static double constexpr epsCoord = 1e-5;
TEST(AlmostEqualAbs(data1.m_start.m_point.GetLatLon(), data2.m_start.m_point.GetLatLon(),
epsCoord),
());
TEST(AlmostEqualAbs(data1.m_end.m_point.GetLatLon(), data2.m_end.m_point.GetLatLon(),
epsCoord),
());
TEST_EQUAL(static_cast<uint32_t>(std::ceil(data1.m_weight)),
static_cast<uint32_t>(std::ceil(data2.m_weight)), ());
TEST(AlmostEqualAbs(data1.m_start.m_point.GetLatLon(), data2.m_start.m_point.GetLatLon(), epsCoord), ());
TEST(AlmostEqualAbs(data1.m_end.m_point.GetLatLon(), data2.m_end.m_point.GetLatLon(), epsCoord), ());
TEST_EQUAL(static_cast<uint32_t>(std::ceil(data1.m_weight)), static_cast<uint32_t>(std::ceil(data2.m_weight)), ());
}
}

View File

@@ -17,15 +17,13 @@ namespace
{
NumMwmId constexpr kTestMwmId = 777;
template <typename CrossMwmId> struct CrossMwmBuilderTestFixture
template <typename CrossMwmId>
struct CrossMwmBuilderTestFixture
{
CrossMwmConnector<CrossMwmId> connector;
CrossMwmConnectorBuilder<CrossMwmId> builder;
explicit CrossMwmBuilderTestFixture(NumMwmId numMwmId = kTestMwmId)
: connector(numMwmId), builder(connector)
{
}
explicit CrossMwmBuilderTestFixture(NumMwmId numMwmId = kTestMwmId) : connector(numMwmId), builder(connector) {}
};
template <typename CrossMwmId>
@@ -69,13 +67,17 @@ void TestOneWayEnter(CrossMwmId const & crossMwmId)
TEST_EQUAL(test.connector.GetNumEnters(), 1, ());
TEST_EQUAL(test.connector.GetNumExits(), 0, ());
TEST(!test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, true /* forward */),
true /* isOutgoing */), ());
true /* isOutgoing */),
());
TEST(test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, true /* forward */),
false /* isOutgoing */), ());
false /* isOutgoing */),
());
TEST(!test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, false /* forward */),
true /* isOutgoing */), ());
true /* isOutgoing */),
());
TEST(!test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, false /* forward */),
false /* isOutgoing */), ());
false /* isOutgoing */),
());
}
template <typename CrossMwmId>
@@ -91,13 +93,17 @@ void TestOneWayExit(CrossMwmId const & crossMwmId)
TEST_EQUAL(test.connector.GetNumEnters(), 0, ());
TEST_EQUAL(test.connector.GetNumExits(), 1, ());
TEST(test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, true /* forward */),
true /* isOutgoing */), ());
true /* isOutgoing */),
());
TEST(!test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, true /* forward */),
false /* isOutgoing */), ());
false /* isOutgoing */),
());
TEST(!test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, false /* forward */),
true /* isOutgoing */), ());
true /* isOutgoing */),
());
TEST(!test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, false /* forward */),
false /* isOutgoing */), ());
false /* isOutgoing */),
());
}
template <typename CrossMwmId>
@@ -113,13 +119,17 @@ void TestTwoWayEnter(CrossMwmId const & crossMwmId)
TEST_EQUAL(test.connector.GetNumEnters(), 1, ());
TEST_EQUAL(test.connector.GetNumExits(), 1, ());
TEST(!test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, true /* forward */),
true /* isOutgoing */), ());
true /* isOutgoing */),
());
TEST(test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, true /* forward */),
false /* isOutgoing */), ());
false /* isOutgoing */),
());
TEST(test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, false /* forward */),
true /* isOutgoing */), ());
true /* isOutgoing */),
());
TEST(!test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, false /* forward */),
false /* isOutgoing */), ());
false /* isOutgoing */),
());
}
template <typename CrossMwmId>
@@ -135,13 +145,17 @@ void TestTwoWayExit(CrossMwmId const & crossMwmId)
TEST_EQUAL(test.connector.GetNumEnters(), 1, ());
TEST_EQUAL(test.connector.GetNumExits(), 1, ());
TEST(test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, true /* forward */),
true /* isOutgoing */), ());
true /* isOutgoing */),
());
TEST(!test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, true /* forward */),
false /* isOutgoing */), ());
false /* isOutgoing */),
());
TEST(!test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, false /* forward */),
true /* isOutgoing */), ());
true /* isOutgoing */),
());
TEST(test.connector.IsTransition(Segment(kTestMwmId, featureId, segmentIdx, false /* forward */),
false /* isOutgoing */), ());
false /* isOutgoing */),
());
}
template <typename CrossMwmId>
@@ -190,12 +204,10 @@ void TestSerialization(CrossMwmConnectorBuilderEx<CrossMwmId> & builder)
TEST(test.connector.HasWeights(), ());
TestOutgoingEdges(test.connector, Segment(kTestMwmId, 10, 1, true /* forward */),
{{Segment(kTestMwmId, 20, 2, false /* forward */),
RouteWeight::FromCrossMwmWeight(kEdgesWeight)}});
{{Segment(kTestMwmId, 20, 2, false /* forward */), RouteWeight::FromCrossMwmWeight(kEdgesWeight)}});
TestOutgoingEdges(test.connector, Segment(kTestMwmId, 20, 2, true /* forward */),
{{Segment(kTestMwmId, 20, 2, false /* forward */),
RouteWeight::FromCrossMwmWeight(kEdgesWeight)}});
{{Segment(kTestMwmId, 20, 2, false /* forward */), RouteWeight::FromCrossMwmWeight(kEdgesWeight)}});
}
void GetCrossMwmId(uint32_t i, base::GeoObjectId & id)
@@ -213,7 +225,7 @@ void TestWeightsSerialization()
{
size_t constexpr kNumTransitions = 3;
uint32_t constexpr segmentIdx = 1;
double const weights[] = { 4.0, 20.0, connector::kNoRoute, 12.0, connector::kNoRoute, 40.0, 48.0, 24.0, 12.0 };
double const weights[] = {4.0, 20.0, connector::kNoRoute, 12.0, connector::kNoRoute, 40.0, 48.0, 24.0, 12.0};
TEST_EQUAL(std::size(weights), kNumTransitions * kNumTransitions, ());
std::map<std::pair<Segment, Segment>, double> expectedWeights;
@@ -221,7 +233,7 @@ void TestWeightsSerialization()
vector<uint8_t> buffer;
{
CrossMwmConnectorBuilderEx<CrossMwmId> builder;
for (uint32_t featureId : { 2, 0, 1 }) // reshuffled
for (uint32_t featureId : {2, 0, 1}) // reshuffled
{
CrossMwmId id;
GetCrossMwmId(featureId, id);
@@ -320,8 +332,8 @@ UNIT_TEST(CMWMC_Serialization)
{
CrossMwmConnectorBuilderEx<TransitId> builder;
// osmId featureId, segmentIdx, roadMask, oneWayMask, forwardIsEnter
builder.AddTransition(TransitId(1ULL /* stop 1 id */, 2ULL /* stop 2 id */, 1ULL /* line id */),
10, 1, kCarMask, kCarMask, true);
builder.AddTransition(TransitId(1ULL /* stop 1 id */, 2ULL /* stop 2 id */, 1ULL /* line id */), 10, 1, kCarMask,
kCarMask, true);
builder.AddTransition(TransitId(1ULL, 3ULL, 1ULL), 20, 2, kCarMask, 0, true);
builder.AddTransition(TransitId(1ULL, 3ULL, 2ULL), 30, 3, kPedestrianMask, kCarMask, true);
TestSerialization(builder);
@@ -333,4 +345,4 @@ UNIT_TEST(CMWMC_WeightsSerialization)
TestWeightsSerialization<base::GeoObjectId>();
TestWeightsSerialization<TransitId>();
}
} // namespace cross_mwm_connector_test
} // namespace cross_mwm_connector_test

View File

@@ -78,8 +78,7 @@ using Algorithm = AStarAlgorithm<Segment, SegmentEdge, RouteWeight>;
UNIT_TEST(XYGraph)
{
unique_ptr<WorldGraph> graph = BuildXYGraph();
auto const start =
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *graph);
auto const start = MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *graph);
auto const finish = MakeFakeEnding(5, 0, m2::PointD(2, 3), *graph);
auto starter = MakeStarter(start, finish, *graph);
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 1}, {2, 2}, {2, 3}};
@@ -90,36 +89,28 @@ UNIT_TEST(XYGraph)
UNIT_CLASS_TEST(RestrictionTest, XYGraph_RestrictionF1F3Only)
{
Init(BuildXYGraph());
RestrictionVec restrictionsOnly = {
{1 /* feature from */, 3 /* feature to */}
};
RestrictionVec restrictionsOnly = {{1 /* feature from */, 3 /* feature to */}};
RestrictionVec restrictionsNo;
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 1}, {2, 2}, {2, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), std::move(restrictionsNo), *this);
}
// Route through XY graph with one restriction (type only) from F3 to F5.
UNIT_CLASS_TEST(RestrictionTest, XYGraph_RestrictionF3F5Only)
{
Init(BuildXYGraph());
RestrictionVec restrictionsOnly = {
{3 /* feature from */, 5 /* feature to */}
};
RestrictionVec restrictionsOnly = {{3 /* feature from */, 5 /* feature to */}};
RestrictionVec restrictionsNo;
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 1}, {2, 2}, {2, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), std::move(restrictionsNo), *this);
}
// Cumulative case. Route through XY graph with two restricitons (type only) applying
@@ -127,19 +118,15 @@ UNIT_CLASS_TEST(RestrictionTest, XYGraph_RestrictionF3F5Only)
UNIT_CLASS_TEST(RestrictionTest, XYGraph_PermutationsF3F5OnlyF1F3Only)
{
Init(BuildXYGraph());
RestrictionVec restrictionsOnly = {
{1 /* feature from */, 3 /* feature to */},
{3 /* feature from */, 5 /* feature to */}
};
RestrictionVec restrictionsOnly = {{1 /* feature from */, 3 /* feature to */},
{3 /* feature from */, 5 /* feature to */}};
RestrictionVec restrictionsNo;
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 1}, {2, 2}, {2, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), std::move(restrictionsNo), *this);
}
// Cumulative case. Route through XY graph with two restricitons (type only and type no) applying
@@ -148,21 +135,15 @@ UNIT_CLASS_TEST(RestrictionTest, XYGraph_PermutationsF3F5OnlyAndF0F2No)
{
Init(BuildXYGraph());
RestrictionVec restrictionsNo = {
{1 /* feature from */, 2 /* feature to */}
};
RestrictionVec restrictionsNo = {{1 /* feature from */, 2 /* feature to */}};
RestrictionVec restrictionsOnly = {
{3 /* feature from */, 5 /* feature to */}
};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
RestrictionVec restrictionsOnly = {{3 /* feature from */, 5 /* feature to */}};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 1}, {2, 2}, {2, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), std::move(restrictionsNo), *this);
}
// Cumulative case. Trying to build route through XY graph with two restricitons applying
@@ -171,19 +152,13 @@ UNIT_CLASS_TEST(RestrictionTest, XYGraph_PermutationsF3F5OnlyAndF0F2No)
UNIT_CLASS_TEST(RestrictionTest, XYGraph_RestrictionF3F5OnlyAndF1F3No)
{
Init(BuildXYGraph());
RestrictionVec restrictionsNo = {
{1 /* feature from */, 3 /* feature to */}
};
RestrictionVec restrictionsOnly = {
{3 /* feature from */, 5 /* feature to */}
};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
RestrictionVec restrictionsNo = {{1 /* feature from */, 3 /* feature to */}};
RestrictionVec restrictionsOnly = {{3 /* feature from */, 5 /* feature to */}};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
TestRestrictions(
{} /* expectedGeom */, Algorithm::Result::NoPath,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions({} /* expectedGeom */, Algorithm::Result::NoPath,
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(5, 0, m2::PointD(2, 3), *m_graph), std::move(restrictionsNo), *this);
}
// Finish
@@ -249,7 +224,6 @@ unique_ptr<SingleVehicleWorldGraph> BuildXXGraph()
return BuildWorldGraph(std::move(loader), estimator, joints);
}
// 2 * *
// ↗ ↘
// F4 F5
@@ -283,12 +257,12 @@ unique_ptr<SingleVehicleWorldGraph> BuildCubeGraph()
RoadGeometry::Points({{2.0, 2.0}, {3.0, 1.0}}));
vector<Joint> const joints = {
MakeJoint({{0 /* feature id */, 0 /* point id */}}), /* joint at point (2, -1) */
MakeJoint({{0, 1}, {1, 0}, {2, 0}}), /* joint at point (2, 0) */
MakeJoint({{2, 1}, {4, 0}}), /* joint at point (1, 1) */
MakeJoint({{4, 1}, {5, 0}}), /* joint at point (2, 2) */
MakeJoint({{5, 1}, {3, 0}}), /* joint at point (3, 1) */
MakeJoint({{1, 1}, {3, 1}}), /* joint at point (3, 0) */
MakeJoint({{0 /* feature id */, 0 /* point id */}}), /* joint at point (2, -1) */
MakeJoint({{0, 1}, {1, 0}, {2, 0}}), /* joint at point (2, 0) */
MakeJoint({{2, 1}, {4, 0}}), /* joint at point (1, 1) */
MakeJoint({{4, 1}, {5, 0}}), /* joint at point (2, 2) */
MakeJoint({{5, 1}, {3, 0}}), /* joint at point (3, 1) */
MakeJoint({{1, 1}, {3, 1}}), /* joint at point (3, 0) */
};
traffic::TrafficCache const trafficCache;
@@ -302,10 +276,9 @@ UNIT_CLASS_TEST(RestrictionTest, XXGraph)
Init(BuildXXGraph());
RestrictionVec restrictions = {};
vector<m2::PointD> const expectedGeom = {{2 /* x */, -1 /* y */}, {2, 0}, {1, 1}, {2, 2}, {3, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, -1), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(3, 3), *m_graph), std::move(restrictions), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, -1), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(3, 3), *m_graph), std::move(restrictions), *this);
}
// Cumulative case. Route through XX graph with two restricitons (type only) applying
@@ -314,34 +287,26 @@ UNIT_CLASS_TEST(RestrictionTest, XXGraph_PermutationsF1F3OnlyAndF3F6Only)
{
Init(BuildXXGraph());
RestrictionVec restrictionsNo;
RestrictionVec restrictionsOnly = {
{1 /* feature from */, 3 /* feature to */},
{3 /* feature from */, 6 /* feature to */}
};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
RestrictionVec restrictionsOnly = {{1 /* feature from */, 3 /* feature to */},
{3 /* feature from */, 6 /* feature to */}};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {{2 /* x */, -1 /* y */}, {2, 0}, {1, 1}, {2, 2}, {3, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, -1), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(3, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, -1), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(3, 3), *m_graph), std::move(restrictionsNo), *this);
}
// Route through XX graph with one restriciton (type no) from F1 to F3.
UNIT_CLASS_TEST(RestrictionTest, XXGraph_RestrictionF1F3No)
{
Init(BuildXXGraph());
RestrictionVec restrictionsNo = {
{1 /* feature from */, 3 /* feature to */}
};
vector<m2::PointD> const expectedGeom = {
{2 /* x */, -1 /* y */}, {2, 0}, {3, 0}, {3, 1}, {2, 2}, {3, 3}};
RestrictionVec restrictionsNo = {{1 /* feature from */, 3 /* feature to */}};
vector<m2::PointD> const expectedGeom = {{2 /* x */, -1 /* y */}, {2, 0}, {3, 0}, {3, 1}, {2, 2}, {3, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, -1), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(3, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, -1), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(3, 3), *m_graph), std::move(restrictionsNo), *this);
}
// Cumulative case. Route through XX graph with four restricitons of different types applying
@@ -349,24 +314,17 @@ UNIT_CLASS_TEST(RestrictionTest, XXGraph_RestrictionF1F3No)
UNIT_CLASS_TEST(RestrictionTest, XXGraph_PermutationsF1F3NoF7F8OnlyF8F4OnlyF4F6Only)
{
Init(BuildXXGraph());
RestrictionVec restrictionsNo = {
{1 /* feature from */, 3 /* feature to */}
};
RestrictionVec restrictionsNo = {{1 /* feature from */, 3 /* feature to */}};
RestrictionVec restrictionsOnly = {
{4 /* feature from */, 6 /* feature to */},
{7 /* feature from */, 8 /* feature to */},
{8 /* feature from */, 4 /* feature to */}
};
RestrictionVec restrictionsOnly = {{4 /* feature from */, 6 /* feature to */},
{7 /* feature from */, 8 /* feature to */},
{8 /* feature from */, 4 /* feature to */}};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
vector<m2::PointD> const expectedGeom = {
{2 /* x */, -1 /* y */}, {2, 0}, {3, 0}, {3, 1}, {2, 2}, {3, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, -1), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(3, 3), *m_graph), std::move(restrictionsNo), *this);
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {{2 /* x */, -1 /* y */}, {2, 0}, {3, 0}, {3, 1}, {2, 2}, {3, 3}};
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(9 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, -1), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(3, 3), *m_graph), std::move(restrictionsNo), *this);
}
UNIT_CLASS_TEST(RestrictionTest, XXGraph_CheckOnlyRestriction)
@@ -375,20 +333,18 @@ UNIT_CLASS_TEST(RestrictionTest, XXGraph_CheckOnlyRestriction)
m2::PointD const start(2.0, -1.0);
m2::PointD const finish(3.0, 0.2);
auto const test = [&](vector<m2::PointD> const & expectedGeom, RestrictionVec && restrictionsNo) {
auto const test = [&](vector<m2::PointD> const & expectedGeom, RestrictionVec && restrictionsNo)
{
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, start, *m_graph),
MakeFakeEnding(3 /* featureId */, 0 /* segmentIdx */, finish, *m_graph),
std::move(restrictionsNo), *this);
expectedGeom, Algorithm::Result::OK, MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, start, *m_graph),
MakeFakeEnding(3 /* featureId */, 0 /* segmentIdx */, finish, *m_graph), std::move(restrictionsNo), *this);
};
RestrictionVec restrictionsOnly = {
{0 /* feature from */, 2 /* feature to */},
{0 /* feature from */, 2 /* feature to */},
};
RestrictionVec restrictionsNo;
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
// Check that without restrictions we can find path better.
test({start, {2, 0}, {1, 1}, {2, 2}, {3, 1}, finish}, std::move(restrictionsNo));

View File

@@ -43,8 +43,7 @@ FakeGraph ConstructFakeGraph(uint32_t numerationStart, uint32_t numFake, uint32_
TEST_EQUAL(fakeGraph.GetSize(), 0, ("Constructed fake graph not empty"));
if (numFake < 1)
{
CHECK_EQUAL(numReal, 0,
("Construction of non-empty fake graph without pure fake vertices not supported."));
CHECK_EQUAL(numReal, 0, ("Construction of non-empty fake graph without pure fake vertices not supported."));
return fakeGraph;
}
@@ -53,8 +52,7 @@ FakeGraph ConstructFakeGraph(uint32_t numerationStart, uint32_t numFake, uint32_
fakeGraph.AddStandaloneVertex(startSegment, startVertex);
// Add pure fake.
for (uint32_t prevNumber = numerationStart; prevNumber + 1 < numerationStart + numFake + numReal;
++prevNumber)
for (uint32_t prevNumber = numerationStart; prevNumber + 1 < numerationStart + numFake + numReal; ++prevNumber)
{
bool const newIsReal = prevNumber + 1 >= numerationStart + numFake;
auto const prevSegment = GetSegment(prevNumber);
@@ -62,8 +60,8 @@ FakeGraph ConstructFakeGraph(uint32_t numerationStart, uint32_t numFake, uint32_
auto const newVertex = GetFakeVertex(prevNumber + 1);
auto const realSegment = GetSegment(prevNumber + 1, true /* isReal */);
fakeGraph.AddVertex(prevSegment, newSegment, newVertex, true /* isOutgoing */,
newIsReal /* isPartOfReal */, realSegment);
fakeGraph.AddVertex(prevSegment, newSegment, newVertex, true /* isOutgoing */, newIsReal /* isPartOfReal */,
realSegment);
// Test segment to vertex mapping.
TEST_EQUAL(fakeGraph.GetVertex(newSegment), newVertex, ("Wrong segment to vertex mapping."));
@@ -79,16 +77,13 @@ FakeGraph ConstructFakeGraph(uint32_t numerationStart, uint32_t numFake, uint32_
Segment realFound;
if (newIsReal)
{
TEST_EQUAL(fakeGraph.FindReal(newSegment, realFound), true,
("Unexpected real segment found."));
TEST_EQUAL(fakeGraph.FindReal(newSegment, realFound), true, ("Unexpected real segment found."));
TEST_EQUAL(realSegment, realFound, ("Wrong fake to real mapping."));
TEST_EQUAL(fakeGraph.GetFake(realSegment), set<Segment>{newSegment},
("Unexpected fake segment found."));
TEST_EQUAL(fakeGraph.GetFake(realSegment), set<Segment>{newSegment}, ("Unexpected fake segment found."));
}
else
{
TEST_EQUAL(fakeGraph.FindReal(newSegment, realFound), false,
("Unexpected real segment found."));
TEST_EQUAL(fakeGraph.FindReal(newSegment, realFound), false, ("Unexpected real segment found."));
TEST(fakeGraph.GetFake(realSegment).empty(), ("Unexpected fake segment found."));
}
}
@@ -106,8 +101,7 @@ UNIT_TEST(FakeGraphTest)
auto fakeGraph0 = ConstructFakeGraph(0, fake0, real0);
TEST_EQUAL(fakeGraph0.GetSize(), fake0 + real0, ("Wrong fake graph size"));
auto const fakeGraph1 =
ConstructFakeGraph(static_cast<uint32_t>(fakeGraph0.GetSize()), fake1, real1);
auto const fakeGraph1 = ConstructFakeGraph(static_cast<uint32_t>(fakeGraph0.GetSize()), fake1, real1);
TEST_EQUAL(fakeGraph1.GetSize(), fake1 + real1, ("Wrong fake graph size"));
fakeGraph0.Append(fakeGraph1);
@@ -119,24 +113,20 @@ UNIT_TEST(FakeGraphTest)
auto const segmentFrom = GetSegment(i);
auto const segmentTo = GetSegment(i + 1);
TEST_EQUAL(fakeGraph0.GetVertex(segmentFrom), GetFakeVertex(i),
("Wrong segment to vertex mapping."));
TEST_EQUAL(fakeGraph0.GetVertex(segmentTo), GetFakeVertex(i + 1),
("Wrong segment to vertex mapping."));
TEST_EQUAL(fakeGraph0.GetVertex(segmentFrom), GetFakeVertex(i), ("Wrong segment to vertex mapping."));
TEST_EQUAL(fakeGraph0.GetVertex(segmentTo), GetFakeVertex(i + 1), ("Wrong segment to vertex mapping."));
// No connection to next fake segment; next segment was in separate fake graph before Append.
if (i + 1 == fake0 + real0)
{
TEST(fakeGraph0.GetEdges(segmentFrom, true /* isOutgoing */).empty(),
("Wrong ingoing edges set."));
TEST(fakeGraph0.GetEdges(segmentTo, false /* isOutgoing */).empty(),
("Wrong ingoing edges set."));
TEST(fakeGraph0.GetEdges(segmentFrom, true /* isOutgoing */).empty(), ("Wrong ingoing edges set."));
TEST(fakeGraph0.GetEdges(segmentTo, false /* isOutgoing */).empty(), ("Wrong ingoing edges set."));
}
else
{
TEST_EQUAL(fakeGraph0.GetEdges(segmentFrom, true /* isOutgoing */), set<Segment>{segmentTo},
("Wrong ingoing edges set."));
TEST_EQUAL(fakeGraph0.GetEdges(segmentTo, false /* isOutgoing */),
set<Segment>{segmentFrom}, ("Wrong ingoing edges set."));
TEST_EQUAL(fakeGraph0.GetEdges(segmentTo, false /* isOutgoing */), set<Segment>{segmentFrom},
("Wrong ingoing edges set."));
}
}
}

View File

@@ -10,8 +10,8 @@ using namespace routing;
namespace
{
static const m2::PolylineD kTestDirectedPolyline1(std::vector<m2::PointD>{{0.0, 0.0}, {3.0, 0.0}, {5.0, 0.0}});
static const m2::PolylineD kTestDirectedPolyline2(std::vector<m2::PointD>{{6.0, 0.0}, {7.0, 0.0}});
static m2::PolylineD const kTestDirectedPolyline1(std::vector<m2::PointD>{{0.0, 0.0}, {3.0, 0.0}, {5.0, 0.0}});
static m2::PolylineD const kTestDirectedPolyline2(std::vector<m2::PointD>{{6.0, 0.0}, {7.0, 0.0}});
} // namespace
UNIT_TEST(FollowedPolylineAppend)
@@ -73,8 +73,7 @@ UNIT_TEST(FollowedPolylineDistanceCalculationTest)
// Test full length case.
FollowedPolyline polyline(kTestDirectedPolyline1.Begin(), kTestDirectedPolyline1.End());
double distance = polyline.GetDistanceM(polyline.Begin(), polyline.End());
double masterDistance = mercator::DistanceOnEarth(kTestDirectedPolyline1.Front(),
kTestDirectedPolyline1.Back());
double masterDistance = mercator::DistanceOnEarth(kTestDirectedPolyline1.Front(), kTestDirectedPolyline1.Back());
TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
distance = polyline.GetTotalDistanceMeters();
TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
@@ -82,8 +81,7 @@ UNIT_TEST(FollowedPolylineDistanceCalculationTest)
// Test partial length case.
polyline.UpdateProjection(mercator::RectByCenterXYAndSizeInMeters({3, 0}, 2));
distance = polyline.GetDistanceM(polyline.GetCurrentIter(), polyline.End());
masterDistance = mercator::DistanceOnEarth(kTestDirectedPolyline1.GetPoint(1),
kTestDirectedPolyline1.Back());
masterDistance = mercator::DistanceOnEarth(kTestDirectedPolyline1.GetPoint(1), kTestDirectedPolyline1.Back());
TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
distance = polyline.GetDistanceToEndMeters();
TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
@@ -91,8 +89,7 @@ UNIT_TEST(FollowedPolylineDistanceCalculationTest)
// Test point in the middle case.
polyline.UpdateProjection(mercator::RectByCenterXYAndSizeInMeters({4, 0}, 2));
distance = polyline.GetDistanceM(polyline.GetCurrentIter(), polyline.End());
masterDistance = mercator::DistanceOnEarth(m2::PointD(4, 0),
kTestDirectedPolyline1.Back());
masterDistance = mercator::DistanceOnEarth(m2::PointD(4, 0), kTestDirectedPolyline1.Back());
TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
distance = polyline.GetDistanceToEndMeters();
TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
@@ -121,8 +118,7 @@ UNIT_TEST(FollowedPolylineGetDistanceFromBeginM)
polyline.UpdateProjection(mercator::RectByCenterXYAndSizeInMeters(point, 2));
double const distance = polyline.GetDistanceFromStartMeters();
double const masterDistance =
mercator::DistanceOnEarth(kTestDirectedPolyline1.Front(), point);
double const masterDistance = mercator::DistanceOnEarth(kTestDirectedPolyline1.Front(), point);
TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
}
} // namespace routing_test

View File

@@ -95,8 +95,7 @@ UNIT_TEST(Guides_FinishAndStartAttached)
auto const links = guides.GetOsmConnections(checkpointIdx);
TEST(!links.empty(), ());
bool const isCheckpointNear =
guides.FitsForDirectLinkToGuide(checkpointIdx, checkpoints.size());
bool const isCheckpointNear = guides.FitsForDirectLinkToGuide(checkpointIdx, checkpoints.size());
auto const ending = guides.GetFakeEnding(checkpointIdx);
// Initial projection to guides track.

View File

@@ -71,16 +71,14 @@ void TestRoute(FakeEnding const & start, FakeEnding const & finish, size_t expec
if (expectedWeight != kUnknownWeight)
{
double constexpr kEpsilon = 0.01;
TEST(AlmostEqualRel(timeSec, expectedWeight, kEpsilon),
("Expected weight:", expectedWeight, "got:", timeSec));
TEST(AlmostEqualRel(timeSec, expectedWeight, kEpsilon), ("Expected weight:", expectedWeight, "got:", timeSec));
}
if (expectedRoute)
TEST_EQUAL(noFakeRoute, *expectedRoute, ());
}
void TestEdges(IndexGraph & graph, Segment const & segment, vector<Segment> const & expectedTargets,
bool isOutgoing)
void TestEdges(IndexGraph & graph, Segment const & segment, vector<Segment> const & expectedTargets, bool isOutgoing)
{
ASSERT(segment.IsForward() || !graph.GetRoadGeometry(segment.GetFeatureId()).IsOneWay(), ());
@@ -99,19 +97,20 @@ void TestEdges(IndexGraph & graph, Segment const & segment, vector<Segment> cons
TEST_EQUAL(targets, sortedExpectedTargets, ());
}
void TestOutgoingEdges(IndexGraph & graph, Segment const & segment,
vector<Segment> const & expectedTargets)
void TestOutgoingEdges(IndexGraph & graph, Segment const & segment, vector<Segment> const & expectedTargets)
{
TestEdges(graph, segment, expectedTargets, true /* isOutgoing */);
}
void TestIngoingEdges(IndexGraph & graph, Segment const & segment,
vector<Segment> const & expectedTargets)
void TestIngoingEdges(IndexGraph & graph, Segment const & segment, vector<Segment> const & expectedTargets)
{
TestEdges(graph, segment, expectedTargets, false /* isOutgoing */);
}
uint32_t AbsDelta(uint32_t v0, uint32_t v1) { return v0 > v1 ? v0 - v1 : v1 - v0; }
uint32_t AbsDelta(uint32_t v0, uint32_t v1)
{
return v0 > v1 ? v0 - v1 : v1 - v0;
}
// R4 (one way down)
//
@@ -130,13 +129,10 @@ uint32_t AbsDelta(uint32_t v0, uint32_t v1) { return v0 > v1 ? v0 - v1 : v1 - v0
UNIT_TEST(EdgesTest)
{
unique_ptr<TestGeometryLoader> loader = make_unique<TestGeometryLoader>();
loader->AddRoad(
0 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{0.0, 0.0}, {1.0, 0.0}, {2.0, 0.0}, {3.0, 0.0}, {4.0, 0.0}}));
loader->AddRoad(1 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{1.0, -1.0}, {3.0, -1.0}}));
loader->AddRoad(2 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{1.0, -1.0}, {3.0, -1.0}}));
loader->AddRoad(0 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{0.0, 0.0}, {1.0, 0.0}, {2.0, 0.0}, {3.0, 0.0}, {4.0, 0.0}}));
loader->AddRoad(1 /* featureId */, false, 1.0 /* speed */, RoadGeometry::Points({{1.0, -1.0}, {3.0, -1.0}}));
loader->AddRoad(2 /* featureId */, false, 1.0 /* speed */, RoadGeometry::Points({{1.0, -1.0}, {3.0, -1.0}}));
loader->AddRoad(3 /* featureId */, true, 1.0 /* speed */,
RoadGeometry::Points({{1.0, 1.0}, {1.0, 0.0}, {1.0, -1.0}}));
loader->AddRoad(4 /* featureId */, true, 1.0 /* speed */,
@@ -154,33 +150,27 @@ UNIT_TEST(EdgesTest)
joints.emplace_back(MakeJoint({{2, 1}, {4, 2}})); // J5
graph.Import(joints);
TestOutgoingEdges(
graph, {kTestNumMwmId, 0 /* featureId */, 0 /* segmentIdx */, true /* forward */},
{{kTestNumMwmId, 0, 0, false}, {kTestNumMwmId, 0, 1, true}, {kTestNumMwmId, 3, 1, true}});
TestOutgoingEdges(graph, {kTestNumMwmId, 0 /* featureId */, 0 /* segmentIdx */, true /* forward */},
{{kTestNumMwmId, 0, 0, false}, {kTestNumMwmId, 0, 1, true}, {kTestNumMwmId, 3, 1, true}});
TestIngoingEdges(graph, {kTestNumMwmId, 0, 0, true}, {{kTestNumMwmId, 0, 0, false}});
TestOutgoingEdges(graph, {kTestNumMwmId, 0, 0, false}, {{kTestNumMwmId, 0, 0, true}});
TestIngoingEdges(
graph, {kTestNumMwmId, 0, 0, false},
{{kTestNumMwmId, 0, 0, true}, {kTestNumMwmId, 0, 1, false}, {kTestNumMwmId, 3, 0, true}});
TestIngoingEdges(graph, {kTestNumMwmId, 0, 0, false},
{{kTestNumMwmId, 0, 0, true}, {kTestNumMwmId, 0, 1, false}, {kTestNumMwmId, 3, 0, true}});
TestOutgoingEdges(
graph, {kTestNumMwmId, 0, 2, true},
{{kTestNumMwmId, 0, 2, false}, {kTestNumMwmId, 0, 3, true}, {kTestNumMwmId, 4, 1, true}});
TestOutgoingEdges(graph, {kTestNumMwmId, 0, 2, true},
{{kTestNumMwmId, 0, 2, false}, {kTestNumMwmId, 0, 3, true}, {kTestNumMwmId, 4, 1, true}});
TestIngoingEdges(graph, {kTestNumMwmId, 0, 2, true}, {{kTestNumMwmId, 0, 1, true}});
TestOutgoingEdges(graph, {kTestNumMwmId, 0, 2, false}, {{kTestNumMwmId, 0, 1, false}});
TestIngoingEdges(
graph, {kTestNumMwmId, 0, 2, false},
{{kTestNumMwmId, 0, 2, true}, {kTestNumMwmId, 0, 3, false}, {kTestNumMwmId, 4, 0, true}});
TestIngoingEdges(graph, {kTestNumMwmId, 0, 2, false},
{{kTestNumMwmId, 0, 2, true}, {kTestNumMwmId, 0, 3, false}, {kTestNumMwmId, 4, 0, true}});
TestOutgoingEdges(
graph, {kTestNumMwmId, 3, 0, true},
{{kTestNumMwmId, 3, 1, true}, {kTestNumMwmId, 0, 0, false}, {kTestNumMwmId, 0, 1, true}});
TestOutgoingEdges(graph, {kTestNumMwmId, 3, 0, true},
{{kTestNumMwmId, 3, 1, true}, {kTestNumMwmId, 0, 0, false}, {kTestNumMwmId, 0, 1, true}});
TestIngoingEdges(graph, {kTestNumMwmId, 3, 0, true}, {{kTestNumMwmId, 2, 0, false}});
TestOutgoingEdges(graph, {kTestNumMwmId, 4, 1, true}, {{kTestNumMwmId, 2, 0, false}});
TestIngoingEdges(
graph, {kTestNumMwmId, 4, 1, true},
{{kTestNumMwmId, 4, 0, true}, {kTestNumMwmId, 0, 2, true}, {kTestNumMwmId, 0, 3, false}});
TestIngoingEdges(graph, {kTestNumMwmId, 4, 1, true},
{{kTestNumMwmId, 4, 0, true}, {kTestNumMwmId, 0, 2, true}, {kTestNumMwmId, 0, 3, false}});
}
// Roads R1:
@@ -194,23 +184,19 @@ UNIT_TEST(EdgesTest)
UNIT_TEST(FindPathCross)
{
unique_ptr<TestGeometryLoader> loader = make_unique<TestGeometryLoader>();
loader->AddRoad(
0 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{-2.0, 0.0}, {-1.0, 0.0}, {0.0, 0.0}, {1.0, 0.0}, {2.0, 0.0}}));
loader->AddRoad(
1 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{0.0, -2.0}, {0.0, -1.0}, {0.0, 0.0}, {0.0, 1.0}, {0.0, 2.0}}));
loader->AddRoad(0 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{-2.0, 0.0}, {-1.0, 0.0}, {0.0, 0.0}, {1.0, 0.0}, {2.0, 0.0}}));
loader->AddRoad(1 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{0.0, -2.0}, {0.0, -1.0}, {0.0, 0.0}, {0.0, 1.0}, {0.0, 2.0}}));
traffic::TrafficCache const trafficCache;
shared_ptr<EdgeEstimator> estimator = CreateEstimatorForCar(trafficCache);
unique_ptr<WorldGraph> worldGraph =
BuildWorldGraph(std::move(loader), estimator, {MakeJoint({{0, 2}, {1, 2}})});
unique_ptr<WorldGraph> worldGraph = BuildWorldGraph(std::move(loader), estimator, {MakeJoint({{0, 2}, {1, 2}})});
vector<FakeEnding> endPoints;
for (uint32_t i = 0; i < 4; ++i)
{
endPoints.push_back(MakeFakeEnding(0 /* featureId */, i /* segmentIdx */,
m2::PointD(-1.5 + i, 0.0), *worldGraph));
endPoints.push_back(MakeFakeEnding(0 /* featureId */, i /* segmentIdx */, m2::PointD(-1.5 + i, 0.0), *worldGraph));
endPoints.push_back(MakeFakeEnding(1, i, m2::PointD(0.0, -1.5 + i), *worldGraph));
}
@@ -219,8 +205,7 @@ UNIT_TEST(FindPathCross)
for (auto const & finish : endPoints)
{
uint32_t expectedLength = 0;
if (start.m_projections[0].m_segment.GetFeatureId() ==
finish.m_projections[0].m_segment.GetFeatureId())
if (start.m_projections[0].m_segment.GetFeatureId() == finish.m_projections[0].m_segment.GetFeatureId())
{
expectedLength = AbsDelta(start.m_projections[0].m_segment.GetSegmentIdx(),
finish.m_projections[0].m_segment.GetSegmentIdx()) +
@@ -238,8 +223,7 @@ UNIT_TEST(FindPathCross)
else
expectedLength += finish.m_projections[0].m_segment.GetSegmentIdx() - 1;
}
TestRoute(start, finish, expectedLength, nullptr /* expectedRoute */, kUnknownWeight,
*worldGraph);
TestRoute(start, finish, expectedLength, nullptr /* expectedRoute */, kUnknownWeight, *worldGraph);
}
}
}
@@ -276,10 +260,8 @@ UNIT_TEST(FindPathManhattan)
vector<Joint> joints;
for (uint32_t i = 0; i < kCitySize; ++i)
{
for (uint32_t j = 0; j < kCitySize; ++j)
joints.emplace_back(MakeJoint({{i, j}, {j + kCitySize, i}}));
}
unique_ptr<WorldGraph> worldGraph = BuildWorldGraph(std::move(loader), estimator, joints);
@@ -288,10 +270,9 @@ UNIT_TEST(FindPathManhattan)
{
for (uint32_t segmentId = 0; segmentId < kCitySize - 1; ++segmentId)
{
endPoints.push_back(MakeFakeEnding(featureId, segmentId,
m2::PointD(0.5 + segmentId, featureId), *worldGraph));
endPoints.push_back(MakeFakeEnding(featureId + kCitySize, segmentId,
m2::PointD(featureId, 0.5 + segmentId), *worldGraph));
endPoints.push_back(MakeFakeEnding(featureId, segmentId, m2::PointD(0.5 + segmentId, featureId), *worldGraph));
endPoints.push_back(
MakeFakeEnding(featureId + kCitySize, segmentId, m2::PointD(featureId, 0.5 + segmentId), *worldGraph));
}
}
@@ -301,22 +282,20 @@ UNIT_TEST(FindPathManhattan)
{
uint32_t expectedLength = 0;
auto const startFeatureOffset =
start.m_projections[0].m_segment.GetFeatureId() < kCitySize
? start.m_projections[0].m_segment.GetFeatureId()
: start.m_projections[0].m_segment.GetFeatureId() - kCitySize;
auto const finishFeatureOffset =
finish.m_projections[0].m_segment.GetFeatureId() < kCitySize
? finish.m_projections[0].m_segment.GetFeatureId()
: finish.m_projections[0].m_segment.GetFeatureId() - kCitySize;
auto const startFeatureOffset = start.m_projections[0].m_segment.GetFeatureId() < kCitySize
? start.m_projections[0].m_segment.GetFeatureId()
: start.m_projections[0].m_segment.GetFeatureId() - kCitySize;
auto const finishFeatureOffset = finish.m_projections[0].m_segment.GetFeatureId() < kCitySize
? finish.m_projections[0].m_segment.GetFeatureId()
: finish.m_projections[0].m_segment.GetFeatureId() - kCitySize;
if ((start.m_projections[0].m_segment.GetFeatureId() < kCitySize) ==
(finish.m_projections[0].m_segment.GetFeatureId() < kCitySize))
{
uint32_t segDelta = AbsDelta(start.m_projections[0].m_segment.GetSegmentIdx(),
finish.m_projections[0].m_segment.GetSegmentIdx());
if (segDelta == 0 && start.m_projections[0].m_segment.GetFeatureId() !=
finish.m_projections[0].m_segment.GetFeatureId())
if (segDelta == 0 &&
start.m_projections[0].m_segment.GetFeatureId() != finish.m_projections[0].m_segment.GetFeatureId())
segDelta = 1;
expectedLength += segDelta;
expectedLength += AbsDelta(startFeatureOffset, finishFeatureOffset) + 1;
@@ -324,28 +303,17 @@ UNIT_TEST(FindPathManhattan)
else
{
if (start.m_projections[0].m_segment.GetSegmentIdx() < finishFeatureOffset)
{
expectedLength += finishFeatureOffset - start.m_projections[0].m_segment.GetSegmentIdx();
}
else
{
expectedLength +=
start.m_projections[0].m_segment.GetSegmentIdx() - finishFeatureOffset + 1;
}
expectedLength += start.m_projections[0].m_segment.GetSegmentIdx() - finishFeatureOffset + 1;
if (finish.m_projections[0].m_segment.GetSegmentIdx() < startFeatureOffset)
{
expectedLength += startFeatureOffset - finish.m_projections[0].m_segment.GetSegmentIdx();
}
else
{
expectedLength +=
finish.m_projections[0].m_segment.GetSegmentIdx() - startFeatureOffset + 1;
}
expectedLength += finish.m_projections[0].m_segment.GetSegmentIdx() - startFeatureOffset + 1;
}
TestRoute(start, finish, expectedLength, nullptr /* expectedRoute */, kUnknownWeight,
*worldGraph);
TestRoute(start, finish, expectedLength, nullptr /* expectedRoute */, kUnknownWeight, *worldGraph);
}
}
}
@@ -363,13 +331,11 @@ UNIT_TEST(RoadSpeed)
{
unique_ptr<TestGeometryLoader> loader = make_unique<TestGeometryLoader>();
loader->AddRoad(
0 /* featureId */, false, 10.0 /* speed */,
RoadGeometry::Points({{1.0, 0.0}, {2.0, -1.0}, {3.0, -1.0}, {4.0, -1.0}, {5.0, 0.0}}));
loader->AddRoad(0 /* featureId */, false, 10.0 /* speed */,
RoadGeometry::Points({{1.0, 0.0}, {2.0, -1.0}, {3.0, -1.0}, {4.0, -1.0}, {5.0, 0.0}}));
loader->AddRoad(
1 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{0.0, 0.0}, {1.0, 0.0}, {3.0, 0.0}, {5.0, 0.0}, {6.0, 0.0}}));
loader->AddRoad(1 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{0.0, 0.0}, {1.0, 0.0}, {3.0, 0.0}, {5.0, 0.0}, {6.0, 0.0}}));
traffic::TrafficCache const trafficCache;
shared_ptr<EdgeEstimator> estimator = CreateEstimatorForCar(trafficCache);
@@ -380,8 +346,7 @@ UNIT_TEST(RoadSpeed)
unique_ptr<WorldGraph> worldGraph = BuildWorldGraph(std::move(loader), estimator, joints);
auto const start =
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(0.5, 0), *worldGraph);
auto const start = MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(0.5, 0), *worldGraph);
auto const finish = MakeFakeEnding(1, 3, m2::PointD(5.5, 0), *worldGraph);
vector<Segment> const expectedRoute({{kTestNumMwmId, 1, 0, true},
@@ -390,12 +355,11 @@ UNIT_TEST(RoadSpeed)
{kTestNumMwmId, 0, 2, true},
{kTestNumMwmId, 0, 3, true},
{kTestNumMwmId, 1, 3, true}});
double const expectedWeight =
mercator::DistanceOnEarth({0.5, 0.0}, {1.0, 0.0}) / KmphToMps(1.0) +
mercator::DistanceOnEarth({1.0, 0.0}, {2.0, -1.0}) / KmphToMps(10.0) +
mercator::DistanceOnEarth({2.0, -1.0}, {4.0, -1.0}) / KmphToMps(10.0) +
mercator::DistanceOnEarth({4.0, -1.0}, {5.0, 0.0}) / KmphToMps(10.0) +
mercator::DistanceOnEarth({5.0, 0.0}, {5.5, 0.0}) / KmphToMps(1.0);
double const expectedWeight = mercator::DistanceOnEarth({0.5, 0.0}, {1.0, 0.0}) / KmphToMps(1.0) +
mercator::DistanceOnEarth({1.0, 0.0}, {2.0, -1.0}) / KmphToMps(10.0) +
mercator::DistanceOnEarth({2.0, -1.0}, {4.0, -1.0}) / KmphToMps(10.0) +
mercator::DistanceOnEarth({4.0, -1.0}, {5.0, 0.0}) / KmphToMps(10.0) +
mercator::DistanceOnEarth({5.0, 0.0}, {5.5, 0.0}) / KmphToMps(1.0);
TestRoute(start, finish, expectedRoute.size(), &expectedRoute, expectedWeight, *worldGraph);
}
@@ -411,14 +375,12 @@ UNIT_TEST(OneSegmentWay)
{
unique_ptr<TestGeometryLoader> loader = make_unique<TestGeometryLoader>();
loader->AddRoad(0 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{0.0, 0.0}, {3.0, 0.0}}));
loader->AddRoad(0 /* featureId */, false, 1.0 /* speed */, RoadGeometry::Points({{0.0, 0.0}, {3.0, 0.0}}));
traffic::TrafficCache const trafficCache;
shared_ptr<EdgeEstimator> estimator = CreateEstimatorForCar(trafficCache);
unique_ptr<WorldGraph> worldGraph = BuildWorldGraph(std::move(loader), estimator, vector<Joint>());
vector<Segment> const expectedRoute(
{{kTestNumMwmId, 0 /* featureId */, 0 /* seg id */, true /* forward */}});
vector<Segment> const expectedRoute({{kTestNumMwmId, 0 /* featureId */, 0 /* seg id */, true /* forward */}});
// Starter must match any combination of start and finish directions.
vector<bool> const tf = {{true, false}};
@@ -426,10 +388,10 @@ UNIT_TEST(OneSegmentWay)
{
for (auto const finishIsForward : tf)
{
auto const start = MakeFakeEnding({Segment(kTestNumMwmId, 0, 0, startIsForward)},
m2::PointD(1.0, 0.0), *worldGraph);
auto const finish = MakeFakeEnding({Segment(kTestNumMwmId, 0, 0, finishIsForward)},
m2::PointD(2.0, 0.0), *worldGraph);
auto const start =
MakeFakeEnding({Segment(kTestNumMwmId, 0, 0, startIsForward)}, m2::PointD(1.0, 0.0), *worldGraph);
auto const finish =
MakeFakeEnding({Segment(kTestNumMwmId, 0, 0, finishIsForward)}, m2::PointD(2.0, 0.0), *worldGraph);
auto const expectedWeight = mercator::DistanceOnEarth({1.0, 0.0}, {2.0, 0.0}) / KmphToMps(1.0);
TestRoute(start, finish, expectedRoute.size(), &expectedRoute, expectedWeight, *worldGraph);
@@ -457,8 +419,7 @@ UNIT_TEST(OneSegmentWayBackward)
shared_ptr<EdgeEstimator> estimator = CreateEstimatorForCar(trafficCache);
unique_ptr<WorldGraph> worldGraph = BuildWorldGraph(std::move(loader), estimator, vector<Joint>());
auto const start =
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *worldGraph);
auto const start = MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *worldGraph);
auto const finish = MakeFakeEnding(0, 0, m2::PointD(1, 0), *worldGraph);
auto starter = MakeStarter(start, finish, *worldGraph);
@@ -480,10 +441,8 @@ UNIT_TEST(FakeSegmentCoordinates)
{
unique_ptr<TestGeometryLoader> loader = make_unique<TestGeometryLoader>();
loader->AddRoad(0 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{0.0, 0.0}, {2.0, 0.0}}));
loader->AddRoad(1 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{2.0, 0.0}, {4.0, 0.0}}));
loader->AddRoad(0 /* featureId */, false, 1.0 /* speed */, RoadGeometry::Points({{0.0, 0.0}, {2.0, 0.0}}));
loader->AddRoad(1 /* featureId */, false, 1.0 /* speed */, RoadGeometry::Points({{2.0, 0.0}, {4.0, 0.0}}));
vector<Joint> joints;
joints.emplace_back(MakeJoint({{0 /* featureId */, 1 /* pointId */}, {1, 0}}));
@@ -499,10 +458,9 @@ UNIT_TEST(FakeSegmentCoordinates)
{
for (auto const finishIsForward : tf)
{
auto const start = MakeFakeEnding({Segment(kTestNumMwmId, 0, 0, startIsForward)},
m2::PointD(1, 0), *worldGraph);
auto const finish = MakeFakeEnding({Segment(kTestNumMwmId, 1, 0, finishIsForward)},
m2::PointD(3, 0), *worldGraph);
auto const start = MakeFakeEnding({Segment(kTestNumMwmId, 0, 0, startIsForward)}, m2::PointD(1, 0), *worldGraph);
auto const finish =
MakeFakeEnding({Segment(kTestNumMwmId, 1, 0, finishIsForward)}, m2::PointD(3, 0), *worldGraph);
auto starter = MakeStarter(start, finish, *worldGraph);
TestRouteGeometry(*starter, AlgorithmForIndexGraphStarter::Result::OK, expectedGeom);
@@ -523,10 +481,8 @@ UNIT_TEST(FakeEndingAStarInvariant)
{
unique_ptr<TestGeometryLoader> loader = make_unique<TestGeometryLoader>();
loader->AddRoad(0 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{0.0, 0.0}, {8.0, 0.0}}));
loader->AddRoad(1 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{8.0, 0.0}, {8.0, 1.0 / 1000.0}}));
loader->AddRoad(0 /* featureId */, false, 1.0 /* speed */, RoadGeometry::Points({{0.0, 0.0}, {8.0, 0.0}}));
loader->AddRoad(1 /* featureId */, false, 1.0 /* speed */, RoadGeometry::Points({{8.0, 0.0}, {8.0, 1.0 / 1000.0}}));
vector<Joint> joints;
joints.emplace_back(MakeJoint({{0 /* featureId */, 1 /* pointId */}, {1, 0}}));
@@ -534,17 +490,14 @@ UNIT_TEST(FakeEndingAStarInvariant)
traffic::TrafficCache const trafficCache;
shared_ptr<EdgeEstimator> estimator = CreateEstimatorForCar(trafficCache);
unique_ptr<WorldGraph> worldGraph = BuildWorldGraph(std::move(loader), estimator, joints);
vector<Segment> const expectedRoute(
{{kTestNumMwmId, 0 /* featureId */, 0 /* seg id */, true /* forward */}});
vector<Segment> const expectedRoute({{kTestNumMwmId, 0 /* featureId */, 0 /* seg id */, true /* forward */}});
auto const start =
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(1.0, 1.0), *worldGraph);
auto const start = MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(1.0, 1.0), *worldGraph);
auto const finish = MakeFakeEnding(0, 0, m2::PointD(2.0, 1.0), *worldGraph);
auto const expectedWeight =
estimator->CalcOffroad({1.0, 1.0}, {1.0, 0.0}, EdgeEstimator::Purpose::Weight) +
mercator::DistanceOnEarth({1.0, 0.0}, {2.0, 0.0}) / KmphToMps(1.0) +
estimator->CalcOffroad({2.0, 0.0}, {2.0, 1.0}, EdgeEstimator::Purpose::Weight);
auto const expectedWeight = estimator->CalcOffroad({1.0, 1.0}, {1.0, 0.0}, EdgeEstimator::Purpose::Weight) +
mercator::DistanceOnEarth({1.0, 0.0}, {2.0, 0.0}) / KmphToMps(1.0) +
estimator->CalcOffroad({2.0, 0.0}, {2.0, 1.0}, EdgeEstimator::Purpose::Weight);
TestRoute(start, finish, expectedRoute.size(), &expectedRoute, expectedWeight, *worldGraph);
}
@@ -559,7 +512,8 @@ UNIT_TEST(SerializeSimpleGraph)
{
IndexGraph graph;
vector<Joint> joints = {
MakeJoint({{0, 1}, {1, 0}}), MakeJoint({{1, 1}, {2, 0}}),
MakeJoint({{0, 1}, {1, 0}}),
MakeJoint({{1, 1}, {2, 0}}),
};
graph.Import(joints);
unordered_map<uint32_t, VehicleMask> masks;
@@ -657,9 +611,9 @@ unique_ptr<SingleVehicleWorldGraph> BuildLoopGraph()
vector<Joint> const joints = {
MakeJoint({{0 /* feature id */, 2 /* point id */}, {0, 9}}), /* joint at point (0.0002, 0) */
MakeJoint({{1, 1}, {0, 0}}), /* joint at point (0.0002, 0.0001) */
MakeJoint({{0, 6}, {2, 0}}), /* joint at point (0.00005, 0.0003) */
MakeJoint({{2, 1}}), /* joint at point (0.00005, 0.0004) */
MakeJoint({{1, 1}, {0, 0}}), /* joint at point (0.0002, 0.0001) */
MakeJoint({{0, 6}, {2, 0}}), /* joint at point (0.00005, 0.0003) */
MakeJoint({{2, 1}}), /* joint at point (0.00005, 0.0004) */
};
traffic::TrafficCache const trafficCache;
@@ -672,8 +626,7 @@ unique_ptr<SingleVehicleWorldGraph> BuildLoopGraph()
UNIT_CLASS_TEST(RestrictionTest, LoopGraph)
{
Init(BuildLoopGraph());
auto start =
MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(0.0002, 0), *m_graph);
auto start = MakeFakeEnding(1 /* featureId */, 0 /* segmentIdx */, m2::PointD(0.0002, 0), *m_graph);
auto finish = MakeFakeEnding(2, 0, m2::PointD(0.00005, 0.0004), *m_graph);
vector<Segment> const expectedRoute = {{kTestNumMwmId, 1, 0, true}, {kTestNumMwmId, 0, 0, true},
@@ -681,14 +634,13 @@ UNIT_CLASS_TEST(RestrictionTest, LoopGraph)
{kTestNumMwmId, 0, 7, false}, {kTestNumMwmId, 0, 6, false},
{kTestNumMwmId, 2, 0, true}};
auto const expectedWeight =
mercator::DistanceOnEarth({0.0002, 0.0}, {0.0002, 0.0001}) / KmphToMps(100.0) +
mercator::DistanceOnEarth({0.0002, 0.0001}, {0.00015, 0.0001}) / KmphToMps(100.0) +
mercator::DistanceOnEarth({0.00015, 0.0001}, {0.0001, 0.0001}) / KmphToMps(100.0) +
mercator::DistanceOnEarth({0.0001, 0.0001}, {0.00005, 0.00015}) / KmphToMps(100.0) +
mercator::DistanceOnEarth({0.00005, 0.00015}, {0.00005, 0.0002}) / KmphToMps(100.0) +
mercator::DistanceOnEarth({0.00005, 0.0002}, {0.00005, 0.0003}) / KmphToMps(100.0) +
mercator::DistanceOnEarth({0.00005, 0.0003}, {0.00005, 0.0004}) / KmphToMps(100.0);
auto const expectedWeight = mercator::DistanceOnEarth({0.0002, 0.0}, {0.0002, 0.0001}) / KmphToMps(100.0) +
mercator::DistanceOnEarth({0.0002, 0.0001}, {0.00015, 0.0001}) / KmphToMps(100.0) +
mercator::DistanceOnEarth({0.00015, 0.0001}, {0.0001, 0.0001}) / KmphToMps(100.0) +
mercator::DistanceOnEarth({0.0001, 0.0001}, {0.00005, 0.00015}) / KmphToMps(100.0) +
mercator::DistanceOnEarth({0.00005, 0.00015}, {0.00005, 0.0002}) / KmphToMps(100.0) +
mercator::DistanceOnEarth({0.00005, 0.0002}, {0.00005, 0.0003}) / KmphToMps(100.0) +
mercator::DistanceOnEarth({0.00005, 0.0003}, {0.00005, 0.0004}) / KmphToMps(100.0);
TestRoute(start, finish, expectedRoute.size(), &expectedRoute, expectedWeight, *m_graph);
}
@@ -829,10 +781,8 @@ UNIT_TEST(FinishNearZeroEdge)
{
unique_ptr<TestGeometryLoader> loader = make_unique<TestGeometryLoader>();
loader->AddRoad(0 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{2.0, 0.0}, {4.0, 0.0}}));
loader->AddRoad(1 /* featureId */, false, 1.0 /* speed */,
RoadGeometry::Points({{4.0, 0.0}, {4.0, 0.0}}));
loader->AddRoad(0 /* featureId */, false, 1.0 /* speed */, RoadGeometry::Points({{2.0, 0.0}, {4.0, 0.0}}));
loader->AddRoad(1 /* featureId */, false, 1.0 /* speed */, RoadGeometry::Points({{4.0, 0.0}, {4.0, 0.0}}));
vector<Joint> joints;
joints.emplace_back(MakeJoint({{0 /* featureId */, 1 /* pointId */}, {1, 0}}));
@@ -840,14 +790,13 @@ UNIT_TEST(FinishNearZeroEdge)
traffic::TrafficCache const trafficCache;
shared_ptr<EdgeEstimator> estimator = CreateEstimatorForCar(trafficCache);
unique_ptr<WorldGraph> worldGraph = BuildWorldGraph(std::move(loader), estimator, joints);
auto const start = MakeFakeEnding({Segment(kTestNumMwmId, 0, 0, true /* forward */)},
m2::PointD(1.0, 0.0), *worldGraph);
auto const finish = MakeFakeEnding({Segment(kTestNumMwmId, 1, 0, false /* forward */)},
m2::PointD(5.0, 0.0), *worldGraph);
auto const start =
MakeFakeEnding({Segment(kTestNumMwmId, 0, 0, true /* forward */)}, m2::PointD(1.0, 0.0), *worldGraph);
auto const finish =
MakeFakeEnding({Segment(kTestNumMwmId, 1, 0, false /* forward */)}, m2::PointD(5.0, 0.0), *worldGraph);
auto starter = MakeStarter(start, finish, *worldGraph);
vector<m2::PointD> const expectedGeom = {
{1.0 /* x */, 0.0 /* y */}, {2.0, 0.0}, {4.0, 0.0}, {5.0, 0.0}};
vector<m2::PointD> const expectedGeom = {{1.0 /* x */, 0.0 /* y */}, {2.0, 0.0}, {4.0, 0.0}, {5.0, 0.0}};
TestRouteGeometry(*starter, AlgorithmForIndexGraphStarter::Result::OK, expectedGeom);
}
} // namespace index_graph_test

View File

@@ -30,8 +30,7 @@ Graph & GetGraph(unordered_map<NumMwmId, unique_ptr<Graph>> const & graphs, NumM
}
template <typename Graph>
void AddGraph(unordered_map<NumMwmId, unique_ptr<Graph>> & graphs, NumMwmId mwmId,
unique_ptr<Graph> graph)
void AddGraph(unordered_map<NumMwmId, unique_ptr<Graph>> & graphs, NumMwmId mwmId, unique_ptr<Graph> graph)
{
auto it = graphs.find(mwmId);
CHECK(it == graphs.end(), ("Already contains graph for mwm", mwmId));
@@ -89,10 +88,7 @@ void NoUTurnRestrictionTest::TestRouteGeom(Segment const & start, Segment const
static auto constexpr kEps = 1e-3;
auto const point = m_graph->GetWorldGraph().GetPoint(routingResult.m_path[i], true /* forward */);
if (!AlmostEqualAbs(mercator::FromLatLon(point), expectedRouteGeom[i], kEps))
{
TEST(false, ("Coords missmated at index:", i, "expected:", expectedRouteGeom[i],
"received:", point));
}
TEST(false, ("Coords missmated at index:", i, "expected:", expectedRouteGeom[i], "received:", point));
}
}
@@ -115,7 +111,10 @@ Geometry & TestIndexGraphLoader::GetGeometry(NumMwmId mwmId)
return GetIndexGraph(mwmId).GetGeometry();
}
void TestIndexGraphLoader::Clear() { m_graphs.clear(); }
void TestIndexGraphLoader::Clear()
{
m_graphs.clear();
}
void TestIndexGraphLoader::AddGraph(NumMwmId mwmId, unique_ptr<IndexGraph> graph)
{
@@ -128,7 +127,10 @@ TransitGraph & TestTransitGraphLoader::GetTransitGraph(NumMwmId mwmId, IndexGrap
return GetGraph(m_graphs, mwmId);
}
void TestTransitGraphLoader::Clear() { m_graphs.clear(); }
void TestTransitGraphLoader::Clear()
{
m_graphs.clear();
}
void TestTransitGraphLoader::AddGraph(NumMwmId mwmId, unique_ptr<TransitGraph> graph)
{
@@ -136,8 +138,7 @@ void TestTransitGraphLoader::AddGraph(NumMwmId mwmId, unique_ptr<TransitGraph> g
}
// WeightedEdgeEstimator --------------------------------------------------------------
double WeightedEdgeEstimator::CalcSegmentWeight(Segment const & segment,
RoadGeometry const & /* road */,
double WeightedEdgeEstimator::CalcSegmentWeight(Segment const & segment, RoadGeometry const & /* road */,
EdgeEstimator::Purpose /* purpose */) const
{
auto const it = m_segmentWeights.find(segment);
@@ -145,8 +146,14 @@ double WeightedEdgeEstimator::CalcSegmentWeight(Segment const & segment,
return it->second;
}
double WeightedEdgeEstimator::GetUTurnPenalty(Purpose purpose) const { return 0.0; }
double WeightedEdgeEstimator::GetFerryLandingPenalty(Purpose purpose) const { return 0.0; }
double WeightedEdgeEstimator::GetUTurnPenalty(Purpose purpose) const
{
return 0.0;
}
double WeightedEdgeEstimator::GetFerryLandingPenalty(Purpose purpose) const
{
return 0.0;
}
// TestIndexGraphTopology --------------------------------------------------------------------------
TestIndexGraphTopology::TestIndexGraphTopology(uint32_t numVertices) : m_numVertices(numVertices) {}
@@ -207,8 +214,7 @@ void TestIndexGraphTopology::SetVertexAccess(Vertex v, RoadAccess::Type type)
CHECK(found, ("Cannot set access for vertex that is not in the graph", v));
}
void TestIndexGraphTopology::SetVertexAccessConditional(Vertex v, RoadAccess::Type type,
string const & condition)
void TestIndexGraphTopology::SetVertexAccessConditional(Vertex v, RoadAccess::Type type, string const & condition)
{
osmoh::OpeningHours openingHours(condition);
CHECK(openingHours.IsValid(), (condition));
@@ -233,8 +239,7 @@ void TestIndexGraphTopology::SetVertexAccessConditional(Vertex v, RoadAccess::Ty
CHECK(found, ("Cannot set access for vertex that is not in the graph", v));
}
bool TestIndexGraphTopology::FindPath(Vertex start, Vertex finish, double & pathWeight,
vector<Edge> & pathEdges) const
bool TestIndexGraphTopology::FindPath(Vertex start, Vertex finish, double & pathWeight, vector<Edge> & pathEdges) const
{
CHECK_LESS(start, m_numVertices, ());
CHECK_LESS(finish, m_numVertices, ());
@@ -253,15 +258,13 @@ bool TestIndexGraphTopology::FindPath(Vertex start, Vertex finish, double & path
AddDirectedEdge(edgeRequests, start, start, 0.0);
// |startSegment| corresponds to edge from |start| to |start| which has featureId |startFeatureId|
// and the only segment with segmentIdx |0|. It is a loop so direction does not matter.
auto const startSegment = Segment(kTestNumMwmId, startFeatureId, 0 /* segmentIdx */,
true /* forward */);
auto const startSegment = Segment(kTestNumMwmId, startFeatureId, 0 /* segmentIdx */, true /* forward */);
auto const finishFeatureId = static_cast<uint32_t>(edgeRequests.size());
AddDirectedEdge(edgeRequests, finish, finish, 0.0);
// |finishSegment| corresponds to edge from |finish| to |finish| which has featureId |finishFeatureId|
// and the only segment with segmentIdx |0|. It is a loop so direction does not matter.
auto const finishSegment = Segment(kTestNumMwmId, finishFeatureId, 0 /* segmentIdx */,
true /* forward */);
auto const finishSegment = Segment(kTestNumMwmId, finishFeatureId, 0 /* segmentIdx */, true /* forward */);
Builder builder(m_numVertices);
builder.SetCurrentTimeGetter(m_currentTimeGetter);
@@ -282,8 +285,7 @@ bool TestIndexGraphTopology::FindPath(Vertex start, Vertex finish, double & path
RoutingResult<Segment, RouteWeight> unidirectionalRoutingResult;
auto const unidirectionalResultCode = algorithm.FindPath(params, unidirectionalRoutingResult);
CHECK_EQUAL(resultCode, unidirectionalResultCode, ());
CHECK(routingResult.m_distance.IsAlmostEqualForTests(unidirectionalRoutingResult.m_distance,
kEpsilon),
CHECK(routingResult.m_distance.IsAlmostEqualForTests(unidirectionalRoutingResult.m_distance, kEpsilon),
("Distances differ:", routingResult.m_distance, unidirectionalRoutingResult.m_distance));
}
@@ -316,8 +318,8 @@ bool TestIndexGraphTopology::FindPath(Vertex start, Vertex finish, double & path
return true;
}
void TestIndexGraphTopology::AddDirectedEdge(vector<EdgeRequest> & edgeRequests, Vertex from,
Vertex to, double weight) const
void TestIndexGraphTopology::AddDirectedEdge(vector<EdgeRequest> & edgeRequests, Vertex from, Vertex to,
double weight) const
{
uint32_t const id = static_cast<uint32_t>(edgeRequests.size());
edgeRequests.emplace_back(id, from, to, weight);
@@ -374,19 +376,13 @@ void TestIndexGraphTopology::Builder::BuildGraphFromRequests(vector<EdgeRequest>
pointToAccess[RoadPoint(request.m_id, 0 /* pointId */)] = request.m_fromAccessType;
if (!request.m_fromAccessConditionalType.IsEmpty())
{
pointToAccessConditional[RoadPoint(request.m_id, 0 /* pointId */)] =
request.m_fromAccessConditionalType;
}
pointToAccessConditional[RoadPoint(request.m_id, 0 /* pointId */)] = request.m_fromAccessConditionalType;
if (request.m_toAccessType != RoadAccess::Type::Yes)
pointToAccess[RoadPoint(request.m_id, 1 /* pointId */)] = request.m_toAccessType;
if (!request.m_toAccessConditionalType.IsEmpty())
{
pointToAccessConditional[RoadPoint(request.m_id, 1 /* pointId */)] =
request.m_toAccessConditionalType;
}
pointToAccessConditional[RoadPoint(request.m_id, 1 /* pointId */)] = request.m_toAccessConditionalType;
}
m_roadAccess.SetAccess(std::move(wayToAccess), std::move(pointToAccess));
@@ -412,20 +408,18 @@ void TestIndexGraphTopology::Builder::BuildSegmentFromEdge(EdgeRequest const & r
// Functions ---------------------------------------------------------------------------------------
unique_ptr<SingleVehicleWorldGraph> BuildWorldGraph(unique_ptr<TestGeometryLoader> geometryLoader,
shared_ptr<EdgeEstimator> estimator,
vector<Joint> const & joints)
shared_ptr<EdgeEstimator> estimator, vector<Joint> const & joints)
{
auto graph = make_unique<IndexGraph>(make_shared<Geometry>(std::move(geometryLoader)), estimator);
graph->Import(joints);
auto indexLoader = make_unique<TestIndexGraphLoader>();
indexLoader->AddGraph(kTestNumMwmId, std::move(graph));
return make_unique<SingleVehicleWorldGraph>(nullptr /* crossMwmGraph */, std::move(indexLoader),
estimator, MwmHierarchyHandler());
return make_unique<SingleVehicleWorldGraph>(nullptr /* crossMwmGraph */, std::move(indexLoader), estimator,
MwmHierarchyHandler());
}
unique_ptr<IndexGraph> BuildIndexGraph(unique_ptr<TestGeometryLoader> geometryLoader,
shared_ptr<EdgeEstimator> estimator,
vector<Joint> const & joints)
shared_ptr<EdgeEstimator> estimator, vector<Joint> const & joints)
{
auto graph = make_unique<IndexGraph>(make_shared<Geometry>(std::move(geometryLoader)), estimator);
graph->Import(joints);
@@ -433,28 +427,25 @@ unique_ptr<IndexGraph> BuildIndexGraph(unique_ptr<TestGeometryLoader> geometryLo
}
unique_ptr<SingleVehicleWorldGraph> BuildWorldGraph(unique_ptr<ZeroGeometryLoader> geometryLoader,
shared_ptr<EdgeEstimator> estimator,
vector<Joint> const & joints)
shared_ptr<EdgeEstimator> estimator, vector<Joint> const & joints)
{
auto graph = make_unique<IndexGraph>(make_shared<Geometry>(std::move(geometryLoader)), estimator);
graph->Import(joints);
auto indexLoader = make_unique<TestIndexGraphLoader>();
indexLoader->AddGraph(kTestNumMwmId, std::move(graph));
return make_unique<SingleVehicleWorldGraph>(nullptr /* crossMwmGraph */, std::move(indexLoader),
estimator, MwmHierarchyHandler());
return make_unique<SingleVehicleWorldGraph>(nullptr /* crossMwmGraph */, std::move(indexLoader), estimator,
MwmHierarchyHandler());
}
unique_ptr<TransitWorldGraph> BuildWorldGraph(unique_ptr<TestGeometryLoader> geometryLoader,
shared_ptr<EdgeEstimator> estimator,
vector<Joint> const & joints,
shared_ptr<EdgeEstimator> estimator, vector<Joint> const & joints,
routing::transit::GraphData const & transitData)
{
auto indexGraph = make_unique<IndexGraph>(make_shared<Geometry>(std::move(geometryLoader)), estimator);
indexGraph->Import(joints);
auto transitGraph =
make_unique<TransitGraph>(::transit::TransitVersion::OnlySubway, kTestNumMwmId, estimator);
auto transitGraph = make_unique<TransitGraph>(::transit::TransitVersion::OnlySubway, kTestNumMwmId, estimator);
TransitGraph::Endings gateEndings;
MakeGateEndings(transitData.GetGates(), kTestNumMwmId, *indexGraph, gateEndings);
transitGraph->Fill(transitData, gateEndings);
@@ -465,8 +456,8 @@ unique_ptr<TransitWorldGraph> BuildWorldGraph(unique_ptr<TestGeometryLoader> geo
auto transitLoader = make_unique<TestTransitGraphLoader>();
transitLoader->AddGraph(kTestNumMwmId, std::move(transitGraph));
return make_unique<TransitWorldGraph>(nullptr /* crossMwmGraph */, std::move(indexLoader),
std::move(transitLoader), estimator);
return make_unique<TransitWorldGraph>(nullptr /* crossMwmGraph */, std::move(indexLoader), std::move(transitLoader),
estimator);
}
AlgorithmForWorldGraph::Result CalculateRoute(IndexGraphStarter & starter, vector<Segment> & roadPoints,
@@ -485,8 +476,7 @@ AlgorithmForWorldGraph::Result CalculateRoute(IndexGraphStarter & starter, vecto
return resultCode;
}
void TestRouteGeometry(IndexGraphStarter & starter,
AlgorithmForWorldGraph::Result expectedRouteResult,
void TestRouteGeometry(IndexGraphStarter & starter, AlgorithmForWorldGraph::Result expectedRouteResult,
vector<m2::PointD> const & expectedRouteGeom)
{
vector<Segment> routeSegs;
@@ -495,8 +485,7 @@ void TestRouteGeometry(IndexGraphStarter & starter,
TEST_EQUAL(resultCode, expectedRouteResult, ());
if (AlgorithmForWorldGraph::Result::NoPath == expectedRouteResult &&
expectedRouteGeom.empty())
if (AlgorithmForWorldGraph::Result::NoPath == expectedRouteResult && expectedRouteGeom.empty())
{
// The route goes through a restriction. So there's no choice for building route
// except for going through restriction. So no path.
@@ -509,7 +498,8 @@ void TestRouteGeometry(IndexGraphStarter & starter,
CHECK(!routeSegs.empty(), ());
vector<m2::PointD> geom;
auto const pushPoint = [&geom](ms::LatLon const & ll) {
auto const pushPoint = [&geom](ms::LatLon const & ll)
{
auto const point = mercator::FromLatLon(ll);
if (geom.empty() || geom.back() != point)
geom.push_back(point);
@@ -538,10 +528,8 @@ void TestRouteGeometry(IndexGraphStarter & starter,
}
}
void TestRestrictions(vector<m2::PointD> const & expectedRouteGeom,
AlgorithmForWorldGraph::Result expectedRouteResult,
FakeEnding const & start, FakeEnding const & finish,
RestrictionVec && restrictions,
void TestRestrictions(vector<m2::PointD> const & expectedRouteGeom, AlgorithmForWorldGraph::Result expectedRouteResult,
FakeEnding const & start, FakeEnding const & finish, RestrictionVec && restrictions,
RestrictionTest & restrictionTest)
{
restrictionTest.SetRestrictions(std::move(restrictions));
@@ -550,12 +538,9 @@ void TestRestrictions(vector<m2::PointD> const & expectedRouteGeom,
TestRouteGeometry(*restrictionTest.m_starter, expectedRouteResult, expectedRouteGeom);
}
void TestRestrictions(vector<m2::PointD> const & expectedRouteGeom,
AlgorithmForWorldGraph::Result expectedRouteResult,
FakeEnding const & start, FakeEnding const & finish,
RestrictionVec && restrictions,
vector<RestrictionUTurn> && restrictionsNoUTurn,
RestrictionTest & restrictionTest)
void TestRestrictions(vector<m2::PointD> const & expectedRouteGeom, AlgorithmForWorldGraph::Result expectedRouteResult,
FakeEnding const & start, FakeEnding const & finish, RestrictionVec && restrictions,
vector<RestrictionUTurn> && restrictionsNoUTurn, RestrictionTest & restrictionTest)
{
restrictionTest.SetRestrictions(std::move(restrictions));
restrictionTest.SetUTurnRestrictions(std::move(restrictionsNoUTurn));
@@ -564,8 +549,7 @@ void TestRestrictions(vector<m2::PointD> const & expectedRouteGeom,
TestRouteGeometry(*restrictionTest.m_starter, expectedRouteResult, expectedRouteGeom);
}
void TestRestrictions(double expectedLength,
FakeEnding const & start, FakeEnding const & finish,
void TestRestrictions(double expectedLength, FakeEnding const & start, FakeEnding const & finish,
RestrictionVec && restrictions, RestrictionTest & restrictionTest)
{
restrictionTest.SetRestrictions(std::move(restrictions));
@@ -588,13 +572,11 @@ void TestRestrictions(double expectedLength,
}
static auto constexpr kEps = 1e-3;
TEST(AlmostEqualAbs(expectedLength, length, kEps),
("Length expected:", expectedLength, "has:", length));
TEST(AlmostEqualAbs(expectedLength, length, kEps), ("Length expected:", expectedLength, "has:", length));
}
void TestTopologyGraph(TestIndexGraphTopology const & graph, TestIndexGraphTopology::Vertex from,
TestIndexGraphTopology::Vertex to, bool expectedPathFound,
double const expectedWeight,
TestIndexGraphTopology::Vertex to, bool expectedPathFound, double const expectedWeight,
vector<TestIndexGraphTopology::Edge> const & expectedEdges)
{
double pathWeight = 0.0;
@@ -604,26 +586,20 @@ void TestTopologyGraph(TestIndexGraphTopology const & graph, TestIndexGraphTopol
if (!pathFound)
return;
TEST(AlmostEqualAbs(pathWeight, expectedWeight, kEpsilon),
(pathWeight, expectedWeight, pathEdges));
TEST(AlmostEqualAbs(pathWeight, expectedWeight, kEpsilon), (pathWeight, expectedWeight, pathEdges));
TEST_EQUAL(pathEdges, expectedEdges, ());
}
FakeEnding MakeFakeEnding(uint32_t featureId, uint32_t segmentIdx, m2::PointD const & point,
WorldGraph & graph)
FakeEnding MakeFakeEnding(uint32_t featureId, uint32_t segmentIdx, m2::PointD const & point, WorldGraph & graph)
{
return MakeFakeEnding({Segment(kTestNumMwmId, featureId, segmentIdx, true /* forward */)}, point,
graph);
return MakeFakeEnding({Segment(kTestNumMwmId, featureId, segmentIdx, true /* forward */)}, point, graph);
}
unique_ptr<IndexGraphStarter> MakeStarter(FakeEnding const & start, FakeEnding const & finish,
WorldGraph & graph)
unique_ptr<IndexGraphStarter> MakeStarter(FakeEnding const & start, FakeEnding const & finish, WorldGraph & graph)
{
return make_unique<IndexGraphStarter>(start, finish, 0 /* fakeNumerationStart */,
false /* strictForward */, graph);
return make_unique<IndexGraphStarter>(start, finish, 0 /* fakeNumerationStart */, false /* strictForward */, graph);
}
time_t GetUnixtimeByDate(uint16_t year, Month month, uint8_t monthDay, uint8_t hours,
uint8_t minutes)
time_t GetUnixtimeByDate(uint16_t year, Month month, uint8_t monthDay, uint8_t hours, uint8_t minutes)
{
std::tm t{};
t.tm_year = year - 1900;
@@ -636,11 +612,11 @@ time_t GetUnixtimeByDate(uint16_t year, Month month, uint8_t monthDay, uint8_t h
return moment;
}
time_t GetUnixtimeByDate(uint16_t year, Month month, Weekday weekday, uint8_t hours,
uint8_t minutes)
time_t GetUnixtimeByDate(uint16_t year, Month month, Weekday weekday, uint8_t hours, uint8_t minutes)
{
int monthDay = 1;
auto createUnixtime = [&]() {
auto createUnixtime = [&]()
{
std::tm t{};
t.tm_year = year - 1900;
t.tm_mon = static_cast<int>(month) - 1;

View File

@@ -61,16 +61,14 @@ public:
m_graph->GetPoint(to, true /* front */));
}
void GetOutgoingEdgesList(astar::VertexData<Vertex, RouteWeight> const & vertexData,
EdgeListT & edges) override
void GetOutgoingEdgesList(astar::VertexData<Vertex, RouteWeight> const & vertexData, EdgeListT & edges) override
{
edges.clear();
m_graph->GetEdgeList(vertexData, true /* isOutgoing */, true /* useRoutingOptions */,
true /* useAccessConditional */, edges);
}
void GetIngoingEdgesList(astar::VertexData<Vertex, RouteWeight> const & vertexData,
EdgeListT & edges) override
void GetIngoingEdgesList(astar::VertexData<Vertex, RouteWeight> const & vertexData, EdgeListT & edges) override
{
edges.clear();
m_graph->GetEdgeList(vertexData, false /* isOutgoing */, true /* useRoutingOptions */,
@@ -106,8 +104,7 @@ struct NoUTurnRestrictionTest
void SetRestrictions(RestrictionVec && restrictions);
void SetNoUTurnRestrictions(std::vector<RestrictionUTurn> && restrictions);
void TestRouteGeom(Segment const & start, Segment const & finish,
AlgorithmForWorldGraph::Result expectedRouteResult,
void TestRouteGeom(Segment const & start, Segment const & finish, AlgorithmForWorldGraph::Result expectedRouteResult,
std::vector<m2::PointD> const & expectedRouteGeom);
std::unique_ptr<WorldGraphForAStar> m_graph;
@@ -131,10 +128,7 @@ public:
IndexGraph & GetIndexGraph(NumMwmId mwmId) override;
Geometry & GetGeometry(NumMwmId mwmId) override;
std::vector<RouteSegment::SpeedCamera> GetSpeedCameraInfo(Segment const & segment) override
{
return {};
}
std::vector<RouteSegment::SpeedCamera> GetSpeedCameraInfo(Segment const & segment) override { return {}; }
void Clear() override;
@@ -171,8 +165,7 @@ public:
explicit WeightedEdgeEstimator(std::map<Segment, double> const & segmentWeights)
: EdgeEstimator(1e10 /* maxSpeedKMpH */, 1.0 /* offroadSpeedKMpH */)
, m_segmentWeights(segmentWeights)
{
}
{}
// EdgeEstimator overrides:
~WeightedEdgeEstimator() override = default;
@@ -207,8 +200,7 @@ public:
// Sets access for previously added edge.
void SetEdgeAccess(Vertex from, Vertex to, RoadAccess::Type type);
/// \param |condition| in osm opening hours format.
void SetEdgeAccessConditional(Vertex from, Vertex to, RoadAccess::Type type,
std::string const & condition);
void SetEdgeAccessConditional(Vertex from, Vertex to, RoadAccess::Type type, std::string const & condition);
// Sets access type for previously added point.
void SetVertexAccess(Vertex v, RoadAccess::Type type);
@@ -216,11 +208,13 @@ public:
void SetVertexAccessConditional(Vertex v, RoadAccess::Type type, std::string const & condition);
// Finds a path between the start and finish vertices. Returns true iff a path exists.
bool FindPath(Vertex start, Vertex finish, double & pathWeight,
std::vector<Edge> & pathEdges) const;
bool FindPath(Vertex start, Vertex finish, double & pathWeight, std::vector<Edge> & pathEdges) const;
template <typename T>
void SetCurrentTimeGetter(T && getter) { m_currentTimeGetter = std::forward<T>(getter); }
void SetCurrentTimeGetter(T && getter)
{
m_currentTimeGetter = std::forward<T>(getter);
}
private:
struct EdgeRequest
@@ -239,10 +233,8 @@ private:
RoadAccess::Type m_toAccessType = RoadAccess::Type::Yes;
RoadAccess::Conditional m_toAccessConditionalType;
EdgeRequest(uint32_t id, Vertex from, Vertex to, double weight)
: m_id(id), m_from(from), m_to(to), m_weight(weight)
{
}
EdgeRequest(uint32_t id, Vertex from, Vertex to, double weight) : m_id(id), m_from(from), m_to(to), m_weight(weight)
{}
};
// Builder builds a graph from edge requests.
@@ -266,8 +258,7 @@ private:
std::function<time_t()> m_currentTimeGetter;
};
void AddDirectedEdge(std::vector<EdgeRequest> & edgeRequests, Vertex from, Vertex to,
double weight) const;
void AddDirectedEdge(std::vector<EdgeRequest> & edgeRequests, Vertex from, Vertex to, double weight) const;
std::function<time_t()> m_currentTimeGetter;
uint32_t const m_numVertices;
@@ -281,31 +272,28 @@ std::unique_ptr<SingleVehicleWorldGraph> BuildWorldGraph(std::unique_ptr<ZeroGeo
std::shared_ptr<EdgeEstimator> estimator,
std::vector<Joint> const & joints);
AStarAlgorithm<Segment, SegmentEdge, RouteWeight>::Result CalculateRoute(
IndexGraphStarter & starter, std::vector<Segment> & roadPoints, double & timeSec);
AStarAlgorithm<Segment, SegmentEdge, RouteWeight>::Result CalculateRoute(IndexGraphStarter & starter,
std::vector<Segment> & roadPoints,
double & timeSec);
void TestRouteGeometry(
IndexGraphStarter & starter,
AStarAlgorithm<Segment, SegmentEdge, RouteWeight>::Result expectedRouteResult,
std::vector<m2::PointD> const & expectedRouteGeom);
void TestRouteGeometry(IndexGraphStarter & starter,
AStarAlgorithm<Segment, SegmentEdge, RouteWeight>::Result expectedRouteResult,
std::vector<m2::PointD> const & expectedRouteGeom);
/// \brief Applies |restrictions| to graph in |restrictionTest| and
/// tests the resulting route.
/// \note restrictionTest should have a valid |restrictionTest.m_graph|.
void TestRestrictions(std::vector<m2::PointD> const & expectedRouteGeom,
AStarAlgorithm<Segment, SegmentEdge, RouteWeight>::Result expectedRouteResult,
FakeEnding const & start, FakeEnding const & finish,
RestrictionVec && restrictions, RestrictionTest & restrictionTest);
FakeEnding const & start, FakeEnding const & finish, RestrictionVec && restrictions,
RestrictionTest & restrictionTest);
void TestRestrictions(std::vector<m2::PointD> const & expectedRouteGeom,
AStarAlgorithm<Segment, SegmentEdge, RouteWeight>::Result expectedRouteResult,
FakeEnding const & start, FakeEnding const & finish,
RestrictionVec && restrictions,
std::vector<RestrictionUTurn> && restrictionsNoUTurn,
RestrictionTest & restrictionTest);
FakeEnding const & start, FakeEnding const & finish, RestrictionVec && restrictions,
std::vector<RestrictionUTurn> && restrictionsNoUTurn, RestrictionTest & restrictionTest);
void TestRestrictions(double timeExpected,
FakeEnding const & start, FakeEnding const & finish,
void TestRestrictions(double timeExpected, FakeEnding const & start, FakeEnding const & finish,
RestrictionVec && restrictions, RestrictionTest & restrictionTest);
// Tries to find a unique path from |from| to |to| in |graph|.
@@ -314,23 +302,18 @@ void TestRestrictions(double timeExpected,
// If |expectedPathFound| is false, |expectedWeight| and |expectedEdges| may
// take arbitrary values.
void TestTopologyGraph(TestIndexGraphTopology const & graph, TestIndexGraphTopology::Vertex from,
TestIndexGraphTopology::Vertex to, bool expectedPathFound,
double expectedWeight,
TestIndexGraphTopology::Vertex to, bool expectedPathFound, double expectedWeight,
std::vector<TestIndexGraphTopology::Edge> const & expectedEdges);
// Creates FakeEnding projected to |Segment(kTestNumMwmId, featureId, segmentIdx, true /* forward
// */)|.
FakeEnding MakeFakeEnding(uint32_t featureId, uint32_t segmentIdx, m2::PointD const & point,
WorldGraph & graph);
FakeEnding MakeFakeEnding(uint32_t featureId, uint32_t segmentIdx, m2::PointD const & point, WorldGraph & graph);
std::unique_ptr<IndexGraphStarter> MakeStarter(FakeEnding const & start, FakeEnding const & finish,
WorldGraph & graph);
std::unique_ptr<IndexGraphStarter> MakeStarter(FakeEnding const & start, FakeEnding const & finish, WorldGraph & graph);
using Month = osmoh::MonthDay::Month;
using Weekday = osmoh::Weekday;
time_t GetUnixtimeByDate(uint16_t year, Month month, uint8_t monthDay, uint8_t hours,
uint8_t minutes);
time_t GetUnixtimeByDate(uint16_t year, Month month, Weekday weekday, uint8_t hours,
uint8_t minutes);
time_t GetUnixtimeByDate(uint16_t year, Month month, uint8_t monthDay, uint8_t hours, uint8_t minutes);
time_t GetUnixtimeByDate(uint16_t year, Month month, Weekday weekday, uint8_t hours, uint8_t minutes);
} // namespace routing_test

View File

@@ -1,7 +1,7 @@
#include "testing/testing.hpp"
#include "routing/maxspeeds_serialization.hpp"
#include "routing/maxspeeds.hpp"
#include "routing/maxspeeds_serialization.hpp"
#include "routing_common/maxspeed_conversion.hpp"
@@ -32,9 +32,8 @@ void TestMaxspeedsSerialization(vector<FeatureMaxspeed> const & speeds)
MaxspeedConverter const & converter = GetMaxspeedConverter();
for (auto const & s : speeds)
{
inputSpeeds.push_back({ s.GetFeatureId(),
converter.SpeedToMacro(s.GetForwardSpeedInUnits()),
converter.SpeedToMacro(s.GetBackwardSpeedInUnits()) });
inputSpeeds.push_back({s.GetFeatureId(), converter.SpeedToMacro(s.GetForwardSpeedInUnits()),
converter.SpeedToMacro(s.GetBackwardSpeedInUnits())});
}
int constexpr SPEEDS_COUNT = MaxspeedsSerializer::DEFAULT_SPEEDS_COUNT;
@@ -136,38 +135,32 @@ UNIT_TEST(MaxspeedsSerializer_Smoke)
UNIT_TEST(MaxspeedsSerializer_OneForwardMetric)
{
TestMaxspeedsSerialization(
{FeatureMaxspeed(0 /* feature id */, Units::Metric, 20 /* speed */)});
TestMaxspeedsSerialization({FeatureMaxspeed(0 /* feature id */, Units::Metric, 20 /* speed */)});
}
UNIT_TEST(MaxspeedsSerializer_OneNone)
{
TestMaxspeedsSerialization(
{FeatureMaxspeed(0 /* feature id */, Units::Metric, kNoneMaxSpeed)});
TestMaxspeedsSerialization({FeatureMaxspeed(0 /* feature id */, Units::Metric, kNoneMaxSpeed)});
}
UNIT_TEST(MaxspeedsSerializer_OneWalk)
{
TestMaxspeedsSerialization(
{FeatureMaxspeed(0 /* feature id */, Units::Metric, kWalkMaxSpeed)});
TestMaxspeedsSerialization({FeatureMaxspeed(0 /* feature id */, Units::Metric, kWalkMaxSpeed)});
}
UNIT_TEST(MaxspeedsSerializer_OneBidirectionalMetric_1)
{
TestMaxspeedsSerialization(
{FeatureMaxspeed(0 /* feature id */, Units::Metric, 20 /* speed */, 40 /* speed */)});
TestMaxspeedsSerialization({FeatureMaxspeed(0 /* feature id */, Units::Metric, 20 /* speed */, 40 /* speed */)});
}
UNIT_TEST(MaxspeedsSerializer_OneBidirectionalMetric_2)
{
TestMaxspeedsSerialization(
{FeatureMaxspeed(0 /* feature id */, Units::Metric, 10 /* speed */, kWalkMaxSpeed)});
TestMaxspeedsSerialization({FeatureMaxspeed(0 /* feature id */, Units::Metric, 10 /* speed */, kWalkMaxSpeed)});
}
UNIT_TEST(MaxspeedsSerializer_OneBidirectionalImperial)
{
TestMaxspeedsSerialization(
{FeatureMaxspeed(0 /* feature id */, Units::Imperial, 30 /* speed */, 50 /* speed */)});
TestMaxspeedsSerialization({FeatureMaxspeed(0 /* feature id */, Units::Imperial, 30 /* speed */, 50 /* speed */)});
}
UNIT_TEST(MaxspeedsSerializer_BigMetric)

View File

@@ -35,29 +35,36 @@ UNIT_TEST(MwmHierarchyHandler_Smoke)
routing::MwmHierarchyHandler handler(mwmIDs, getter);
TEST(!handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Belarus_Maglieu Region"),
GetCountryID(mwmIDs, "Belarus_Vitebsk Region")), ());
GetCountryID(mwmIDs, "Belarus_Vitebsk Region")),
());
TEST(handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Belarus_Hrodna Region"),
GetCountryID(mwmIDs, "Lithuania_East")), ());
GetCountryID(mwmIDs, "Lithuania_East")),
());
TEST(!handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Belarus_Maglieu Region"),
GetCountryID(mwmIDs, "Russia_Smolensk Oblast")), ());
TEST(handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Ukraine_Kherson Oblast"),
GetCountryID(mwmIDs, "Crimea")), ());
TEST(handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Russia_Krasnodar Krai"),
GetCountryID(mwmIDs, "Crimea")), ());
GetCountryID(mwmIDs, "Russia_Smolensk Oblast")),
());
TEST(handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Ukraine_Kherson Oblast"), GetCountryID(mwmIDs, "Crimea")),
());
TEST(handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Russia_Krasnodar Krai"), GetCountryID(mwmIDs, "Crimea")),
());
TEST(!handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Denmark_Region Zealand"),
GetCountryID(mwmIDs, "Denmark_Region of Southern Denmark")), ());
GetCountryID(mwmIDs, "Denmark_Region of Southern Denmark")),
());
TEST(handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Ukraine_Zakarpattia Oblast"),
GetCountryID(mwmIDs, "Slovakia_Region of Kosice")), ());
GetCountryID(mwmIDs, "Slovakia_Region of Kosice")),
());
TEST(handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Ukraine_Zakarpattia Oblast"),
GetCountryID(mwmIDs, "Hungary_Northern Great Plain")), ());
GetCountryID(mwmIDs, "Hungary_Northern Great Plain")),
());
TEST(!handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Hungary_Northern Great Plain"),
GetCountryID(mwmIDs, "Slovakia_Region of Kosice")), ());
GetCountryID(mwmIDs, "Slovakia_Region of Kosice")),
());
TEST(!handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Ireland_Connacht"),
GetCountryID(mwmIDs, "UK_Northern Ireland")), ());
TEST(handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Ireland_Leinster"),
GetCountryID(mwmIDs, "UK_Wales")), ());
GetCountryID(mwmIDs, "UK_Northern Ireland")),
());
TEST(handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, "Ireland_Leinster"), GetCountryID(mwmIDs, "UK_Wales")), ());
char const * ip[] = {"Israel", "Jerusalem", "Palestine"};
for (auto s1 : ip)
@@ -65,4 +72,4 @@ UNIT_TEST(MwmHierarchyHandler_Smoke)
TEST(!handler.HasCrossBorderPenalty(GetCountryID(mwmIDs, s1), GetCountryID(mwmIDs, s2)), (s1, s2));
}
} // namespace mwm_hierarchy_test
} // namespace mwm_hierarchy_test

View File

@@ -2,8 +2,8 @@
#include "routing/routing_tests/road_graph_builder.hpp"
#include "routing/road_graph.hpp"
#include "routing/nearest_edge_finder.hpp"
#include "routing/road_graph.hpp"
#include "routing_common/maxspeed_conversion.hpp"
@@ -27,8 +27,7 @@ void TestNearestOnMock1(m2::PointD const & point, size_t const candidatesCount,
for (size_t i = 0; i < graph->GetRoadCount(); ++i)
{
FeatureID const featureId = MakeTestFeatureID(base::checked_cast<uint32_t>(i));
auto const & roadInfo =
graph->GetRoadInfo(featureId, {true /* forward */, false /* in city */, Maxspeed()});
auto const & roadInfo = graph->GetRoadInfo(featureId, {true /* forward */, false /* in city */, Maxspeed()});
finder.AddInformationSource(IRoadGraph::FullRoadInfo(featureId, roadInfo));
}
@@ -72,4 +71,4 @@ UNIT_TEST(MiddleSegmentTest_Mock1Graph)
geometry::MakePointWithAltitudeForTesting(m2::PointD(12.5, 0)))};
TestNearestOnMock1(m2::PointD(12.5, 2.5), 2, expected);
}
} // namespace nearest_edge_finder_tests
} // namespace nearest_edge_finder_tests

View File

@@ -26,8 +26,7 @@ struct OHSerDesTestFixture
OHSerDesTestFixture()
: m_memWriter(m_buffer)
, m_bitWriter(std::make_unique<BitWriter<MemWriter<Buffer>>>(m_memWriter))
{
}
{}
BitWriter<MemWriter<Buffer>> & GetWriter() { return *m_bitWriter; }
BitReader<ReaderSource<MemReader>> & GetReader()
@@ -110,8 +109,7 @@ void TestModifier(osmoh::RuleSequence const & rule, osmoh::RuleSequence::Modifie
TEST_EQUAL(rule.GetModifier(), modifier, ());
}
void TestTime(osmoh::RuleSequence const & rule, uint32_t startH, uint32_t startM, uint32_t endH,
uint32_t endM)
void TestTime(osmoh::RuleSequence const & rule, uint32_t startH, uint32_t startM, uint32_t endH, uint32_t endM)
{
TEST_EQUAL(rule.GetTimes().size(), 1, ());
auto const & time = rule.GetTimes()[0];
@@ -123,9 +121,8 @@ void TestTime(osmoh::RuleSequence const & rule, uint32_t startH, uint32_t startM
TEST_EQUAL(time.GetEnd().GetMinutesCount(), endM, ());
}
void TestMonth(osmoh::RuleSequence const & rule, uint32_t startYear,
Month startMonth, osmoh::MonthDay::TDayNum startDay,
uint32_t endYear, Month endMonth, osmoh::MonthDay::TDayNum endDay)
void TestMonth(osmoh::RuleSequence const & rule, uint32_t startYear, Month startMonth,
osmoh::MonthDay::TDayNum startDay, uint32_t endYear, Month endMonth, osmoh::MonthDay::TDayNum endDay)
{
TEST_EQUAL(rule.GetMonths().size(), 1, ());
auto const & range = rule.GetMonths().back();
@@ -139,16 +136,15 @@ void TestMonth(osmoh::RuleSequence const & rule, uint32_t startYear,
TEST_EQUAL(range.GetEnd().GetDayNum(), endDay, ());
}
void TestMonth(osmoh::RuleSequence const & rule, Month startMonth,
osmoh::MonthDay::TDayNum startDay, Month endMonth, osmoh::MonthDay::TDayNum endDay)
void TestMonth(osmoh::RuleSequence const & rule, Month startMonth, osmoh::MonthDay::TDayNum startDay, Month endMonth,
osmoh::MonthDay::TDayNum endDay)
{
TestMonth(rule, 0 /* startYear */, startMonth, startDay, 0 /* endYear */, endMonth, endDay);
}
void TestMonth(osmoh::RuleSequence const & rule, Month startMonth, Month endMonth)
{
TestMonth(rule, 0 /* startYear */, startMonth, 0 /* startDay */, 0 /* endYear*/, endMonth,
0 /* endDay */);
TestMonth(rule, 0 /* startYear */, startMonth, 0 /* startDay */, 0 /* endYear*/, endMonth, 0 /* endDay */);
}
UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_EnableTests_1)
@@ -859,4 +855,4 @@ UNIT_CLASS_TEST(OHSerDesTestFixture, OpeningHoursSerDes_InverseMonths_Usage_2)
TEST(!oh.IsOpen(GetUnixtimeByDate(2020, Month::Apr, 20, 20 /* hh */, 00 /* mm */)), ());
TEST(!oh.IsOpen(GetUnixtimeByDate(2020, Month::May, 20, 20 /* hh */, 00 /* mm */)), ());
}
} // namespace opening_hours_serdes_tests
} // namespace opening_hours_serdes_tests

View File

@@ -21,8 +21,7 @@ UNIT_CLASS_TEST(PositionAccumulator, Smoke)
PushNextPoint({0.0001, 0.0});
TEST_EQUAL(GetPointsForTesting().size(), 2, ());
TEST(AlmostEqualAbs(GetDirection(), m2::PointD(0.0001, 0.0), kEps), (GetDirection()));
TEST(AlmostEqualAbs(GetTrackLengthMForTesting(), 11.13, kEpsMeters),
(GetTrackLengthMForTesting()));
TEST(AlmostEqualAbs(GetTrackLengthMForTesting(), 11.13, kEpsMeters), (GetTrackLengthMForTesting()));
}
UNIT_CLASS_TEST(PositionAccumulator, GoodSegment)
@@ -36,10 +35,8 @@ UNIT_CLASS_TEST(PositionAccumulator, GoodSegment)
for (signed i = -15; i <= 0; ++i)
PushNextPoint({kStepShortButValid * i, 0.0});
TEST_EQUAL(GetPointsForTesting().size(), 2, ());
TEST(AlmostEqualAbs(GetDirection(), m2::PointD(9 * kStepShortButValid, 0.0), kEps),
(GetDirection()));
TEST(AlmostEqualAbs(GetTrackLengthMForTesting(), 10.02, kEpsMeters),
(GetTrackLengthMForTesting()));
TEST(AlmostEqualAbs(GetDirection(), m2::PointD(9 * kStepShortButValid, 0.0), kEps), (GetDirection()));
TEST(AlmostEqualAbs(GetTrackLengthMForTesting(), 10.02, kEpsMeters), (GetTrackLengthMForTesting()));
double constexpr kStepGood = 0.0001;
for (size_t i = 0; i < 10; ++i)
@@ -47,8 +44,7 @@ UNIT_CLASS_TEST(PositionAccumulator, GoodSegment)
TEST_EQUAL(GetPointsForTesting().size(), 8, ());
TEST(AlmostEqualAbs(GetDirection(), m2::PointD(0.0007, 0.0), kEps), (GetDirection()));
TEST(AlmostEqualAbs(GetTrackLengthMForTesting(), 77.92, kEpsMeters),
(GetTrackLengthMForTesting()));
TEST(AlmostEqualAbs(GetTrackLengthMForTesting(), 77.92, kEpsMeters), (GetTrackLengthMForTesting()));
}
// Test on removing too outdated elements from the position accumulator.
@@ -68,9 +64,9 @@ UNIT_CLASS_TEST(PositionAccumulator, RemovingOutdated)
UNIT_CLASS_TEST(PositionAccumulator, LongSegment)
{
PushNextPoint({0.0, 0.0});
PushNextPoint({0.001, 0.0}); // Longer than |MaxValidSegmentLengthM|.
PushNextPoint({0.001, 0.0}); // Longer than |MaxValidSegmentLengthM|.
TEST_EQUAL(GetPointsForTesting().size(), 1, ());
PushNextPoint({0.001001, 0.0}); // Shorter than |kMinValidSegmentLengthM|, so it's ignored.
PushNextPoint({0.001001, 0.0}); // Shorter than |kMinValidSegmentLengthM|, so it's ignored.
PushNextPoint({0.00102, 0.0});
PushNextPoint({0.00104, 0.0});
// The distance from point {0.001, 0.0} to this one is greater then
@@ -78,7 +74,7 @@ UNIT_CLASS_TEST(PositionAccumulator, LongSegment)
PushNextPoint({0.0012, 0.0});
TEST_EQUAL(GetPointsForTesting().size(), 2, ());
TEST(AlmostEqualAbs(GetDirection(), m2::PointD(0.0002, 0.0), kEps), (GetDirection()));
PushNextPoint({0.00201, 0.0}); // Longer than |PositionAccumulator::kMaxValidSegmentLengthM|.
PushNextPoint({0.00201, 0.0}); // Longer than |PositionAccumulator::kMaxValidSegmentLengthM|.
TEST_EQUAL(GetPointsForTesting().size(), 1, ());
TEST(AlmostEqualAbs(GetDirection(), m2::PointD(0.0, 0.0), kEps), (GetDirection()));
}

View File

@@ -29,8 +29,7 @@ UNIT_CLASS_TEST(RestrictionTest, CrossGraph_NoUTurn)
SetStarter(MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(-1, 0), *m_graph),
MakeFakeEnding(7, 0, m2::PointD(1, 2), *m_graph));
vector<m2::PointD> const expectedGeom = {
{-1.0 /* x */, 0.0 /* y */}, {0.0, 0.0}, {1.0, 0.0}, {1.0, 1.0}, {1.0, 2.0}};
vector<m2::PointD> const expectedGeom = {{-1.0 /* x */, 0.0 /* y */}, {0.0, 0.0}, {1.0, 0.0}, {1.0, 1.0}, {1.0, 2.0}};
TestRouteGeometry(*m_starter, Algorithm::Result::OK, expectedGeom);
}
@@ -40,16 +39,13 @@ UNIT_CLASS_TEST(RestrictionTest, CrossGraph_UTurn)
SetStarter(MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(-1, 0), *m_graph),
MakeFakeEnding(7, 0, m2::PointD(1, 2), *m_graph));
RestrictionVec restrictionsNo = {
{1 /* feature from */, 6 /* feature to */}
};
RestrictionVec restrictionsNo = {{1 /* feature from */, 6 /* feature to */}};
vector<m2::PointD> const expectedGeom = {{-1.0, 0.0}, {0.0, 0.0}, {1.0, 0.0}, {1.0, -1.0},
{1.0, 0.0}, {1.0, 1.0}, {1.0, 2.0}};
TestRestrictions(
6.0 /* expectedTime */,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(-1, 0), *m_graph),
MakeFakeEnding(7, 0, m2::PointD(1, 2), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(6.0 /* expectedTime */,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(-1, 0), *m_graph),
MakeFakeEnding(7, 0, m2::PointD(1, 2), *m_graph), std::move(restrictionsNo), *this);
}
// Finish
@@ -106,78 +102,60 @@ UNIT_CLASS_TEST(RestrictionTest, TriangularGraph)
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 1}, {0, 2}, {0, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(5 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), {}, *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(5 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), {}, *this);
}
// Route through triangular graph with restriction type no from feature 2 to feature 1.
UNIT_CLASS_TEST(RestrictionTest, TriangularGraph_RestrictionNoF2F1)
{
Init(BuildTriangularGraph());
RestrictionVec restrictionsNo = {
{2 /* feature from */, 1 /* feature to */}};
vector<m2::PointD> const expectedGeom = {
{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 2}, {0, 3}};
RestrictionVec restrictionsNo = {{2 /* feature from */, 1 /* feature to */}};
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 2}, {0, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(5 /* featureId */, 0 /* senmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(5 /* featureId */, 0 /* senmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
}
UNIT_CLASS_TEST(RestrictionTest, TriangularGraph_RestrictionNoF5F2)
{
Init(BuildTriangularGraph());
RestrictionVec restrictionsNo = {
{5 /* feature from */, 2 /* feature to */}};
vector<m2::PointD> const expectedGeom = {
{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 2}, {0, 3}};
RestrictionVec restrictionsNo = {{5 /* feature from */, 2 /* feature to */}};
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 2}, {0, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(5 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(5 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
}
UNIT_CLASS_TEST(RestrictionTest, TriangularGraph_RestrictionOnlyF5F3)
{
Init(BuildTriangularGraph());
RestrictionVec restrictionsOnly = {
{{5 /* feature from */, 3 /* feature to */}}};
RestrictionVec restrictionsOnly = {{{5 /* feature from */, 3 /* feature to */}}};
RestrictionVec restrictionsNo;
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
vector<m2::PointD> const expectedGeom = {
{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 2}, {0, 3}};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 2}, {0, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(5 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(5 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
}
UNIT_CLASS_TEST(RestrictionTest, TriangularGraph_RestrictionNoF5F2RestrictionOnlyF5F3)
{
Init(BuildTriangularGraph());
RestrictionVec restrictionsNo = {
{5 /* feature from */, 2 /* feature to */}
};
RestrictionVec restrictionsNo = {{5 /* feature from */, 2 /* feature to */}};
RestrictionVec restrictionsOnly = {
{5 /* feature from */, 3 /* feature to */}
};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
RestrictionVec restrictionsOnly = {{5 /* feature from */, 3 /* feature to */}};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {
{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 2}, {0, 3}};
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 2}, {0, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(5 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(5 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
}
// Finish
@@ -228,43 +206,33 @@ UNIT_CLASS_TEST(RestrictionTest, TwowayCornerGraph)
Init(BuildTwowayCornerGraph());
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 1}, {0, 2}, {0, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(3 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), {}, *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(3 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), {}, *this);
}
UNIT_CLASS_TEST(RestrictionTest, TwowayCornerGraph_RestrictionF3F2No)
{
Init(BuildTwowayCornerGraph());
RestrictionVec restrictionsNo = {
{3 /* feature from */, 2 /* feature to */}
};
vector<m2::PointD> const expectedGeom = {
{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 1}, {0, 2}, {0, 3}};
RestrictionVec restrictionsNo = {{3 /* feature from */, 2 /* feature to */}};
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 1}, {0, 2}, {0, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(3 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(3 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
}
UNIT_CLASS_TEST(RestrictionTest, TwowayCornerGraph_RestrictionF3F1Only)
{
Init(BuildTwowayCornerGraph());
RestrictionVec restrictionsOnly = {
{3 /* feature from */, 1 /* feature to */}
};
RestrictionVec restrictionsOnly = {{3 /* feature from */, 1 /* feature to */}};
RestrictionVec restrictionsNo;
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
vector<m2::PointD> const expectedGeom = {
{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 1}, {0, 2}, {0, 3}};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 1}, {0, 2}, {0, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(3 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(3 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(4, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
}
// Finish
@@ -336,69 +304,52 @@ UNIT_CLASS_TEST(RestrictionTest, TwoSquaresGraph)
Init(BuildTwoSquaresGraph());
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 1}, {0, 2}, {0, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(10 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(11, 0, m2::PointD(0, 3), *m_graph), {}, *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(10 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(11, 0, m2::PointD(0, 3), *m_graph), {}, *this);
}
UNIT_CLASS_TEST(RestrictionTest, TwoSquaresGraph_RestrictionF10F3Only)
{
Init(BuildTwoSquaresGraph());
RestrictionVec restrictionsOnly = {
{10 /* feature from */, 3 /* feature to */}
};
RestrictionVec restrictionsOnly = {{10 /* feature from */, 3 /* feature to */}};
RestrictionVec restrictionsNo;
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {
{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {1, 1}, {0, 2}, {0, 3}};
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {1, 1}, {0, 2}, {0, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(10 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(11, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(10 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(11, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
}
UNIT_CLASS_TEST(RestrictionTest, TwoSquaresGraph_RestrictionF10F3OnlyF3F4Only)
{
Init(BuildTwoSquaresGraph());
RestrictionVec restrictionsOnly = {
{3 /* feature from */, 4 /* feature to */},
{10 /* feature from */, 3 /* feature to */}
};
RestrictionVec restrictionsOnly = {{3 /* feature from */, 4 /* feature to */},
{10 /* feature from */, 3 /* feature to */}};
RestrictionVec restrictionsNo;
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {
{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 2}, {0, 3}};
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}, {0, 2}, {0, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(10 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(11, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(10 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(11, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
}
UNIT_CLASS_TEST(RestrictionTest, TwoSquaresGraph_RestrictionF2F8NoRestrictionF9F1Only)
{
Init(BuildTwoSquaresGraph());
RestrictionVec restrictionsNo = {
{2 /* feature from */, 8 /* feature to */}
}; // Invalid restriction.
RestrictionVec restrictionsOnly = {
{9 /* feature from */, 1 /* feature to */}
}; // Invalid restriction.
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
RestrictionVec restrictionsNo = {{2 /* feature from */, 8 /* feature to */}}; // Invalid restriction.
RestrictionVec restrictionsOnly = {{9 /* feature from */, 1 /* feature to */}}; // Invalid restriction.
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 1}, {0, 2}, {0, 3}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(10 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(11, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(10 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(11, 0, m2::PointD(0, 3), *m_graph), std::move(restrictionsNo), *this);
}
// 2 *
@@ -450,9 +401,8 @@ unique_ptr<SingleVehicleWorldGraph> BuildFlagGraph()
UNIT_TEST(FlagGraph)
{
unique_ptr<WorldGraph> graph = BuildFlagGraph();
auto starter =
MakeStarter(MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *graph),
MakeFakeEnding(6, 0, m2::PointD(0.5, 1), *graph), *graph);
auto starter = MakeStarter(MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *graph),
MakeFakeEnding(6, 0, m2::PointD(0.5, 1), *graph), *graph);
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 0}, {1, 1}, {0.5, 1}};
TestRouteGeometry(*starter, Algorithm::Result::OK, expectedGeom);
}
@@ -461,54 +411,40 @@ UNIT_TEST(FlagGraph)
UNIT_CLASS_TEST(RestrictionTest, FlagGraph_RestrictionF0F3No)
{
Init(BuildFlagGraph());
RestrictionVec restrictionsNo = {
{0 /* feature from */, 3 /* feature to */}
};
vector<m2::PointD> const expectedGeom = {
{2 /* x */, 0 /* y */}, {1, 0}, {0, 0}, {0, 1}, {0.5, 1}};
RestrictionVec restrictionsNo = {{0 /* feature from */, 3 /* feature to */}};
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 0}, {0, 0}, {0, 1}, {0.5, 1}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(0.5, 1), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(0.5, 1), *m_graph), std::move(restrictionsNo), *this);
}
// Route through flag graph with one restriciton (type only) from F0 to F1.
UNIT_CLASS_TEST(RestrictionTest, FlagGraph_RestrictionF0F1Only)
{
Init(BuildFlagGraph());
RestrictionVec restrictionsNo = {
{0 /* feature from */, 1 /* feature to */}
};
RestrictionVec restrictionsNo = {{0 /* feature from */, 1 /* feature to */}};
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 0}, {1, 1}, {0.5, 1}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(0.5, 1), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(0.5, 1), *m_graph), std::move(restrictionsNo), *this);
}
UNIT_CLASS_TEST(RestrictionTest, FlagGraph_PermutationsF1F3NoF7F8OnlyF8F4OnlyF4F6Only)
{
Init(BuildFlagGraph());
RestrictionVec restrictionsNo = {
{0 /* feature from */, 3 /* feature to */}
};
RestrictionVec restrictionsNo = {{0 /* feature from */, 3 /* feature to */}};
RestrictionVec restrictionsOnly = {
{0 /* feature from */, 1 /* feature to */},
{1 /* feature from */, 2 /* feature to */}
};
RestrictionVec restrictionsOnly = {{0 /* feature from */, 1 /* feature to */},
{1 /* feature from */, 2 /* feature to */}};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {
{2 /* x */, 0 /* y */}, {1, 0}, {0, 0}, {0, 1}, {0.5, 1}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(0.5, 1), *m_graph), std::move(restrictionsNo), *this);
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 0}, {0, 0}, {0, 1}, {0.5, 1}};
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(0.5, 1), *m_graph), std::move(restrictionsNo), *this);
}
// 1 *-F4-*-F5-*---F6---* Finish
@@ -556,9 +492,8 @@ unique_ptr<SingleVehicleWorldGraph> BuildPosterGraph()
UNIT_TEST(PosterGraph)
{
unique_ptr<WorldGraph> graph = BuildPosterGraph();
auto starter =
MakeStarter(MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *graph),
MakeFakeEnding(6, 0, m2::PointD(2, 1), *graph), *graph);
auto starter = MakeStarter(MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *graph),
MakeFakeEnding(6, 0, m2::PointD(2, 1), *graph), *graph);
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 0}, {1, 1}, {2, 1}};
TestRouteGeometry(*starter, Algorithm::Result::OK, expectedGeom);
@@ -568,16 +503,12 @@ UNIT_TEST(PosterGraph)
UNIT_CLASS_TEST(RestrictionTest, PosterGraph_RestrictionF0F3No)
{
Init(BuildPosterGraph());
RestrictionVec restrictionsNo = {
{0 /* feature from */, 3 /* feature to */}
};
vector<m2::PointD> const expectedGeom = {
{2 /* x */, 0 /* y */}, {1, 0}, {0, 0}, {0, 1}, {0.5, 1}, {1, 1}, {2, 1}};
RestrictionVec restrictionsNo = {{0 /* feature from */, 3 /* feature to */}};
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 0}, {0, 0}, {0, 1}, {0.5, 1}, {1, 1}, {2, 1}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(2, 1), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(2, 1), *m_graph), std::move(restrictionsNo), *this);
}
// Route through poster graph with restrictions F0-F1 (type only).
@@ -585,19 +516,14 @@ UNIT_CLASS_TEST(RestrictionTest, PosterGraph_RestrictionF0F1Only)
{
Init(BuildPosterGraph());
RestrictionVec restrictionsOnly = {
{0 /* feature from */, 1 /* feature to */}
};
RestrictionVec restrictionsOnly = {{0 /* feature from */, 1 /* feature to */}};
RestrictionVec restrictionsNo;
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {
{2 /* x */, 0 /* y */}, {1, 0}, {0, 0}, {0, 1}, {0.5, 1}, {1, 1}, {2, 1}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(2, 1), *m_graph), std::move(restrictionsNo), *this);
vector<m2::PointD> const expectedGeom = {{2 /* x */, 0 /* y */}, {1, 0}, {0, 0}, {0, 1}, {0.5, 1}, {1, 1}, {2, 1}};
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(2, 0), *m_graph),
MakeFakeEnding(6, 0, m2::PointD(2, 1), *m_graph), std::move(restrictionsNo), *this);
}
// 1 *--F1-->*
@@ -621,12 +547,10 @@ unique_ptr<WorldGraph> BuildTwoWayGraph()
RoadGeometry::Points({{-1.0, 0.0}, {0.0, 0.0}}));
vector<Joint> const joints = {
MakeJoint(
{{0 /* feature id */, 0 /* point id */}, {1, 0}, {3, 1}}), /* joint at point (0, 0) */
MakeJoint(
{{0 /* feature id */, 2 /* point id */}, {1, 3}, {2, 0}}), /* joint at point (3, 0) */
MakeJoint({{3 /* feature id */, 0 /* point id */}}), /* joint at point (-1, 0) */
MakeJoint({{2 /* feature id */, 1 /* point id */}}), /* joint at point (4, 0) */
MakeJoint({{0 /* feature id */, 0 /* point id */}, {1, 0}, {3, 1}}), /* joint at point (0, 0) */
MakeJoint({{0 /* feature id */, 2 /* point id */}, {1, 3}, {2, 0}}), /* joint at point (3, 0) */
MakeJoint({{3 /* feature id */, 0 /* point id */}}), /* joint at point (-1, 0) */
MakeJoint({{2 /* feature id */, 1 /* point id */}}), /* joint at point (4, 0) */
};
traffic::TrafficCache const trafficCache;
@@ -637,9 +561,8 @@ unique_ptr<WorldGraph> BuildTwoWayGraph()
UNIT_TEST(TwoWayGraph)
{
unique_ptr<WorldGraph> graph = BuildTwoWayGraph();
auto starter =
MakeStarter(MakeFakeEnding(3 /* featureId */, 0 /* segmentIdx */, m2::PointD(-1, 0), *graph),
MakeFakeEnding(2, 0, m2::PointD(4, 0), *graph), *graph);
auto starter = MakeStarter(MakeFakeEnding(3 /* featureId */, 0 /* segmentIdx */, m2::PointD(-1, 0), *graph),
MakeFakeEnding(2, 0, m2::PointD(4, 0), *graph), *graph);
vector<m2::PointD> const expectedGeom = {{-1 /* x */, 0 /* y */}, {0, 0}, {1, 0}, {3, 0}, {4, 0}};
TestRouteGeometry(*starter, Algorithm::Result::OK, expectedGeom);
@@ -687,9 +610,8 @@ unique_ptr<SingleVehicleWorldGraph> BuildSquaresGraph()
UNIT_TEST(SquaresGraph)
{
unique_ptr<WorldGraph> graph = BuildSquaresGraph();
auto starter =
MakeStarter(MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *graph),
MakeFakeEnding(5, 0, m2::PointD(0, 0), *graph), *graph);
auto starter = MakeStarter(MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *graph),
MakeFakeEnding(5, 0, m2::PointD(0, 0), *graph), *graph);
vector<m2::PointD> const expectedGeom = {{3 /* x */, 0 /* y */}, {2, 0}, {1, 0}, {0, 0}};
TestRouteGeometry(*starter, Algorithm::Result::OK, expectedGeom);
}
@@ -698,21 +620,15 @@ UNIT_CLASS_TEST(RestrictionTest, SquaresGraph_RestrictionF0F1OnlyF1F5Only)
{
Init(BuildSquaresGraph());
RestrictionVec restrictionsNo;
RestrictionVec restrictionsOnly = {
{0 /* feature from */, 3 /* feature to */}
};
RestrictionVec restrictionsOnly = {{0 /* feature from */, 3 /* feature to */}};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {
{3.0, 0.0}, {2.0, 0.0}, {2.0, 1.0}, {1.0, 1.0}, {1.0, 0.0}, {0.0, 0.0}
};
vector<m2::PointD> const expectedGeom = {{3.0, 0.0}, {2.0, 0.0}, {2.0, 1.0}, {1.0, 1.0}, {1.0, 0.0}, {0.0, 0.0}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(5, 0, m2::PointD(0, 0), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(3, 0), *m_graph),
MakeFakeEnding(5, 0, m2::PointD(0, 0), *m_graph), std::move(restrictionsNo), *this);
}
// 0 Start *--F0--->*<--F1---*---F1---*---F1--->*---F2-->* Finish
@@ -746,16 +662,12 @@ unique_ptr<SingleVehicleWorldGraph> BuildLineGraph()
UNIT_CLASS_TEST(RestrictionTest, LineGraph_RestrictionF1F1No)
{
Init(BuildLineGraph());
RestrictionVec restrictionsNo = {
{1 /* feature from */, 1 /* feature to */}
};
vector<m2::PointD> const expectedGeom = {
{0 /* x */, 0 /* y */}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}};
RestrictionVec restrictionsNo = {{1 /* feature from */, 1 /* feature to */}};
vector<m2::PointD> const expectedGeom = {{0 /* x */, 0 /* y */}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(0, 0), *m_graph),
MakeFakeEnding(2, 0, m2::PointD(5, 0), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(0, 0), *m_graph),
MakeFakeEnding(2, 0, m2::PointD(5, 0), *m_graph), std::move(restrictionsNo), *this);
}
// 2 *---F2-->*
@@ -798,18 +710,14 @@ UNIT_CLASS_TEST(RestrictionTest, FGraph_RestrictionF0F2Only)
{
Init(BuildFGraph());
RestrictionVec restrictionsNo;
RestrictionVec restrictionsOnly = {
{0 /* feature from */, 2 /* feature to */}
};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
RestrictionVec restrictionsOnly = {{0 /* feature from */, 2 /* feature to */}};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
vector<m2::PointD> const expectedGeom = {{0 /* x */, 0 /* y */}, {0, 1}, {1, 1}};
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(0, 0), *m_graph),
MakeFakeEnding(1, 0, m2::PointD(1, 1), *m_graph), std::move(restrictionsNo), *this);
TestRestrictions(expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(0, 0), *m_graph),
MakeFakeEnding(1, 0, m2::PointD(1, 1), *m_graph), std::move(restrictionsNo), *this);
}
/// @todo By VNG: no-pass-through behaviour was changed.
@@ -820,8 +728,7 @@ UNIT_CLASS_TEST(RestrictionTest, FGraph_RestrictionF0F2Only)
// | |
// 0 Start *---F0---*---F1---*---F2---* Finish
// 0 1 2 3
unique_ptr<SingleVehicleWorldGraph> BuildNonPassThroughGraph(bool passThroughStart,
bool passThroughShortWay,
unique_ptr<SingleVehicleWorldGraph> BuildNonPassThroughGraph(bool passThroughStart, bool passThroughShortWay,
bool passThroughLongWay)
{
unique_ptr<TestGeometryLoader> loader = make_unique<TestGeometryLoader>();
@@ -875,7 +782,7 @@ UNIT_CLASS_TEST(RestrictionTest, NonPassThroughShortWay)
SetStarter(MakeFakeEnding(0 /* featureId */, 0 /* segmentIdx */, m2::PointD(0, 0), *m_graph),
MakeFakeEnding(2, 0, m2::PointD(3, 0), *m_graph));
//vector<m2::PointD> const expectedGeom = {{0 /* x */, 0 /* y */}, {1, 0}, {1, 1}, {2, 1}, {2, 0}, {3, 0}};
// vector<m2::PointD> const expectedGeom = {{0 /* x */, 0 /* y */}, {1, 0}, {1, 1}, {2, 1}, {2, 0}, {3, 0}};
vector<m2::PointD> const expectedGeom = {{0 /* x */, 0 /* y */}, {1, 0}, {2, 0}, {3, 0}};
TestRouteGeometry(*m_starter, Algorithm::Result::OK, expectedGeom);
}
@@ -938,16 +845,16 @@ unique_ptr<SingleVehicleWorldGraph> BuildTwoCubeGraph1()
RoadGeometry::Points({{2.0, 1.0}, {3.0, 1.0}}));
vector<Joint> const joints = {
// {{/* feature id */, /* point id */}, ... }
MakeJoint({{7, 0}}), /* joint at point (-1, 0) */
MakeJoint({{0, 0}, {6, 0}, {7, 1}}), /* joint at point (0, 0) */
MakeJoint({{0, 1}, {1, 0}}), /* joint at point (1, 0) */
MakeJoint({{1, 1}, {2, 0}}), /* joint at point (2, 0) */
MakeJoint({{2, 1}, {3, 1}, {8, 0}}), /* joint at point (2, 1) */
MakeJoint({{3, 0}, {4, 1}}), /* joint at point (1, 1) */
MakeJoint({{5, 1}, {4, 0}}), /* joint at point (0, 2) */
MakeJoint({{6, 1}, {5, 0}}), /* joint at point (-1, 1) */
MakeJoint({{8, 1}}), /* joint at point (3, 1) */
// {{/* feature id */, /* point id */}, ... }
MakeJoint({{7, 0}}), /* joint at point (-1, 0) */
MakeJoint({{0, 0}, {6, 0}, {7, 1}}), /* joint at point (0, 0) */
MakeJoint({{0, 1}, {1, 0}}), /* joint at point (1, 0) */
MakeJoint({{1, 1}, {2, 0}}), /* joint at point (2, 0) */
MakeJoint({{2, 1}, {3, 1}, {8, 0}}), /* joint at point (2, 1) */
MakeJoint({{3, 0}, {4, 1}}), /* joint at point (1, 1) */
MakeJoint({{5, 1}, {4, 0}}), /* joint at point (0, 2) */
MakeJoint({{6, 1}, {5, 0}}), /* joint at point (-1, 1) */
MakeJoint({{8, 1}}), /* joint at point (3, 1) */
};
traffic::TrafficCache const trafficCache;
@@ -993,17 +900,17 @@ unique_ptr<SingleVehicleWorldGraph> BuildTwoCubeGraph2()
RoadGeometry::Points({{3.0, 1.0}, {4.0, 1.0}}));
vector<Joint> const joints = {
// {{/* feature id */, /* point id */}, ... }
MakeJoint({{7, 0}}), /* joint at point (-1, 0) */
MakeJoint({{0, 0}, {6, 0}, {7, 1}}), /* joint at point (0, 0) */
MakeJoint({{0, 1}, {1, 0}}), /* joint at point (1, 0) */
MakeJoint({{1, 1}, {2, 0}, {9, 0}}), /* joint at point (2, 0) */
MakeJoint({{2, 1}, {3, 1}, {8, 0}}), /* joint at point (2, 1) */
MakeJoint({{3, 0}, {4, 1}}), /* joint at point (1, 1) */
MakeJoint({{5, 1}, {4, 0}}), /* joint at point (0, 2) */
MakeJoint({{6, 1}, {5, 0}}), /* joint at point (-1, 1) */
MakeJoint({{8, 1}, {9, 1}, {10, 0}}), /* joint at point (3, 1) */
MakeJoint({{10, 1}}) /* joint at point (4, 1) */
// {{/* feature id */, /* point id */}, ... }
MakeJoint({{7, 0}}), /* joint at point (-1, 0) */
MakeJoint({{0, 0}, {6, 0}, {7, 1}}), /* joint at point (0, 0) */
MakeJoint({{0, 1}, {1, 0}}), /* joint at point (1, 0) */
MakeJoint({{1, 1}, {2, 0}, {9, 0}}), /* joint at point (2, 0) */
MakeJoint({{2, 1}, {3, 1}, {8, 0}}), /* joint at point (2, 1) */
MakeJoint({{3, 0}, {4, 1}}), /* joint at point (1, 1) */
MakeJoint({{5, 1}, {4, 0}}), /* joint at point (0, 2) */
MakeJoint({{6, 1}, {5, 0}}), /* joint at point (-1, 1) */
MakeJoint({{8, 1}, {9, 1}, {10, 0}}), /* joint at point (3, 1) */
MakeJoint({{10, 1}}) /* joint at point (4, 1) */
};
traffic::TrafficCache const trafficCache;
@@ -1017,25 +924,20 @@ UNIT_CLASS_TEST(RestrictionTest, RestrictionNoWithWayAsVia_1)
m2::PointD const start(-1.0, 0.0);
m2::PointD const finish(3.0, 1.0);
auto const test = [&](vector<m2::PointD> const & expectedGeom, RestrictionVec && restrictionsNo) {
auto const test = [&](vector<m2::PointD> const & expectedGeom, RestrictionVec && restrictionsNo)
{
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(7 /* featureId */, 0 /* segmentIdx */, start, *m_graph),
MakeFakeEnding(8 /* featureId */, 0 /* segmentIdx */, finish, *m_graph),
std::move(restrictionsNo), *this);
expectedGeom, Algorithm::Result::OK, MakeFakeEnding(7 /* featureId */, 0 /* segmentIdx */, start, *m_graph),
MakeFakeEnding(8 /* featureId */, 0 /* segmentIdx */, finish, *m_graph), std::move(restrictionsNo), *this);
};
// Can not go from |0| to |2| via |1|
RestrictionVec restrictionsNo = {
{0 /* feature 0 */, 1 /* feature 1 */, 2 /* feature 2 */}
};
RestrictionVec restrictionsNo = {{0 /* feature 0 */, 1 /* feature 1 */, 2 /* feature 2 */}};
// Check that without restrictions we can find path better.
test({start, {0.0, 0.0}, {-1.0, 1.0}, {0.0, 2.0}, {1.0, 1.0}, {2.0, 1.0}, finish},
std::move(restrictionsNo));
test({start, {0.0, 0.0}, {-1.0, 1.0}, {0.0, 2.0}, {1.0, 1.0}, {2.0, 1.0}, finish}, std::move(restrictionsNo));
test({start, {0.0, 0.0}, {1.0, 0.0}, {2.0, 0.0}, {2.0, 1.0}, finish},
RestrictionVec());
test({start, {0.0, 0.0}, {1.0, 0.0}, {2.0, 0.0}, {2.0, 1.0}, finish}, RestrictionVec());
}
UNIT_CLASS_TEST(RestrictionTest, RestrictionNoWithWayAsVia_2)
@@ -1044,25 +946,20 @@ UNIT_CLASS_TEST(RestrictionTest, RestrictionNoWithWayAsVia_2)
m2::PointD const start(-1.0, 0.0);
m2::PointD const finish(4.0, 1.0);
auto const test = [&](vector<m2::PointD> const & expectedGeom, RestrictionVec && restrictionsNo) {
auto const test = [&](vector<m2::PointD> const & expectedGeom, RestrictionVec && restrictionsNo)
{
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(7 /* featureId */, 0 /* segmentIdx */, start, *m_graph),
MakeFakeEnding(10 /* featureId */, 0 /* segmentIdx */, finish, *m_graph),
std::move(restrictionsNo), *this);
expectedGeom, Algorithm::Result::OK, MakeFakeEnding(7 /* featureId */, 0 /* segmentIdx */, start, *m_graph),
MakeFakeEnding(10 /* featureId */, 0 /* segmentIdx */, finish, *m_graph), std::move(restrictionsNo), *this);
};
// Can go from |0| to |9| only via |1|
RestrictionVec restrictionsNo = {
{0 /* feature 0 */, 1 /* feature 1 */, 9 /* feature 2 */}
};
RestrictionVec restrictionsNo = {{0 /* feature 0 */, 1 /* feature 1 */, 9 /* feature 2 */}};
// Check that without restrictions we can find path better.
test({start, {0.0, 0.0}, {1.0, 0.0}, {2.0, 0.0}, {2.0, 1.0}, {3.0, 1.0}, finish},
std::move(restrictionsNo));
test({start, {0.0, 0.0}, {1.0, 0.0}, {2.0, 0.0}, {2.0, 1.0}, {3.0, 1.0}, finish}, std::move(restrictionsNo));
test({start, {0.0, 0.0}, {1.0, 0.0}, {2.0, 0.0}, {3.0, 1.0}, finish},
RestrictionVec());
test({start, {0.0, 0.0}, {1.0, 0.0}, {2.0, 0.0}, {3.0, 1.0}, finish}, RestrictionVec());
}
UNIT_CLASS_TEST(RestrictionTest, RestrictionOnlyWithWayAsVia_1)
@@ -1071,21 +968,17 @@ UNIT_CLASS_TEST(RestrictionTest, RestrictionOnlyWithWayAsVia_1)
m2::PointD const start(-1.0, 0.0);
m2::PointD const finish(4.0, 1.0);
auto const test = [&](vector<m2::PointD> const & expectedGeom, RestrictionVec && restrictionsNo) {
auto const test = [&](vector<m2::PointD> const & expectedGeom, RestrictionVec && restrictionsNo)
{
TestRestrictions(
expectedGeom, Algorithm::Result::OK,
MakeFakeEnding(7 /* featureId */, 0 /* segmentIdx */, start, *m_graph),
MakeFakeEnding(10 /* featureId */, 0 /* segmentIdx */, finish, *m_graph),
std::move(restrictionsNo), *this);
expectedGeom, Algorithm::Result::OK, MakeFakeEnding(7 /* featureId */, 0 /* segmentIdx */, start, *m_graph),
MakeFakeEnding(10 /* featureId */, 0 /* segmentIdx */, finish, *m_graph), std::move(restrictionsNo), *this);
};
RestrictionVec restrictionsNo;
// Can go from |0| to |2| only via |1|
RestrictionVec restrictionsOnly = {
{0 /* feature 0 */, 1 /* feature 1 */, 2 /* feature 2 */}
};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly,
restrictionsNo);
RestrictionVec restrictionsOnly = {{0 /* feature 0 */, 1 /* feature 1 */, 2 /* feature 2 */}};
ConvertRestrictionsOnlyToNo(m_graph->GetIndexGraphForTests(kTestNumMwmId), restrictionsOnly, restrictionsNo);
// Check that without restrictions we can find path better.
test({start, {0, 0}, {1, 0}, {2, 0}, {2, 1}, {3, 1}, finish}, std::move(restrictionsNo));

View File

@@ -53,77 +53,77 @@ void FillRoadAccessBySample_2(RoadAccess & roadAccess)
roadAccess.SetAccess(std::move(wayToAccess), std::move(pointToAccess));
}
//void FillRoadAccessBySampleConditional_1(RoadAccess & roadAccess)
// void FillRoadAccessBySampleConditional_1(RoadAccess & roadAccess)
//{
// std::vector<std::string> const openingHoursStrings = {
// "Mo-Su", "10:00-18:00", "Mo-Fr 10:00-14:00", "09:00-13:00", "Apr - May", "2010 - 2100"};
// std::vector<std::string> const openingHoursStrings = {
// "Mo-Su", "10:00-18:00", "Mo-Fr 10:00-14:00", "09:00-13:00", "Apr - May", "2010 - 2100"};
//
// std::vector<osmoh::OpeningHours> openingHours;
// for (auto const & oh : openingHoursStrings)
// {
// openingHours.emplace_back(oh);
// TEST(openingHours.back().IsValid(), ());
// }
// std::vector<osmoh::OpeningHours> openingHours;
// for (auto const & oh : openingHoursStrings)
// {
// openingHours.emplace_back(oh);
// TEST(openingHours.back().IsValid(), ());
// }
//
// RoadAccess::Conditional conditional_1;
// conditional_1.Insert(RoadAccess::Type::No, std::move(openingHours[0]));
// conditional_1.Insert(RoadAccess::Type::Private, std::move(openingHours[1]));
// RoadAccess::Conditional conditional_1;
// conditional_1.Insert(RoadAccess::Type::No, std::move(openingHours[0]));
// conditional_1.Insert(RoadAccess::Type::Private, std::move(openingHours[1]));
//
// RoadAccess::Conditional conditional_2;
// conditional_2.Insert(RoadAccess::Type::Destination, std::move(openingHours[2]));
// RoadAccess::Conditional conditional_2;
// conditional_2.Insert(RoadAccess::Type::Destination, std::move(openingHours[2]));
//
// RoadAccess::Conditional conditional_3;
// conditional_3.Insert(RoadAccess::Type::No, std::move(openingHours[4]));
// conditional_3.Insert(RoadAccess::Type::Destination, std::move(openingHours[3]));
// RoadAccess::Conditional conditional_3;
// conditional_3.Insert(RoadAccess::Type::No, std::move(openingHours[4]));
// conditional_3.Insert(RoadAccess::Type::Destination, std::move(openingHours[3]));
//
// RoadAccess::Conditional conditional_4;
// conditional_4.Insert(RoadAccess::Type::Destination, std::move(openingHours[5]));
// RoadAccess::Conditional conditional_4;
// conditional_4.Insert(RoadAccess::Type::Destination, std::move(openingHours[5]));
//
// RoadAccess::WayToAccessConditional wayToAccessConditional = {{1 /* featureId */, conditional_1},
// {2 /* featureId */, conditional_2}};
// RoadAccess::WayToAccessConditional wayToAccessConditional = {{1 /* featureId */, conditional_1},
// {2 /* featureId */, conditional_2}};
//
// RoadAccess::PointToAccessConditional pointToAccessConditional = {
// {RoadPoint(3 /* featureId */, 0 /* pointId */), conditional_3},
// {RoadPoint(4 /* featureId */, 7 /* pointId */), conditional_4}};
// RoadAccess::PointToAccessConditional pointToAccessConditional = {
// {RoadPoint(3 /* featureId */, 0 /* pointId */), conditional_3},
// {RoadPoint(4 /* featureId */, 7 /* pointId */), conditional_4}};
//
// roadAccess.SetAccessConditional(std::move(wayToAccessConditional), std::move(pointToAccessConditional));
//}
// roadAccess.SetAccessConditional(std::move(wayToAccessConditional), std::move(pointToAccessConditional));
// }
//
//void FillRoadAccessBySampleConditional_2(RoadAccess & roadAccess)
// void FillRoadAccessBySampleConditional_2(RoadAccess & roadAccess)
//{
// std::vector<std::string> const openingHoursStrings = {
// "Mo", "Apr-May 03:00-04:25", "Mo-Sa 12:00-13:00", "2010-2098", "Nov-Apr", "19:00-21:00"};
// std::vector<std::string> const openingHoursStrings = {
// "Mo", "Apr-May 03:00-04:25", "Mo-Sa 12:00-13:00", "2010-2098", "Nov-Apr", "19:00-21:00"};
//
// std::vector<osmoh::OpeningHours> openingHours;
// for (auto const & oh : openingHoursStrings)
// {
// openingHours.emplace_back(oh);
// TEST(openingHours.back().IsValid(), (oh));
// }
// std::vector<osmoh::OpeningHours> openingHours;
// for (auto const & oh : openingHoursStrings)
// {
// openingHours.emplace_back(oh);
// TEST(openingHours.back().IsValid(), (oh));
// }
//
// RoadAccess::Conditional conditional_1;
// conditional_1.Insert(RoadAccess::Type::Private, std::move(openingHours[0]));
// RoadAccess::Conditional conditional_1;
// conditional_1.Insert(RoadAccess::Type::Private, std::move(openingHours[0]));
//
// RoadAccess::Conditional conditional_2;
// conditional_2.Insert(RoadAccess::Type::No, std::move(openingHours[1]));
// conditional_2.Insert(RoadAccess::Type::Private, std::move(openingHours[2]));
// RoadAccess::Conditional conditional_2;
// conditional_2.Insert(RoadAccess::Type::No, std::move(openingHours[1]));
// conditional_2.Insert(RoadAccess::Type::Private, std::move(openingHours[2]));
//
// RoadAccess::Conditional conditional_3;
// conditional_3.Insert(RoadAccess::Type::Destination, std::move(openingHours[3]));
// RoadAccess::Conditional conditional_3;
// conditional_3.Insert(RoadAccess::Type::Destination, std::move(openingHours[3]));
//
// RoadAccess::Conditional conditional_4;
// conditional_4.Insert(RoadAccess::Type::No, std::move(openingHours[4]));
// conditional_4.Insert(RoadAccess::Type::No, std::move(openingHours[5]));
// RoadAccess::Conditional conditional_4;
// conditional_4.Insert(RoadAccess::Type::No, std::move(openingHours[4]));
// conditional_4.Insert(RoadAccess::Type::No, std::move(openingHours[5]));
//
// RoadAccess::WayToAccessConditional wayToAccessConditional = {{1 /* featureId */, conditional_1},
// {2 /* featureId */, conditional_2}};
// RoadAccess::WayToAccessConditional wayToAccessConditional = {{1 /* featureId */, conditional_1},
// {2 /* featureId */, conditional_2}};
//
// RoadAccess::PointToAccessConditional pointToAccessConditional = {
// {RoadPoint(3 /* featureId */, 10 /* pointId */), conditional_3},
// {RoadPoint(4 /* featureId */, 2 /* pointId */), conditional_4}};
// RoadAccess::PointToAccessConditional pointToAccessConditional = {
// {RoadPoint(3 /* featureId */, 10 /* pointId */), conditional_3},
// {RoadPoint(4 /* featureId */, 2 /* pointId */), conditional_4}};
//
// roadAccess.SetAccessConditional(std::move(wayToAccessConditional), std::move(pointToAccessConditional));
//}
// roadAccess.SetAccessConditional(std::move(wayToAccessConditional), std::move(pointToAccessConditional));
// }
class RoadAccessSerDesTest
{
@@ -170,7 +170,7 @@ UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes)
// @TODO Tests below and functions FillRoadAccessBySampleConditional_1 and
// FillRoadAccessBySampleConditional_2 should be uncommented when access:conditional is
// switched on.
//UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes_Conditional_One_Vehicle)
// UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes_Conditional_One_Vehicle)
//{
// auto constexpr kVehicleTypeCount = static_cast<size_t>(VehicleType::Count);
// for (size_t vehicleTypeId = 0; vehicleTypeId < kVehicleTypeCount; ++vehicleTypeId)
@@ -187,7 +187,7 @@ UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes)
// }
//}
//
//UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes_Conditional_Several_Vehicles)
// UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes_Conditional_Several_Vehicles)
//{
// RoadAccess roadAccessCar;
// FillRoadAccessBySampleConditional_1(roadAccessCar);
@@ -204,7 +204,7 @@ UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes)
// TestDeserialize(VehicleType::Pedestrian, roadAccessPedestrian);
//}
//
//UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes_Conditional_Mixed_Several_Vehicles)
// UNIT_CLASS_TEST(RoadAccessSerDesTest, RoadAccess_Serdes_Conditional_Mixed_Several_Vehicles)
//{
// RoadAccess roadAccessCar;
// FillRoadAccessBySampleConditional_1(roadAccessCar);
@@ -350,68 +350,61 @@ UNIT_TEST(RoadAccess_WayBlockedConditional)
double expectedWeight = 3.0;
vector<TestEdge> expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
graph.SetEdgeAccessConditional(1, 2, RoadAccess::Type::No, "Jan - Jul");
auto const april = []() {
return GetUnixtimeByDate(2020, Month::Apr, 1, 12 /* hh */, 00 /* mm */);
};
auto const april = []() { return GetUnixtimeByDate(2020, Month::Apr, 1, 12 /* hh */, 00 /* mm */); };
graph.SetCurrentTimeGetter(april);
expectedWeight = 0;
expectedEdges = {};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight, expectedEdges);
auto const november = []() {
return GetUnixtimeByDate(2020, Month::Nov, 1, 12 /* hh */, 00 /* mm */);
};
auto const november = []() { return GetUnixtimeByDate(2020, Month::Nov, 1, 12 /* hh */, 00 /* mm */); };
graph.SetCurrentTimeGetter(november);
expectedWeight = 3.0;
expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
}
//UNIT_TEST(RoadAccess_PointBlockedConditional)
// UNIT_TEST(RoadAccess_PointBlockedConditional)
//{
// uint32_t const numVertices = 4;
// TestIndexGraphTopology graph(numVertices);
// uint32_t const numVertices = 4;
// TestIndexGraphTopology graph(numVertices);
//
// graph.AddDirectedEdge(0, 1, 1.0);
// graph.AddDirectedEdge(1, 2, 1.0);
// graph.AddDirectedEdge(2, 3, 1.0);
// graph.AddDirectedEdge(0, 1, 1.0);
// graph.AddDirectedEdge(1, 2, 1.0);
// graph.AddDirectedEdge(2, 3, 1.0);
//
// double expectedWeight = 3.0;
// vector<TestEdge> expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
// double expectedWeight = 3.0;
// vector<TestEdge> expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
//
// graph.SetVertexAccessConditional(1, RoadAccess::Type::No, "Jan - Jul");
// graph.SetVertexAccessConditional(1, RoadAccess::Type::No, "Jan - Jul");
//
// auto const april = []() {
// return GetUnixtimeByDate(2020, Month::Apr, 1, 12 /* hh */, 00 /* mm */);
// };
// auto const april = []() {
// return GetUnixtimeByDate(2020, Month::Apr, 1, 12 /* hh */, 00 /* mm */);
// };
//
// graph.SetCurrentTimeGetter(april);
// expectedWeight = 0;
// expectedEdges = {};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight,
// expectedEdges);
// graph.SetCurrentTimeGetter(april);
// expectedWeight = 0;
// expectedEdges = {};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight,
// expectedEdges);
//
// auto const november = []() {
// return GetUnixtimeByDate(2020, Month::Nov, 1, 12 /* hh */, 00 /* mm */);
// };
// auto const november = []() {
// return GetUnixtimeByDate(2020, Month::Nov, 1, 12 /* hh */, 00 /* mm */);
// };
//
// graph.SetCurrentTimeGetter(november);
// expectedWeight = 3.0;
// expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
//}
// graph.SetCurrentTimeGetter(november);
// expectedWeight = 3.0;
// expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
// }
UNIT_TEST(RoadAccess_WayBlockedAvoidConditional)
{
@@ -425,22 +418,19 @@ UNIT_TEST(RoadAccess_WayBlockedAvoidConditional)
double expectedWeight = 2.0;
vector<TestEdge> expectedEdges = {{0, 1}, {1, 3}};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
graph.SetEdgeAccessConditional(0, 1, RoadAccess::Type::No, "Mo-Fr 10:00 - 19:00");
auto const mondayAlmostTenHours = []() {
return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 9 /* hh */, 50 /* mm */);
};
auto const mondayAlmostTenHours = []()
{ return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 9 /* hh */, 50 /* mm */); };
// In this time we probably will able to pass 0->1 edge, but we are not sure, so we should avoid
// such edges.
graph.SetCurrentTimeGetter(mondayAlmostTenHours);
expectedWeight = 20.0;
expectedEdges = {{0, 2}, {2, 3}};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
graph.SetEdgeAccess(0, 2, RoadAccess::Type::No);
@@ -448,72 +438,69 @@ UNIT_TEST(RoadAccess_WayBlockedAvoidConditional)
graph.SetCurrentTimeGetter(mondayAlmostTenHours);
expectedWeight = 2.0;
expectedEdges = {{0, 1}, {1, 3}};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
auto const mondayTwelveHours = []() {
return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 12 /* hh */, 00 /* mm */);
};
auto const mondayTwelveHours = []()
{ return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 12 /* hh */, 00 /* mm */); };
// But if we sure that in this time edge: 0->1 will be blocked, we definitely should not pass
// 0->1. In this case no way will be found.
graph.SetCurrentTimeGetter(mondayTwelveHours);
expectedWeight = 0.0;
expectedEdges = {};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight, expectedEdges);
}
//UNIT_TEST(RoadAccess_PointBlockedAvoidConditional)
// UNIT_TEST(RoadAccess_PointBlockedAvoidConditional)
//{
// uint32_t const numVertices = 4;
// TestIndexGraphTopology graph(numVertices);
// uint32_t const numVertices = 4;
// TestIndexGraphTopology graph(numVertices);
//
// graph.AddDirectedEdge(0, 1, 1.0);
// graph.AddDirectedEdge(0, 2, 10.0);
// graph.AddDirectedEdge(1, 3, 1.0);
// graph.AddDirectedEdge(2, 3, 10.0);
// graph.AddDirectedEdge(0, 1, 1.0);
// graph.AddDirectedEdge(0, 2, 10.0);
// graph.AddDirectedEdge(1, 3, 1.0);
// graph.AddDirectedEdge(2, 3, 10.0);
//
// double expectedWeight = 2.0;
// vector<TestEdge> expectedEdges = {{0, 1}, {1, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
// double expectedWeight = 2.0;
// vector<TestEdge> expectedEdges = {{0, 1}, {1, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
//
// graph.SetVertexAccessConditional(1, RoadAccess::Type::No, "Mo-Fr 10:00 - 19:00");
// graph.SetVertexAccessConditional(1, RoadAccess::Type::No, "Mo-Fr 10:00 - 19:00");
//
// auto const mondayAlmostTenHours = []() {
// return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 9 /* hh */, 50 /* mm */);
// };
// auto const mondayAlmostTenHours = []() {
// return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 9 /* hh */, 50 /* mm */);
// };
//
// // In this time we probably will able to pass vertex: 1, but we are not sure, so we should avoid
// // such edges.
// graph.SetCurrentTimeGetter(mondayAlmostTenHours);
// expectedWeight = 20.0;
// expectedEdges = {{0, 2}, {2, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
// // In this time we probably will able to pass vertex: 1, but we are not sure, so we should avoid
// // such edges.
// graph.SetCurrentTimeGetter(mondayAlmostTenHours);
// expectedWeight = 20.0;
// expectedEdges = {{0, 2}, {2, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
//
// graph.SetEdgeAccess(0, 2, RoadAccess::Type::No);
// graph.SetEdgeAccess(0, 2, RoadAccess::Type::No);
//
// // But if this is the only path (we blocked 0->2 above), we should pass through vertex: 1 anyway.
// graph.SetCurrentTimeGetter(mondayAlmostTenHours);
// expectedWeight = 2.0;
// expectedEdges = {{0, 1}, {1, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
// // But if this is the only path (we blocked 0->2 above), we should pass through vertex: 1 anyway.
// graph.SetCurrentTimeGetter(mondayAlmostTenHours);
// expectedWeight = 2.0;
// expectedEdges = {{0, 1}, {1, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
//
// auto const mondayTwelveHours = []() {
// return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 12 /* hh */, 00 /* mm */);
// };
// auto const mondayTwelveHours = []() {
// return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 12 /* hh */, 00 /* mm */);
// };
//
// // But if we sure that in this time vertex: 1 will be blocked, we definitely should not pass
// // through vertex: 1. In this case no way will be found.
// graph.SetCurrentTimeGetter(mondayTwelveHours);
// expectedWeight = 0.0;
// expectedEdges = {};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight,
// expectedEdges);
//}
// // But if we sure that in this time vertex: 1 will be blocked, we definitely should not pass
// // through vertex: 1. In this case no way will be found.
// graph.SetCurrentTimeGetter(mondayTwelveHours);
// expectedWeight = 0.0;
// expectedEdges = {};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight,
// expectedEdges);
// }
UNIT_TEST(RoadAccess_WayBlockedConditional_Yes_No)
{
@@ -526,74 +513,68 @@ UNIT_TEST(RoadAccess_WayBlockedConditional_Yes_No)
double expectedWeight = 3.0;
vector<TestEdge> expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
graph.SetEdgeAccessConditional(1, 2, RoadAccess::Type::No, "Mo-Fr");
graph.SetEdgeAccessConditional(1, 2, RoadAccess::Type::Yes, "Sa-Su");
auto const tuesday = []() {
return GetUnixtimeByDate(2020, Month::Apr, Weekday::Tuesday, 10 /* hh */, 00 /* mm */);
};
auto const tuesday = []() { return GetUnixtimeByDate(2020, Month::Apr, Weekday::Tuesday, 10 /* hh */, 00 /* mm */); };
// Way is blocked from Monday to Friday
graph.SetCurrentTimeGetter(tuesday);
expectedWeight = 0;
expectedEdges = {};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight, expectedEdges);
auto const saturday = []() {
return GetUnixtimeByDate(2020, Month::Nov, Weekday::Saturday, 10 /* hh */, 00 /* mm */);
};
auto const saturday = []()
{ return GetUnixtimeByDate(2020, Month::Nov, Weekday::Saturday, 10 /* hh */, 00 /* mm */); };
// And open from Saturday to Sunday
graph.SetCurrentTimeGetter(saturday);
expectedWeight = 3.0;
expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
}
//UNIT_TEST(RoadAccess_PointBlockedConditional_Yes_No)
// UNIT_TEST(RoadAccess_PointBlockedConditional_Yes_No)
//{
// uint32_t const numVertices = 4;
// TestIndexGraphTopology graph(numVertices);
// uint32_t const numVertices = 4;
// TestIndexGraphTopology graph(numVertices);
//
// graph.AddDirectedEdge(0, 1, 1.0);
// graph.AddDirectedEdge(1, 2, 1.0);
// graph.AddDirectedEdge(2, 3, 1.0);
// graph.AddDirectedEdge(0, 1, 1.0);
// graph.AddDirectedEdge(1, 2, 1.0);
// graph.AddDirectedEdge(2, 3, 1.0);
//
// double expectedWeight = 3.0;
// vector<TestEdge> expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
// double expectedWeight = 3.0;
// vector<TestEdge> expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
//
// graph.SetVertexAccessConditional(1, RoadAccess::Type::No, "Mo-Fr");
// graph.SetVertexAccessConditional(1, RoadAccess::Type::Yes, "Sa-Su");
// graph.SetVertexAccessConditional(1, RoadAccess::Type::No, "Mo-Fr");
// graph.SetVertexAccessConditional(1, RoadAccess::Type::Yes, "Sa-Su");
//
// auto const tuesday = []() {
// return GetUnixtimeByDate(2020, Month::Apr, Weekday::Tuesday, 10 /* hh */, 00 /* mm */);
// };
// auto const tuesday = []() {
// return GetUnixtimeByDate(2020, Month::Apr, Weekday::Tuesday, 10 /* hh */, 00 /* mm */);
// };
//
// // Way is blocked from Monday to Friday
// graph.SetCurrentTimeGetter(tuesday);
// expectedWeight = 0;
// expectedEdges = {};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight,
// expectedEdges);
// // Way is blocked from Monday to Friday
// graph.SetCurrentTimeGetter(tuesday);
// expectedWeight = 0;
// expectedEdges = {};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight,
// expectedEdges);
//
// auto const saturday = []() {
// return GetUnixtimeByDate(2020, Month::Nov, Weekday::Saturday, 10 /* hh */, 00 /* mm */);
// };
// auto const saturday = []() {
// return GetUnixtimeByDate(2020, Month::Nov, Weekday::Saturday, 10 /* hh */, 00 /* mm */);
// };
//
// // And open from Saturday to Sunday
// graph.SetCurrentTimeGetter(saturday);
// expectedWeight = 3.0;
// expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
//}
// // And open from Saturday to Sunday
// graph.SetCurrentTimeGetter(saturday);
// expectedWeight = 3.0;
// expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
// TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
// expectedEdges);
// }
UNIT_TEST(RoadAccess_WayBlockedAvoidPrivateConditional)
{
@@ -607,22 +588,19 @@ UNIT_TEST(RoadAccess_WayBlockedAvoidPrivateConditional)
double expectedWeight = 2.0;
vector<TestEdge> expectedEdges = {{0, 1}, {1, 3}};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
graph.SetEdgeAccessConditional(0, 1, RoadAccess::Type::Private, "Mo-Fr 19:00 - 23:00");
auto const mondayAlmostTwentyHalfHours = []() {
return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 20 /* hh */, 30 /* mm */);
};
auto const mondayAlmostTwentyHalfHours = []()
{ return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 20 /* hh */, 30 /* mm */); };
// We should avoid ways with private accesses. At 20:30 edge: 0->1 definitely has private access,
// thus the answer is: 0->2->3.
graph.SetCurrentTimeGetter(mondayAlmostTwentyHalfHours);
expectedWeight = 20.0;
expectedEdges = {{0, 2}, {2, 3}};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
graph.SetEdgeAccess(0, 2, RoadAccess::Type::No);
@@ -630,8 +608,7 @@ UNIT_TEST(RoadAccess_WayBlockedAvoidPrivateConditional)
graph.SetCurrentTimeGetter(mondayAlmostTwentyHalfHours);
expectedWeight = 2.0;
expectedEdges = {{0, 1}, {1, 3}};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
}
UNIT_TEST(RoadAccess_WayBlockedAlwaysNoExceptMonday)
@@ -645,28 +622,23 @@ UNIT_TEST(RoadAccess_WayBlockedAlwaysNoExceptMonday)
double expectedWeight = 3.0;
vector<TestEdge> expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
// Always access no for edge: 1->2.
graph.SetEdgeAccess(1, 2, RoadAccess::Type::No);
expectedWeight = 0;
expectedEdges = {};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, false /* pathFound */, expectedWeight, expectedEdges);
// Except Monday, access yes in this day.
graph.SetEdgeAccessConditional(1, 2, RoadAccess::Type::Yes, "Mo");
auto const monday = []() {
return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 10 /* hh */, 00 /* mm */);
};
auto const monday = []() { return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 10 /* hh */, 00 /* mm */); };
graph.SetCurrentTimeGetter(monday);
expectedWeight = 3.0;
expectedEdges = {{0, 1}, {1, 2}, {2, 3}};
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 3 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
}
UNIT_TEST(RoadAccess_WayBlockedWhenStartButOpenWhenReach)
@@ -686,12 +658,10 @@ UNIT_TEST(RoadAccess_WayBlockedWhenStartButOpenWhenReach)
double expectedWeight = 10804.0;
vector<TestEdge> expectedEdges = {{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}};
TestTopologyGraph(graph, 0 /* from */, 5 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 5 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
auto const startAt_11_50 = []() {
return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 11 /* hh */, 50 /* mm */);
};
auto const startAt_11_50 = []()
{ return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 11 /* hh */, 50 /* mm */); };
graph.SetCurrentTimeGetter(startAt_11_50);
// When we will be at |3|, current time should be:
@@ -700,12 +670,10 @@ UNIT_TEST(RoadAccess_WayBlockedWhenStartButOpenWhenReach)
graph.SetEdgeAccessConditional(3, 4, RoadAccess::Type::No, "10:00 - 13:00");
expectedWeight = 10804.0;
expectedEdges = {{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}};
TestTopologyGraph(graph, 0 /* from */, 5 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 5 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
auto const startAt_10_50 = []() {
return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 10 /* hh */, 50 /* mm */);
};
auto const startAt_10_50 = []()
{ return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 10 /* hh */, 50 /* mm */); };
graph.SetCurrentTimeGetter(startAt_10_50);
// When we will be at |3|, current time should be:
@@ -713,8 +681,7 @@ UNIT_TEST(RoadAccess_WayBlockedWhenStartButOpenWhenReach)
// dangerous zone, but we are not sure, so we should chose alternative way.
expectedWeight = 12802.0;
expectedEdges = {{0, 1}, {1, 2}, {2, 3}, {3, 6}, {6, 5}};
TestTopologyGraph(graph, 0 /* from */, 5 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 5 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
// Block alternative way.
graph.SetEdgeAccess(3, 6, RoadAccess::Type::No);
@@ -722,12 +689,10 @@ UNIT_TEST(RoadAccess_WayBlockedWhenStartButOpenWhenReach)
// way.
expectedWeight = 10804.0;
expectedEdges = {{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}};
TestTopologyGraph(graph, 0 /* from */, 5 /* to */, true /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 5 /* to */, true /* pathFound */, expectedWeight, expectedEdges);
auto const startAt_9_00 = []() {
return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 9 /* hh */, 00 /* mm */);
};
auto const startAt_9_00 = []()
{ return GetUnixtimeByDate(2020, Month::Apr, Weekday::Monday, 9 /* hh */, 00 /* mm */); };
graph.SetCurrentTimeGetter(startAt_9_00);
// If we start at 9:00:00 we will arrive at |3| at:
@@ -736,7 +701,6 @@ UNIT_TEST(RoadAccess_WayBlockedWhenStartButOpenWhenReach)
// way) no way should be found.
expectedWeight = 0.0;
expectedEdges = {};
TestTopologyGraph(graph, 0 /* from */, 5 /* to */, false /* pathFound */, expectedWeight,
expectedEdges);
TestTopologyGraph(graph, 0 /* from */, 5 /* to */, false /* pathFound */, expectedWeight, expectedEdges);
}
} // namespace namespace road_access_test
} // namespace road_access_test

View File

@@ -33,10 +33,7 @@ public:
m_mwmInfo = mwmsInfoList[0];
}
FeatureID MakeFeatureID(uint32_t offset) const
{
return FeatureID(MwmSet::MwmId(m_mwmInfo), offset);
}
FeatureID MakeFeatureID(uint32_t offset) const { return FeatureID(MwmSet::MwmId(m_mwmInfo), offset); }
private:
/// @name MwmSet overrides
@@ -71,22 +68,24 @@ IRoadGraph::RoadInfo RoadGraphMockSource::GetRoadInfo(FeatureID const & featureI
return m_roads[featureId.m_index];
}
double RoadGraphMockSource::GetSpeedKMpH(FeatureID const & featureId,
SpeedParams const & /* speedParams */) const
double RoadGraphMockSource::GetSpeedKMpH(FeatureID const & featureId, SpeedParams const & /* speedParams */) const
{
CHECK_LESS(featureId.m_index, m_roads.size(), ("Invalid feature id."));
return m_roads[featureId.m_index].m_speedKMPH;
}
double RoadGraphMockSource::GetMaxSpeedKMpH() const { return kMaxSpeedKMpH; }
double RoadGraphMockSource::GetMaxSpeedKMpH() const
{
return kMaxSpeedKMpH;
}
void RoadGraphMockSource::ForEachFeatureClosestToCross(m2::PointD const & /* cross */,
ICrossEdgesLoader & edgesLoader) const
{
for (size_t roadId = 0; roadId < m_roads.size(); ++roadId)
{
edgesLoader(MakeTestFeatureID(base::checked_cast<uint32_t>(roadId)), m_roads[roadId]
.m_junctions, m_roads[roadId].m_bidirectional);
edgesLoader(MakeTestFeatureID(base::checked_cast<uint32_t>(roadId)), m_roads[roadId].m_junctions,
m_roads[roadId].m_bidirectional);
}
}

View File

@@ -26,11 +26,9 @@ public:
double GetMaxSpeedKMpH() const override;
/// @}
void ForEachFeatureClosestToCross(m2::PointD const & cross,
ICrossEdgesLoader & edgeLoader) const override;
void ForEachFeatureClosestToCross(m2::PointD const & cross, ICrossEdgesLoader & edgeLoader) const override;
void GetFeatureTypes(FeatureID const & featureId, feature::TypesHolder & types) const override;
void GetJunctionTypes(geometry::PointWithAltitude const & junction,
feature::TypesHolder & types) const override;
void GetJunctionTypes(geometry::PointWithAltitude const & junction, feature::TypesHolder & types) const override;
routing::IRoadGraph::Mode GetMode() const override;
private:

View File

@@ -57,8 +57,7 @@ UNIT_TEST(RoadGraph_NearestEdges)
}
// We are standing at x junction.
geometry::PointWithAltitude const crossPos =
geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 0));
geometry::PointWithAltitude const crossPos = geometry::MakePointWithAltitudeForTesting(m2::PointD(0, 0));
// Expected outgoing edges.
IRoadGraph::EdgeListT expectedOutgoing = {

View File

@@ -25,28 +25,20 @@ using namespace routing::turns;
using namespace std;
// For all test geometry: geometry[0] == geometry[1], since info about 1st point will be lost.
static vector<m2::PointD> const kTestGeometry =
{{0,0}, {0,0}, {1,1}, {1,2}, {1,3}, {1,4}};
static vector<Segment> const kTestSegments =
{{0, 0, 0, true},
{0, 0, 1, true},
{0, 0, 2, true},
{0, 0, 3, true},
{0, 0, 4, true}};
static vector<turns::TurnItem> const kTestTurns(
{turns::TurnItem(1, turns::CarDirection::None),
turns::TurnItem(2, turns::CarDirection::TurnLeft),
turns::TurnItem(3, turns::CarDirection::TurnRight),
turns::TurnItem(4, turns::CarDirection::None),
turns::TurnItem(5, turns::CarDirection::ReachedYourDestination)});
static vector<double> const kTestTimes =
{0.0, 7.0, 10.0, 19.0, 20.0};
static vector<RouteSegment::RoadNameInfo> const kTestNames =
{{"Street0", "", "", "", "", false},
{"Street1", "", "", "", "", false},
{"Street2", "", "", "", "", false},
{"", "", "", "", "", false},
{"Street3", "", "", "", "", false}};
static vector<m2::PointD> const kTestGeometry = {{0, 0}, {0, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}};
static vector<Segment> const kTestSegments = {
{0, 0, 0, true}, {0, 0, 1, true}, {0, 0, 2, true}, {0, 0, 3, true}, {0, 0, 4, true}};
static vector<turns::TurnItem> const kTestTurns({turns::TurnItem(1, turns::CarDirection::None),
turns::TurnItem(2, turns::CarDirection::TurnLeft),
turns::TurnItem(3, turns::CarDirection::TurnRight),
turns::TurnItem(4, turns::CarDirection::None),
turns::TurnItem(5, turns::CarDirection::ReachedYourDestination)});
static vector<double> const kTestTimes = {0.0, 7.0, 10.0, 19.0, 20.0};
static vector<RouteSegment::RoadNameInfo> const kTestNames = {{"Street0", "", "", "", "", false},
{"Street1", "", "", "", "", false},
{"Street2", "", "", "", "", false},
{"", "", "", "", "", false},
{"Street3", "", "", "", "", false}};
void GetTestRouteSegments(vector<m2::PointD> const & routePoints, vector<turns::TurnItem> const & turns,
vector<RouteSegment::RoadNameInfo> const & streets, vector<double> const & times,
@@ -68,18 +60,13 @@ location::GpsInfo GetGps(double x, double y)
vector<vector<Segment>> const GetSegments()
{
auto const segmentsAllReal = kTestSegments;
vector<Segment> const segmentsAllFake =
{{kFakeNumMwmId, 0, 0, true},
{kFakeNumMwmId, 0, 1, true},
{kFakeNumMwmId, 0, 2, true},
{kFakeNumMwmId, 0, 3, true},
{kFakeNumMwmId, 0, 4, true}};
vector<Segment> const segmentsFakeHeadAndTail =
{{kFakeNumMwmId, 0, 0, true},
{0, 0, 1, true},
{0, 0, 2, true},
{0, 0, 3, true},
{kFakeNumMwmId, 0, 4, true}};
vector<Segment> const segmentsAllFake = {{kFakeNumMwmId, 0, 0, true},
{kFakeNumMwmId, 0, 1, true},
{kFakeNumMwmId, 0, 2, true},
{kFakeNumMwmId, 0, 3, true},
{kFakeNumMwmId, 0, 4, true}};
vector<Segment> const segmentsFakeHeadAndTail = {
{kFakeNumMwmId, 0, 0, true}, {0, 0, 1, true}, {0, 0, 2, true}, {0, 0, 3, true}, {kFakeNumMwmId, 0, 4, true}};
return {segmentsAllReal, segmentsFakeHeadAndTail, segmentsAllFake};
}
@@ -99,8 +86,7 @@ UNIT_TEST(AddAbsentCountryToRouteTest)
UNIT_TEST(FinshRouteOnSomeDistanceToTheFinishPointTest)
{
for (auto const vehicleType :
{VehicleType::Car, VehicleType::Bicycle, VehicleType::Pedestrian, VehicleType::Transit})
for (auto const vehicleType : {VehicleType::Car, VehicleType::Bicycle, VehicleType::Pedestrian, VehicleType::Transit})
{
auto const settings = GetRoutingSettings(vehicleType);
for (auto const & segments : GetSegments())
@@ -116,8 +102,8 @@ UNIT_TEST(FinshRouteOnSomeDistanceToTheFinishPointTest)
route.SetGeometry(kTestGeometry.begin(), kTestGeometry.end());
route.SetSubroteAttrs(vector<Route::SubrouteAttrs>(
{Route::SubrouteAttrs(geometry::PointWithAltitude(kTestGeometry.front(), geometry::kDefaultAltitudeMeters),
geometry::PointWithAltitude(kTestGeometry.back(), geometry::kDefaultAltitudeMeters),
0, kTestSegments.size())}));
geometry::PointWithAltitude(kTestGeometry.back(), geometry::kDefaultAltitudeMeters), 0,
kTestSegments.size())}));
// The route should be finished at some distance to the finish point.
double const distToFinish = settings.m_finishToleranceM;
@@ -163,7 +149,7 @@ UNIT_TEST(DistanceAndTimeToCurrentTurnTest)
auto pos = kTestGeometry[0];
route.GetNearestTurn(distance, turn);
size_t currentTurnIndex = 2; // Turn with m_index == 1 is None.
size_t currentTurnIndex = 2; // Turn with m_index == 1 is None.
TEST_ALMOST_EQUAL_ABS(distance, mercator::DistanceOnEarth(pos, kTestGeometry[currentTurnIndex]), 0.1, ());
TEST_EQUAL(turn, kTestTurns[currentTurnIndex - 1], ());
@@ -217,7 +203,7 @@ UNIT_TEST(DistanceAndTimeToCurrentTurnTest)
route.MoveIterator(GetGps(pos.x, pos.y));
route.GetNearestTurn(distance, turn);
size_t const currentTurnIndex = 5; // Turn with m_index == 4 is None.
size_t const currentTurnIndex = 5; // Turn with m_index == 4 is None.
TEST_ALMOST_EQUAL_ABS(distance, mercator::DistanceOnEarth(pos, kTestGeometry[currentTurnIndex]), 0.1, ());
TEST_EQUAL(turn, kTestTurns[currentTurnIndex - 1], ());
@@ -244,7 +230,7 @@ UNIT_TEST(NextTurnTest)
{
// Initial point.
size_t const currentTurnIndex = 2; // Turn with m_index == 1 is None.
size_t const currentTurnIndex = 2; // Turn with m_index == 1 is None.
route.GetNearestTurn(distance, turn);
TEST_EQUAL(turn, kTestTurns[currentTurnIndex - 1], ());
@@ -270,7 +256,7 @@ UNIT_TEST(NextTurnTest)
auto const pos = (kTestGeometry[3] + kTestGeometry[4]) / 2;
route.MoveIterator(GetGps(pos.x, pos.y));
size_t const currentTurnIndex = 5; // Turn with m_index == 4 is None.
size_t const currentTurnIndex = 5; // Turn with m_index == 4 is None.
route.GetNearestTurn(distance, turn);
TEST_EQUAL(turn, kTestTurns[currentTurnIndex - 1], ());
@@ -295,17 +281,17 @@ UNIT_TEST(NextTurnsTest)
// Initial point.
auto const pos = kTestGeometry[0];
size_t const currentTurnIndex = 2; // Turn with m_index == 1 is None.
size_t const currentTurnIndex = 2; // Turn with m_index == 1 is None.
size_t const nextTurnIndex = 3;
TEST(route.GetNextTurns(turnsDist), ());
TEST_EQUAL(turnsDist.size(), 2, ());
double const firstSegLenM = mercator::DistanceOnEarth(pos, kTestGeometry[currentTurnIndex]);
double const secondSegLenM = mercator::DistanceOnEarth(kTestGeometry[currentTurnIndex], kTestGeometry[nextTurnIndex]);
double const secondSegLenM =
mercator::DistanceOnEarth(kTestGeometry[currentTurnIndex], kTestGeometry[nextTurnIndex]);
TEST_EQUAL(turnsDist[0].m_turnItem, kTestTurns[currentTurnIndex - 1], ());
TEST_EQUAL(turnsDist[1].m_turnItem, kTestTurns[nextTurnIndex - 1], ());
TEST_ALMOST_EQUAL_ABS(turnsDist[0].m_distMeters, firstSegLenM, 0.1, ());
TEST_ALMOST_EQUAL_ABS(turnsDist[1].m_distMeters, firstSegLenM + secondSegLenM, 0.1, ());
}
{
// Move between points 1 and 2.
@@ -317,7 +303,8 @@ UNIT_TEST(NextTurnsTest)
TEST(route.GetNextTurns(turnsDist), ());
TEST_EQUAL(turnsDist.size(), 2, ());
double const firstSegLenM = mercator::DistanceOnEarth(pos, kTestGeometry[currentTurnIndex]);
double const secondSegLenM = mercator::DistanceOnEarth(kTestGeometry[currentTurnIndex], kTestGeometry[nextTurnIndex]);
double const secondSegLenM =
mercator::DistanceOnEarth(kTestGeometry[currentTurnIndex], kTestGeometry[nextTurnIndex]);
TEST_EQUAL(turnsDist[0].m_turnItem, kTestTurns[currentTurnIndex - 1], ());
TEST_EQUAL(turnsDist[1].m_turnItem, kTestTurns[nextTurnIndex - 1], ());
TEST_ALMOST_EQUAL_ABS(turnsDist[0].m_distMeters, firstSegLenM, 0.1, ());
@@ -329,11 +316,12 @@ UNIT_TEST(NextTurnsTest)
route.MoveIterator(GetGps(pos.x, pos.y));
size_t const currentTurnIndex = 3;
size_t const nextTurnIndex = 5; // Turn with m_index == 4 is None.
size_t const nextTurnIndex = 5; // Turn with m_index == 4 is None.
TEST(route.GetNextTurns(turnsDist), ());
TEST_EQUAL(turnsDist.size(), 2, ());
double const firstSegLenM = mercator::DistanceOnEarth(pos, kTestGeometry[currentTurnIndex]);
double const secondSegLenM = mercator::DistanceOnEarth(kTestGeometry[currentTurnIndex], kTestGeometry[nextTurnIndex]);
double const secondSegLenM =
mercator::DistanceOnEarth(kTestGeometry[currentTurnIndex], kTestGeometry[nextTurnIndex]);
TEST_EQUAL(turnsDist[0].m_turnItem, kTestTurns[currentTurnIndex - 1], ());
TEST_EQUAL(turnsDist[1].m_turnItem, kTestTurns[nextTurnIndex - 1], ());
TEST_ALMOST_EQUAL_ABS(turnsDist[0].m_distMeters, firstSegLenM, 0.1, ());
@@ -344,7 +332,7 @@ UNIT_TEST(NextTurnsTest)
auto const pos = (kTestGeometry[3] + kTestGeometry[4]) / 2;
route.MoveIterator(GetGps(pos.x, pos.y));
size_t const currentTurnIndex = 5; // Turn with m_index == 4 is None.
size_t const currentTurnIndex = 5; // Turn with m_index == 4 is None.
// nextTurn is absent.
TEST(route.GetNextTurns(turnsDist), ());
double const firstSegLenM = mercator::DistanceOnEarth(pos, kTestGeometry[currentTurnIndex]);
@@ -366,13 +354,8 @@ UNIT_TEST(NextTurnsTest)
//
UNIT_TEST(SelfIntersectedRouteMatchingTest)
{
vector<m2::PointD> const kRouteGeometry =
{{0.0001, 0.0},
{0.0001, 0.0},
{0.0001, 0.0002},
{0.0002, 0.0002},
{0.0002, 0.0001},
{0.0, 0.0001}};
vector<m2::PointD> const kRouteGeometry = {{0.0001, 0.0}, {0.0001, 0.0}, {0.0001, 0.0002},
{0.0002, 0.0002}, {0.0002, 0.0001}, {0.0, 0.0001}};
double constexpr kRoundingErrorMeters = 0.001;
Route route("TestRouter", 0 /* route id */);
@@ -382,16 +365,15 @@ UNIT_TEST(SelfIntersectedRouteMatchingTest)
GetTestRouteSegments(kRouteGeometry, {}, {}, {}, routeSegments);
route.SetRouteSegments(std::move(routeSegments));
auto const testMachedPos = [&](location::GpsInfo const & pos,
location::GpsInfo const & expectedMatchingPos,
size_t expectedIndexInRoute) {
auto const testMachedPos =
[&](location::GpsInfo const & pos, location::GpsInfo const & expectedMatchingPos, size_t expectedIndexInRoute)
{
location::RouteMatchingInfo routeMatchingInfo;
route.MoveIterator(pos);
location::GpsInfo matchedPos = pos;
route.MatchLocationToRoute(matchedPos, routeMatchingInfo);
TEST_LESS(mercator::DistanceOnEarth(
m2::PointD(matchedPos.m_latitude, matchedPos.m_longitude),
m2::PointD(expectedMatchingPos.m_latitude, expectedMatchingPos.m_longitude)),
TEST_LESS(mercator::DistanceOnEarth(m2::PointD(matchedPos.m_latitude, matchedPos.m_longitude),
m2::PointD(expectedMatchingPos.m_latitude, expectedMatchingPos.m_longitude)),
kRoundingErrorMeters, ());
TEST_EQUAL(max(size_t(1), routeMatchingInfo.GetIndexInRoute()), expectedIndexInRoute, ());
};

View File

@@ -27,20 +27,17 @@ size_t UndirectedGraph::GetNodesNumber() const
return m_adjs.size();
}
void UndirectedGraph::GetEdgesList(Vertex const & vertex, bool /* isOutgoing */,
EdgeListT & adj)
void UndirectedGraph::GetEdgesList(Vertex const & vertex, bool /* isOutgoing */, EdgeListT & adj)
{
GetAdjacencyList(vertex, adj);
}
void UndirectedGraph::GetIngoingEdgesList(astar::VertexData<Vertex, Weight> const & vertexData,
EdgeListT & adj)
void UndirectedGraph::GetIngoingEdgesList(astar::VertexData<Vertex, Weight> const & vertexData, EdgeListT & adj)
{
GetEdgesList(vertexData.m_vertex, false /* isOutgoing */, adj);
}
void UndirectedGraph::GetOutgoingEdgesList(astar::VertexData<Vertex, Weight> const & vertexData,
EdgeListT & adj)
void UndirectedGraph::GetOutgoingEdgesList(astar::VertexData<Vertex, Weight> const & vertexData, EdgeListT & adj)
{
GetEdgesList(vertexData.m_vertex, true /* isOutgoing */, adj);
}
@@ -71,16 +68,15 @@ void DirectedGraph::GetEdgesList(Vertex const & v, bool isOutgoing, EdgeListT &
namespace
{
inline double TimeBetweenSec(geometry::PointWithAltitude const & j1,
geometry::PointWithAltitude const & j2, double speedMPS)
inline double TimeBetweenSec(geometry::PointWithAltitude const & j1, geometry::PointWithAltitude const & j2,
double speedMPS)
{
ASSERT(speedMPS > 0.0, ());
ASSERT_NOT_EQUAL(j1.GetAltitude(), geometry::kInvalidAltitude, ());
ASSERT_NOT_EQUAL(j2.GetAltitude(), geometry::kInvalidAltitude, ());
double const distanceM = mercator::DistanceOnEarth(j1.GetPoint(), j2.GetPoint());
double const altitudeDiffM =
static_cast<double>(j2.GetAltitude()) - static_cast<double>(j1.GetAltitude());
double const altitudeDiffM = static_cast<double>(j2.GetAltitude()) - static_cast<double>(j1.GetAltitude());
return std::sqrt(distanceM * distanceM + altitudeDiffM * altitudeDiffM) / speedMPS;
}
@@ -88,11 +84,8 @@ inline double TimeBetweenSec(geometry::PointWithAltitude const & j1,
class WeightedEdge
{
public:
WeightedEdge() = default; // needed for buffer_vector only
WeightedEdge(geometry::PointWithAltitude const & target, double weight)
: target(target), weight(weight)
{
}
WeightedEdge() = default; // needed for buffer_vector only
WeightedEdge(geometry::PointWithAltitude const & target, double weight) : target(target), weight(weight) {}
inline geometry::PointWithAltitude const & GetTarget() const { return target; }
inline double GetWeight() const { return weight; }
@@ -108,13 +101,12 @@ using Algorithm = AStarAlgorithm<geometry::PointWithAltitude, WeightedEdge, doub
class RoadGraph : public Algorithm::Graph
{
public:
explicit RoadGraph(RoadGraphIFace const & roadGraph)
: m_roadGraph(roadGraph), m_maxSpeedMPS(measurement_utils::KmphToMps(roadGraph.GetMaxSpeedKMpH()))
: m_roadGraph(roadGraph)
, m_maxSpeedMPS(measurement_utils::KmphToMps(roadGraph.GetMaxSpeedKMpH()))
{}
void GetOutgoingEdgesList(astar::VertexData<Vertex, Weight> const & vertexData,
EdgeListT & adj) override
void GetOutgoingEdgesList(astar::VertexData<Vertex, Weight> const & vertexData, EdgeListT & adj) override
{
auto const & v = vertexData.m_vertex;
IRoadGraph::EdgeListT edges;
@@ -133,8 +125,7 @@ public:
}
}
void GetIngoingEdgesList(astar::VertexData<Vertex, Weight> const & vertexData,
EdgeListT & adj) override
void GetIngoingEdgesList(astar::VertexData<Vertex, Weight> const & vertexData, EdgeListT & adj) override
{
auto const & v = vertexData.m_vertex;
IRoadGraph::EdgeListT edges;
@@ -181,12 +172,9 @@ std::string DebugPrint(TestAStarBidirectionalAlgo::Result const & value)
{
switch (value)
{
case TestAStarBidirectionalAlgo::Result::OK:
return "OK";
case TestAStarBidirectionalAlgo::Result::NoPath:
return "NoPath";
case TestAStarBidirectionalAlgo::Result::Cancelled:
return "Cancelled";
case TestAStarBidirectionalAlgo::Result::OK: return "OK";
case TestAStarBidirectionalAlgo::Result::NoPath: return "NoPath";
case TestAStarBidirectionalAlgo::Result::Cancelled: return "Cancelled";
}
UNREACHABLE();
@@ -196,8 +184,7 @@ std::string DebugPrint(TestAStarBidirectionalAlgo::Result const & value)
// *************************** AStar-bidirectional routing algorithm implementation ***********************
TestAStarBidirectionalAlgo::Result TestAStarBidirectionalAlgo::CalculateRoute(
RoadGraphIFace const & graph, geometry::PointWithAltitude const & startPos,
geometry::PointWithAltitude const & finalPos,
RoutingResult<IRoadGraph::Vertex, IRoadGraph::Weight> & path)
geometry::PointWithAltitude const & finalPos, RoutingResult<IRoadGraph::Vertex, IRoadGraph::Weight> & path)
{
RoadGraph roadGraph(graph);
base::Cancellable cancellable;
@@ -206,4 +193,4 @@ TestAStarBidirectionalAlgo::Result TestAStarBidirectionalAlgo::CalculateRoute(
Algorithm::Result const res = Algorithm().FindPathBidirectional(params, path);
return Convert(res);
}
} // namespace routing_tests
} // namespace routing_test

View File

@@ -18,7 +18,7 @@ using namespace routing;
struct SimpleEdge
{
SimpleEdge() = default; // needed for buffer_vector only
SimpleEdge() = default; // needed for buffer_vector only
SimpleEdge(uint32_t to, double weight) : m_to(to), m_weight(weight) {}
uint32_t GetTarget() const { return m_to; }
@@ -37,9 +37,7 @@ public:
double GetSpeedKMpH(Edge const & edge, SpeedParams const & speedParams) const
{
double const speedKMpH =
(edge.IsFake() ? GetMaxSpeedKMpH()
: GetSpeedKMpH(edge.GetFeatureId(), speedParams));
double const speedKMpH = (edge.IsFake() ? GetMaxSpeedKMpH() : GetSpeedKMpH(edge.GetFeatureId(), speedParams));
ASSERT_LESS_OR_EQUAL(speedKMpH, GetMaxSpeedKMpH(), ());
return speedKMpH;
}
@@ -53,10 +51,8 @@ public:
// AStarGraph overrides
// @{
void GetIngoingEdgesList(astar::VertexData<Vertex, Weight> const & vertexData,
EdgeListT & adj) override;
void GetOutgoingEdgesList(astar::VertexData<Vertex, Weight> const & vertexData,
EdgeListT & adj) override;
void GetIngoingEdgesList(astar::VertexData<Vertex, Weight> const & vertexData, EdgeListT & adj) override;
void GetOutgoingEdgesList(astar::VertexData<Vertex, Weight> const & vertexData, EdgeListT & adj) override;
double HeuristicCostEstimate(Vertex const & v, Vertex const & w) override;
// @}
@@ -102,4 +98,4 @@ public:
};
std::string DebugPrint(TestAStarBidirectionalAlgo::Result const & result);
} // namespace routing_tests
} // namespace routing_test

View File

@@ -2,7 +2,6 @@
#include "routing/road_graph.hpp"
#include "routing/route.hpp"
#include "routing/road_graph.hpp"
#include "routing/routing_helpers.hpp"
#include "routing/segment.hpp"
#include "routing/turns.hpp"
@@ -25,11 +24,8 @@ using namespace std;
UNIT_TEST(FillSegmentInfoSmokeTest)
{
vector<Segment> const segments = {
{0 /* mwmId */, 1 /* featureId */, 0 /* segmentIdx */, true /* forward */}};
vector<m2::PointD> const junctions = {
m2::PointD(0.0 /* x */, 0.0 /* y */),
m2::PointD(0.0 /* x */, 0.0 /* y */)};
vector<Segment> const segments = {{0 /* mwmId */, 1 /* featureId */, 0 /* segmentIdx */, true /* forward */}};
vector<m2::PointD> const junctions = {m2::PointD(0.0 /* x */, 0.0 /* y */), m2::PointD(0.0 /* x */, 0.0 /* y */)};
vector<turns::TurnItem> const & turnDirs = {{1 /* point index */, CarDirection::ReachedYourDestination}};
vector<double> const times = {1.0};
@@ -44,23 +40,15 @@ UNIT_TEST(FillSegmentInfoSmokeTest)
UNIT_TEST(FillSegmentInfoTest)
{
vector<Segment> const segments =
{{0 /* mwmId */, 1 /* featureId */, 0 /* segmentIdx */, true /* forward */},
{0, 2, 0, true},
{0, 3, 0, true}};
vector<m2::PointD> const junctions =
{m2::PointD(0.0 /* x */, 0.0 /* y */),
m2::PointD(0.0 /* x */, 0.0 /* y */),
m2::PointD(0.1 /* x */, 0.0 /* y */),
m2::PointD(0.2 /* x */, 0.0 /* y */)};
vector<turns::TurnItem> const & turnDirs =
{{1 /* point index */, CarDirection::None},
{2 /* point index */, CarDirection::TurnRight},
{3 /* point index */, CarDirection::ReachedYourDestination}};
vector<RouteSegment::RoadNameInfo> const streets =
{{"zero", "", "", "", "", false},
{"first", "", "", "", "", false},
{"second", "", "", "", "", false}};
vector<Segment> const segments = {
{0 /* mwmId */, 1 /* featureId */, 0 /* segmentIdx */, true /* forward */}, {0, 2, 0, true}, {0, 3, 0, true}};
vector<m2::PointD> const junctions = {m2::PointD(0.0 /* x */, 0.0 /* y */), m2::PointD(0.0 /* x */, 0.0 /* y */),
m2::PointD(0.1 /* x */, 0.0 /* y */), m2::PointD(0.2 /* x */, 0.0 /* y */)};
vector<turns::TurnItem> const & turnDirs = {{1 /* point index */, CarDirection::None},
{2 /* point index */, CarDirection::TurnRight},
{3 /* point index */, CarDirection::ReachedYourDestination}};
vector<RouteSegment::RoadNameInfo> const streets = {
{"zero", "", "", "", "", false}, {"first", "", "", "", "", false}, {"second", "", "", "", "", false}};
vector<double> const times = {1.0, 2.0, 3.0};
vector<RouteSegment> segmentInfo;
@@ -85,22 +73,19 @@ UNIT_TEST(PolylineInRectTest)
// One point polyline outside the rect.
{
auto const junctions =
IRoadGraph::PointWithAltitudeVec({{m2::PointD(3.0, 3.0), 0 /* altitude */}});
auto const junctions = IRoadGraph::PointWithAltitudeVec({{m2::PointD(3.0, 3.0), 0 /* altitude */}});
TEST(!RectCoversPolyline(junctions, m2::RectD(0.0, 0.0, 2.0, 2.0)), ());
}
// One point polyline inside the rect.
{
auto const junctions =
IRoadGraph::PointWithAltitudeVec({{m2::PointD(1.0, 1.0), 0 /* altitude */}});
auto const junctions = IRoadGraph::PointWithAltitudeVec({{m2::PointD(1.0, 1.0), 0 /* altitude */}});
TEST(RectCoversPolyline(junctions, m2::RectD(0.0, 0.0, 2.0, 2.0)), ());
}
// One point polyline on the rect border.
{
auto const junctions =
IRoadGraph::PointWithAltitudeVec({{m2::PointD(0.0, 0.0), 0 /* altitude */}});
auto const junctions = IRoadGraph::PointWithAltitudeVec({{m2::PointD(0.0, 0.0), 0 /* altitude */}});
TEST(RectCoversPolyline(junctions, m2::RectD(0.0, 0.0, 2.0, 2.0)), ());
}

View File

@@ -14,15 +14,9 @@ using RoadType = RoutingOptions::RoadType;
class RoutingOptionsTests
{
public:
RoutingOptionsTests()
{
m_savedOptions = RoutingOptions::LoadCarOptionsFromSettings();
}
RoutingOptionsTests() { m_savedOptions = RoutingOptions::LoadCarOptionsFromSettings(); }
~RoutingOptionsTests()
{
RoutingOptions::SaveCarOptionsToSettings(m_savedOptions);
}
~RoutingOptionsTests() { RoutingOptions::SaveCarOptionsToSettings(m_savedOptions); }
private:
RoutingOptions m_savedOptions;
@@ -60,12 +54,10 @@ void Checker(std::vector<RoutingOptions::Road> const & include)
UNIT_TEST(RoutingOptionTest)
{
Checker({RoutingOptions::Road::Toll, RoutingOptions::Road::Motorway,
RoutingOptions::Road::Dirty});
Checker({RoutingOptions::Road::Toll, RoutingOptions::Road::Motorway, RoutingOptions::Road::Dirty});
Checker({RoutingOptions::Road::Toll, RoutingOptions::Road::Dirty});
Checker({RoutingOptions::Road::Toll, RoutingOptions::Road::Ferry,
RoutingOptions::Road::Dirty});
Checker({RoutingOptions::Road::Toll, RoutingOptions::Road::Ferry, RoutingOptions::Road::Dirty});
Checker({RoutingOptions::Road::Dirty});
Checker({RoutingOptions::Road::Toll});
@@ -75,9 +67,8 @@ UNIT_TEST(RoutingOptionTest)
UNIT_CLASS_TEST(RoutingOptionsTests, GetSetTest)
{
RoutingOptions options = CreateOptions({RoutingOptions::Road::Toll,
RoutingOptions::Road::Motorway,
RoutingOptions::Road::Dirty});
RoutingOptions options =
CreateOptions({RoutingOptions::Road::Toll, RoutingOptions::Road::Motorway, RoutingOptions::Road::Dirty});
RoutingOptions::SaveCarOptionsToSettings(options);
RoutingOptions fromSettings = RoutingOptions::LoadCarOptionsFromSettings();

View File

@@ -30,14 +30,12 @@ using chrono::steady_clock;
vector<m2::PointD> kTestRoute = {{0., 1.}, {0., 1.}, {0., 3.}, {0., 4.}};
vector<Segment> const kTestSegments = {{0, 0, 0, true}, {0, 0, 1, true}, {0, 0, 2, true}};
vector<turns::TurnItem> const kTestTurnsReachOnly =
{turns::TurnItem(1, turns::CarDirection::None),
turns::TurnItem(2, turns::CarDirection::None),
turns::TurnItem(3, turns::CarDirection::ReachedYourDestination)};
vector<turns::TurnItem> const kTestTurns =
{turns::TurnItem(1, turns::CarDirection::None),
turns::TurnItem(2, turns::CarDirection::TurnLeft),
turns::TurnItem(3, turns::CarDirection::ReachedYourDestination)};
vector<turns::TurnItem> const kTestTurnsReachOnly = {turns::TurnItem(1, turns::CarDirection::None),
turns::TurnItem(2, turns::CarDirection::None),
turns::TurnItem(3, turns::CarDirection::ReachedYourDestination)};
vector<turns::TurnItem> const kTestTurns = {turns::TurnItem(1, turns::CarDirection::None),
turns::TurnItem(2, turns::CarDirection::TurnLeft),
turns::TurnItem(3, turns::CarDirection::ReachedYourDestination)};
vector<double> const kTestTimes = {5.0, 10.0, 15.0};
auto const kRouteBuildingMaxDuration = seconds(30);
@@ -53,25 +51,25 @@ private:
public:
DummyRouter(Route & route, RouterResultCode code, size_t & buildCounter)
: m_route(route), m_code(code), m_buildCount(buildCounter)
{
}
: m_route(route)
, m_code(code)
, m_buildCount(buildCounter)
{}
string GetName() const override { return "dummy"; }
void ClearState() override {}
void SetGuides(GuidesTracks && /* guides */) override {}
RouterResultCode CalculateRoute(Checkpoints const & /* checkpoints */,
m2::PointD const & /* startDirection */, bool /* adjust */,
RouterDelegate const & /* delegate */, Route & route) override
RouterResultCode CalculateRoute(Checkpoints const & /* checkpoints */, m2::PointD const & /* startDirection */,
bool /* adjust */, RouterDelegate const & /* delegate */, Route & route) override
{
++m_buildCount;
route = m_route;
return m_code;
}
bool FindClosestProjectionToRoad(m2::PointD const & point, m2::PointD const & direction,
double radius, EdgeProj & proj) override
bool FindClosestProjectionToRoad(m2::PointD const & point, m2::PointD const & direction, double radius,
EdgeProj & proj) override
{
return false;
}
@@ -81,20 +79,18 @@ public:
class ReturnCodesRouter : public IRouter
{
public:
ReturnCodesRouter(initializer_list<RouterResultCode> const & returnCodes,
vector<m2::PointD> const & route)
: m_returnCodes(returnCodes), m_route(route)
{
}
ReturnCodesRouter(initializer_list<RouterResultCode> const & returnCodes, vector<m2::PointD> const & route)
: m_returnCodes(returnCodes)
, m_route(route)
{}
// IRouter overrides:
string GetName() const override { return "return codes router"; }
void ClearState() override {}
void SetGuides(GuidesTracks && /* guides */) override {}
RouterResultCode CalculateRoute(Checkpoints const & /* checkpoints */,
m2::PointD const & /* startDirection */, bool /* adjust */,
RouterDelegate const & /* delegate */, Route & route) override
RouterResultCode CalculateRoute(Checkpoints const & /* checkpoints */, m2::PointD const & /* startDirection */,
bool /* adjust */, RouterDelegate const & /* delegate */, Route & route) override
{
TEST_LESS(m_returnCodesIdx, m_returnCodes.size(), ());
route = Route(GetName(), m_route.begin(), m_route.end(), 0 /* route id */);
@@ -102,8 +98,8 @@ public:
return m_returnCodes[m_returnCodesIdx++];
}
bool FindClosestProjectionToRoad(m2::PointD const & point, m2::PointD const & direction,
double radius, EdgeProj & proj) override
bool FindClosestProjectionToRoad(m2::PointD const & point, m2::PointD const & direction, double radius,
EdgeProj & proj) override
{
return false;
}
@@ -128,10 +124,7 @@ public:
bool WaitUntil(steady_clock::time_point const & time)
{
unique_lock<mutex> lock(m_waitingMutex);
m_cv.wait_until(lock, time, [this, &time]
{
return m_flag || steady_clock::now() > time;
});
m_cv.wait_until(lock, time, [this, &time] { return m_flag || steady_clock::now() > time; });
return m_flag;
}
@@ -147,7 +140,8 @@ class SessionStateTest
{
public:
SessionStateTest(initializer_list<SessionState> expectedStates, RoutingSession & routingSession)
: m_expectedStates(expectedStates), m_session(routingSession)
: m_expectedStates(expectedStates)
, m_session(routingSession)
{
for (size_t i = 1; i < expectedStates.size(); ++i)
{
@@ -157,10 +151,10 @@ public:
}
TimedSignal timedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [this, &timedSignal]() {
m_session.SetChangeSessionStateCallback([this](SessionState previous, SessionState current) {
TestChangeSessionStateCallbackCall(previous, current);
});
GetPlatform().RunTask(Platform::Thread::Gui, [this, &timedSignal]()
{
m_session.SetChangeSessionStateCallback([this](SessionState previous, SessionState current)
{ TestChangeSessionStateCallbackCall(previous, current); });
timedSignal.Signal();
});
TEST(timedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("Callback is not set."));
@@ -171,7 +165,8 @@ public:
TEST_EQUAL(m_numberOfTestCalls, m_expectedNumberOfStateChanging,
("Wrong number of calls of SetState() callback.", m_expectedStates));
TimedSignal timedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [this, &timedSignal]() {
GetPlatform().RunTask(Platform::Thread::Gui, [this, &timedSignal]()
{
m_session.SetChangeSessionStateCallback(nullptr);
timedSignal.Signal();
});
@@ -214,7 +209,8 @@ void TestMovingByUpdatingLat(SessionStateTest const & sessionState, vector<doubl
{
location::GpsInfo uptInfo(info);
TimedSignal signal;
GetPlatform().RunTask(Platform::Thread::Gui, [&session, &signal, &lats, &uptInfo]() {
GetPlatform().RunTask(Platform::Thread::Gui, [&session, &signal, &lats, &uptInfo]()
{
for (auto const lat : lats)
{
uptInfo.m_latitude = lat;
@@ -223,16 +219,14 @@ void TestMovingByUpdatingLat(SessionStateTest const & sessionState, vector<doubl
signal.Signal();
});
TEST(signal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration),
("Along route moving timeout."));
TEST(signal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("Along route moving timeout."));
}
void TestLeavingRoute(RoutingSession & session, location::GpsInfo const & info)
{
vector<double> const latitudes = {0.0, -0.001, -0.002, -0.003, -0.004, -0.005,
-0.006, -0.007, -0.008, -0.009, -0.01, -0.011};
SessionStateTest sessionStateTest({SessionState::OnRoute, SessionState::RouteNeedRebuild},
session);
SessionStateTest sessionStateTest({SessionState::OnRoute, SessionState::RouteNeedRebuild}, session);
TestMovingByUpdatingLat(sessionStateTest, latitudes, info, session);
}
@@ -244,22 +238,19 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestRouteBuilding)
TimedSignal timedSignal;
size_t counter = 0;
GetPlatform().RunTask(Platform::Thread::Gui, [&timedSignal, &counter, this]() {
GetPlatform().RunTask(Platform::Thread::Gui, [&timedSignal, &counter, this]()
{
InitRoutingSession();
Route masterRoute("dummy", kTestRoute.begin(), kTestRoute.end(), 0 /* route id */);
unique_ptr<DummyRouter> router =
make_unique<DummyRouter>(masterRoute, RouterResultCode::NoError, counter);
unique_ptr<DummyRouter> router = make_unique<DummyRouter>(masterRoute, RouterResultCode::NoError, counter);
m_session->SetRouter(std::move(router), nullptr);
m_session->SetRoutingCallbacks(
[&timedSignal](Route const &, RouterResultCode) {
LOG(LINFO, ("Ready"));
timedSignal.Signal();
},
nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
m_session->BuildRoute(Checkpoints(kTestRoute.front(), kTestRoute.back()),
RouterDelegate::kNoTimeout);
m_session->SetRoutingCallbacks([&timedSignal](Route const &, RouterResultCode)
{
LOG(LINFO, ("Ready"));
timedSignal.Signal();
}, nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */, nullptr /* removeRouteCallback */);
m_session->BuildRoute(Checkpoints(kTestRoute.front(), kTestRoute.back()), RouterDelegate::kNoTimeout);
});
// Manual check of the routeBuilding mutex to avoid spurious results.
@@ -275,20 +266,19 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestRouteRebuildingMovingA
size_t counter = 0;
TimedSignal alongTimedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [&alongTimedSignal, this, &counter]() {
GetPlatform().RunTask(Platform::Thread::Gui, [&alongTimedSignal, this, &counter]()
{
InitRoutingSession();
Route masterRoute("dummy", kTestRoute.begin(), kTestRoute.end(), 0 /* route id */);
FillSubroutesInfo(masterRoute);
unique_ptr<DummyRouter> router =
make_unique<DummyRouter>(masterRoute, RouterResultCode::NoError, counter);
unique_ptr<DummyRouter> router = make_unique<DummyRouter>(masterRoute, RouterResultCode::NoError, counter);
m_session->SetRouter(std::move(router), nullptr);
// Go along the route.
m_session->SetRoutingCallbacks(
[&alongTimedSignal](Route const &, RouterResultCode) { alongTimedSignal.Signal(); },
nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
m_session->SetRoutingCallbacks([&alongTimedSignal](Route const &, RouterResultCode) { alongTimedSignal.Signal(); },
nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
m_session->BuildRoute(Checkpoints(kTestRoute.front(), kTestRoute.back()),
RouterDelegate::RouterDelegate::kNoTimeout);
});
@@ -296,12 +286,12 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestRouteRebuildingMovingA
TEST_EQUAL(counter, 1, ());
{
SessionStateTest sessionStateTest(
{SessionState::RouteNotStarted, SessionState::OnRoute, SessionState::RouteBuilding,
SessionState::RouteNotStarted},
*m_session);
SessionStateTest sessionStateTest({SessionState::RouteNotStarted, SessionState::OnRoute,
SessionState::RouteBuilding, SessionState::RouteNotStarted},
*m_session);
TimedSignal oppositeTimedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [&oppositeTimedSignal, &info, this]() {
GetPlatform().RunTask(Platform::Thread::Gui, [&oppositeTimedSignal, &info, this]()
{
info.m_horizontalAccuracy = 0.01;
info.m_verticalAccuracy = 0.01;
info.m_longitude = 0.;
@@ -318,13 +308,11 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestRouteRebuildingMovingA
}
// Rebuild route and go in opposite direction. So initiate a route rebuilding flag.
m_session->SetRoutingCallbacks(
[&oppositeTimedSignal](Route const &, RouterResultCode) { oppositeTimedSignal.Signal(); },
nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
m_session->SetRoutingCallbacks([&oppositeTimedSignal](Route const &, RouterResultCode)
{ oppositeTimedSignal.Signal(); }, nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
{
m_session->BuildRoute(Checkpoints(kTestRoute.front(), kTestRoute.back()),
RouterDelegate::kNoTimeout);
m_session->BuildRoute(Checkpoints(kTestRoute.front(), kTestRoute.back()), RouterDelegate::kNoTimeout);
}
});
TEST(oppositeTimedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("Route was not built."));
@@ -332,7 +320,8 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestRouteRebuildingMovingA
// Going away from route to set rebuilding flag.
TimedSignal checkTimedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [&checkTimedSignal, &info, this]() {
GetPlatform().RunTask(Platform::Thread::Gui, [&checkTimedSignal, &info, this]()
{
info.m_longitude = 0.;
info.m_latitude = 1.;
info.m_speed = measurement_utils::KmphToMps(60);
@@ -345,8 +334,7 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestRouteRebuildingMovingA
TEST_EQUAL(code, SessionState::RouteNeedRebuild, ());
checkTimedSignal.Signal();
});
TEST(checkTimedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration),
("Route was not rebuilt."));
TEST(checkTimedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("Route was not rebuilt."));
}
// Test on route rebuilding when current position moving to the route starting far from the route.
@@ -357,32 +345,29 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestRouteRebuildingMovingT
size_t counter = 0;
TimedSignal alongTimedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [&alongTimedSignal, this, &counter]() {
GetPlatform().RunTask(Platform::Thread::Gui, [&alongTimedSignal, this, &counter]()
{
InitRoutingSession();
Route masterRoute("dummy", kTestRoute.begin(), kTestRoute.end(), 0 /* route id */);
FillSubroutesInfo(masterRoute);
unique_ptr<DummyRouter> router =
make_unique<DummyRouter>(masterRoute, RouterResultCode::NoError, counter);
unique_ptr<DummyRouter> router = make_unique<DummyRouter>(masterRoute, RouterResultCode::NoError, counter);
m_session->SetRouter(std::move(router), nullptr);
m_session->SetRoutingCallbacks(
[&alongTimedSignal](Route const &, RouterResultCode) { alongTimedSignal.Signal(); },
nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
m_session->BuildRoute(Checkpoints(kTestRoute.front(), kTestRoute.back()),
RouterDelegate::kNoTimeout);
m_session->SetRoutingCallbacks([&alongTimedSignal](Route const &, RouterResultCode) { alongTimedSignal.Signal(); },
nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
m_session->BuildRoute(Checkpoints(kTestRoute.front(), kTestRoute.back()), RouterDelegate::kNoTimeout);
});
TEST(alongTimedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("Route was not built."));
TEST_EQUAL(counter, 1, ());
// Going starting far from the route and moving to the route but rebuild flag still is set.
{
SessionStateTest sessionStateTest(
{SessionState::RouteNotStarted, SessionState::RouteNeedRebuild},
*m_session);
SessionStateTest sessionStateTest({SessionState::RouteNotStarted, SessionState::RouteNeedRebuild}, *m_session);
TimedSignal checkTimedSignalAway;
GetPlatform().RunTask(Platform::Thread::Gui, [&checkTimedSignalAway, &info, this]() {
GetPlatform().RunTask(Platform::Thread::Gui, [&checkTimedSignalAway, &info, this]()
{
info.m_longitude = 0.0;
info.m_latitude = 0.0;
info.m_speed = measurement_utils::KmphToMps(60);
@@ -397,8 +382,7 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestRouteRebuildingMovingT
TEST_EQUAL(code, SessionState::RouteNeedRebuild, ());
checkTimedSignalAway.Signal();
});
TEST(checkTimedSignalAway.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration),
("Route was not rebuilt."));
TEST(checkTimedSignalAway.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("Route was not rebuilt."));
}
}
@@ -408,27 +392,26 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestFollowRouteFlagPersist
size_t counter = 0;
TimedSignal alongTimedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [&alongTimedSignal, this, &counter]() {
GetPlatform().RunTask(Platform::Thread::Gui, [&alongTimedSignal, this, &counter]()
{
InitRoutingSession();
Route masterRoute("dummy", kTestRoute.begin(), kTestRoute.end(), 0 /* route id */);
FillSubroutesInfo(masterRoute, kTestTurns);
unique_ptr<DummyRouter> router =
make_unique<DummyRouter>(masterRoute, RouterResultCode::NoError, counter);
unique_ptr<DummyRouter> router = make_unique<DummyRouter>(masterRoute, RouterResultCode::NoError, counter);
m_session->SetRouter(std::move(router), nullptr);
// Go along the route.
m_session->SetRoutingCallbacks(
[&alongTimedSignal](Route const &, RouterResultCode) { alongTimedSignal.Signal(); },
nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
m_session->BuildRoute(Checkpoints(kTestRoute.front(), kTestRoute.back()),
RouterDelegate::kNoTimeout);
m_session->SetRoutingCallbacks([&alongTimedSignal](Route const &, RouterResultCode) { alongTimedSignal.Signal(); },
nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
m_session->BuildRoute(Checkpoints(kTestRoute.front(), kTestRoute.back()), RouterDelegate::kNoTimeout);
});
TEST(alongTimedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("Route was not built."));
TEST_EQUAL(m_onNewTurnCallbackCounter, 0, ());
TimedSignal oppositeTimedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [&oppositeTimedSignal, &info, this, &counter]() {
GetPlatform().RunTask(Platform::Thread::Gui, [&oppositeTimedSignal, &info, this, &counter]()
{
TEST(!m_session->IsFollowing(), ());
m_session->EnableFollowMode();
TEST(m_session->IsFollowing(), ());
@@ -447,18 +430,17 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestFollowRouteFlagPersist
TEST_EQUAL(counter, 1, ());
// Rebuild route and go in opposite direction. So initiate a route rebuilding flag.
m_session->SetRoutingCallbacks(
[&oppositeTimedSignal](Route const &, RouterResultCode) { oppositeTimedSignal.Signal(); },
nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
m_session->BuildRoute(Checkpoints(kTestRoute.front(), kTestRoute.back()),
RouterDelegate::kNoTimeout);
m_session->SetRoutingCallbacks([&oppositeTimedSignal](Route const &, RouterResultCode)
{ oppositeTimedSignal.Signal(); }, nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
m_session->BuildRoute(Checkpoints(kTestRoute.front(), kTestRoute.back()), RouterDelegate::kNoTimeout);
});
TEST(oppositeTimedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("Route was not built."));
TEST_EQUAL(m_onNewTurnCallbackCounter, 1, ());
TimedSignal rebuildTimedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [&rebuildTimedSignal, &info, this] {
GetPlatform().RunTask(Platform::Thread::Gui, [&rebuildTimedSignal, &info, this]
{
// Manual route building resets the following flag.
TEST(!m_session->IsFollowing(), ());
m_session->EnableFollowMode();
@@ -475,17 +457,16 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestFollowRouteFlagPersist
TEST_EQUAL(code, SessionState::RouteNeedRebuild, ());
TEST(m_session->IsFollowing(), ());
m_session->RebuildRoute(
kTestRoute.front(),
[&rebuildTimedSignal](Route const &, RouterResultCode) { rebuildTimedSignal.Signal(); },
nullptr /* needMoreMapsCallback */, nullptr /* removeRouteCallback */, RouterDelegate::kNoTimeout,
SessionState::RouteBuilding, false /* adjust */);
m_session->RebuildRoute(kTestRoute.front(), [&rebuildTimedSignal](Route const &, RouterResultCode)
{ rebuildTimedSignal.Signal(); }, nullptr /* needMoreMapsCallback */, nullptr /* removeRouteCallback */,
RouterDelegate::kNoTimeout, SessionState::RouteBuilding, false /* adjust */);
});
TEST(rebuildTimedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("Route was not built."));
TEST_EQUAL(m_onNewTurnCallbackCounter, 1, ());
TimedSignal checkTimedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [&checkTimedSignal, this] {
GetPlatform().RunTask(Platform::Thread::Gui, [&checkTimedSignal, this]
{
TEST(m_session->IsFollowing(), ());
checkTimedSignal.Signal();
});
@@ -496,30 +477,29 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestFollowRouteFlagPersist
UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestFollowRoutePercentTest)
{
TimedSignal alongTimedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [&alongTimedSignal, this]() {
GetPlatform().RunTask(Platform::Thread::Gui, [&alongTimedSignal, this]()
{
InitRoutingSession();
Route masterRoute("dummy", kTestRoute.begin(), kTestRoute.end(), 0 /* route id */);
FillSubroutesInfo(masterRoute);
size_t counter = 0;
unique_ptr<DummyRouter> router =
make_unique<DummyRouter>(masterRoute, RouterResultCode::NoError, counter);
unique_ptr<DummyRouter> router = make_unique<DummyRouter>(masterRoute, RouterResultCode::NoError, counter);
m_session->SetRouter(std::move(router), nullptr);
// Get completion percent of unexisted route.
TEST_EQUAL(m_session->GetCompletionPercent(), 0, (m_session->GetCompletionPercent()));
// Go along the route.
m_session->SetRoutingCallbacks(
[&alongTimedSignal](Route const &, RouterResultCode) { alongTimedSignal.Signal(); },
nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
m_session->BuildRoute(Checkpoints(kTestRoute.front(), kTestRoute.back()),
RouterDelegate::kNoTimeout);
m_session->SetRoutingCallbacks([&alongTimedSignal](Route const &, RouterResultCode) { alongTimedSignal.Signal(); },
nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
m_session->BuildRoute(Checkpoints(kTestRoute.front(), kTestRoute.back()), RouterDelegate::kNoTimeout);
});
TEST(alongTimedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("Route was not built."));
TimedSignal checkTimedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [&checkTimedSignal, this] {
GetPlatform().RunTask(Platform::Thread::Gui, [&checkTimedSignal, this]
{
// Get completion percent of unstarted route.
TEST_EQUAL(m_session->GetCompletionPercent(), 0, (m_session->GetCompletionPercent()));
@@ -531,30 +511,25 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestFollowRoutePercentTest
info.m_longitude = 0.;
info.m_latitude = 1.;
m_session->OnLocationPositionChanged(info);
TEST(AlmostEqualAbs(m_session->GetCompletionPercent(), 0., 0.5),
(m_session->GetCompletionPercent()));
TEST(AlmostEqualAbs(m_session->GetCompletionPercent(), 0., 0.5), (m_session->GetCompletionPercent()));
info.m_longitude = 0.;
info.m_latitude = 2.;
m_session->OnLocationPositionChanged(info);
TEST(AlmostEqualAbs(m_session->GetCompletionPercent(), 33.3, 0.5),
(m_session->GetCompletionPercent()));
TEST(AlmostEqualAbs(m_session->GetCompletionPercent(), 33.3, 0.5), (m_session->GetCompletionPercent()));
info.m_longitude = 0.;
info.m_latitude = 3.;
m_session->OnLocationPositionChanged(info);
TEST(AlmostEqualAbs(m_session->GetCompletionPercent(), 66.6, 0.5),
(m_session->GetCompletionPercent()));
TEST(AlmostEqualAbs(m_session->GetCompletionPercent(), 66.6, 0.5), (m_session->GetCompletionPercent()));
info.m_longitude = 0.;
info.m_latitude = 3.99;
m_session->OnLocationPositionChanged(info);
TEST(AlmostEqualAbs(m_session->GetCompletionPercent(), 100., 0.5),
(m_session->GetCompletionPercent()));
TEST(AlmostEqualAbs(m_session->GetCompletionPercent(), 100., 0.5), (m_session->GetCompletionPercent()));
checkTimedSignal.Signal();
});
TEST(checkTimedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration),
("Route checking timeout."));
TEST(checkTimedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("Route checking timeout."));
}
UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestRouteRebuildingError)
@@ -562,44 +537,40 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestRouteRebuildingError)
vector<m2::PointD> const kRoute = {{0.0, 0.001}, {0.0, 0.002}, {0.0, 0.003}, {0.0, 0.004}};
// Creation RoutingSession.
TimedSignal createTimedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [this, &kRoute, &createTimedSignal]() {
GetPlatform().RunTask(Platform::Thread::Gui, [this, &kRoute, &createTimedSignal]()
{
InitRoutingSession();
unique_ptr<ReturnCodesRouter> router = make_unique<ReturnCodesRouter>(initializer_list<
RouterResultCode>{RouterResultCode::NoError, RouterResultCode::InternalError}, kRoute);
unique_ptr<ReturnCodesRouter> router = make_unique<ReturnCodesRouter>(
initializer_list<RouterResultCode>{RouterResultCode::NoError, RouterResultCode::InternalError}, kRoute);
m_session->SetRouter(std::move(router), nullptr);
createTimedSignal.Signal();
});
TEST(createTimedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration),
("RouteSession was not created."));
TEST(createTimedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("RouteSession was not created."));
// Building a route.
{
SessionStateTest sessionStateTest(
{SessionState::NoValidRoute, SessionState::RouteBuilding, SessionState::RouteNotStarted},
*m_session);
{SessionState::NoValidRoute, SessionState::RouteBuilding, SessionState::RouteNotStarted}, *m_session);
TimedSignal buildTimedSignal;
GetPlatform().RunTask(Platform::Thread::Gui, [this, &kRoute, &buildTimedSignal]() {
m_session->SetRoutingCallbacks(
[&buildTimedSignal](Route const &, RouterResultCode) { buildTimedSignal.Signal(); },
nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
GetPlatform().RunTask(Platform::Thread::Gui, [this, &kRoute, &buildTimedSignal]()
{
m_session->SetRoutingCallbacks([&buildTimedSignal](Route const &, RouterResultCode)
{ buildTimedSignal.Signal(); }, nullptr /* rebuildReadyCallback */, nullptr /* needMoreMapsCallback */,
nullptr /* removeRouteCallback */);
m_session->BuildRoute(Checkpoints(kRoute.front(), kRoute.back()),
RouterDelegate::kNoTimeout);
m_session->BuildRoute(Checkpoints(kRoute.front(), kRoute.back()), RouterDelegate::kNoTimeout);
});
TEST(buildTimedSignal
.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("Route was not built."));
TEST(buildTimedSignal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("Route was not built."));
}
location::GpsInfo info;
info.m_horizontalAccuracy = 5.0; // meters
info.m_verticalAccuracy = 5.0; // meters
info.m_horizontalAccuracy = 5.0; // meters
info.m_verticalAccuracy = 5.0; // meters
info.m_longitude = 0.0;
// Moving along route.
{
SessionStateTest sessionStateTest({SessionState::RouteNotStarted, SessionState::OnRoute},
*m_session);
SessionStateTest sessionStateTest({SessionState::RouteNotStarted, SessionState::OnRoute}, *m_session);
vector<double> const latitudes = {0.001, 0.0015, 0.002};
TestMovingByUpdatingLat(sessionStateTest, latitudes, info, *m_session);
}
@@ -609,8 +580,7 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestRouteRebuildingError)
// Continue moving along the route.
{
SessionStateTest sessionStateTest({SessionState::RouteNeedRebuild, SessionState::OnRoute},
*m_session);
SessionStateTest sessionStateTest({SessionState::RouteNeedRebuild, SessionState::OnRoute}, *m_session);
vector<double> const latitudes = {0.002, 0.0025, 0.003};
TestMovingByUpdatingLat(sessionStateTest, latitudes, info, *m_session);
}
@@ -620,22 +590,20 @@ UNIT_CLASS_TEST(AsyncGuiThreadTestWithRoutingSession, TestRouteRebuildingError)
// In this case the navigation is continued based on the former route.
TestLeavingRoute(*m_session, info);
{
SessionStateTest sessionStateTest(
{SessionState::RouteNeedRebuild, SessionState::RouteRebuilding}, *m_session);
SessionStateTest sessionStateTest({SessionState::RouteNeedRebuild, SessionState::RouteRebuilding}, *m_session);
TimedSignal signal;
GetPlatform().RunTask(Platform::Thread::Gui, [this, &signal]() {
GetPlatform().RunTask(Platform::Thread::Gui, [this, &signal]()
{
m_session->SetState(SessionState::RouteRebuilding);
signal.Signal();
});
TEST(signal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration),
("State was not set."));
TEST(signal.WaitUntil(steady_clock::now() + kRouteBuildingMaxDuration), ("State was not set."));
}
// Continue moving along the route again.
{
// Test on state is not changed.
SessionStateTest sessionStateTest({SessionState::RouteRebuilding, SessionState::OnRoute},
*m_session);
SessionStateTest sessionStateTest({SessionState::RouteRebuilding, SessionState::OnRoute}, *m_session);
vector<double> const latitudes = {0.003, 0.0035, 0.004};
TestMovingByUpdatingLat(sessionStateTest, latitudes, info, *m_session);
}

View File

@@ -2,12 +2,12 @@
#include "routing/speed_camera_ser_des.hpp"
#include "platform/platform_tests_support/scoped_file.hpp"
#include "platform/platform_tests_support/scoped_dir.hpp"
#include "platform/platform_tests_support/scoped_file.hpp"
#include "coding/files_container.hpp"
#include "coding/file_reader.hpp"
#include "coding/file_writer.hpp"
#include "coding/files_container.hpp"
#include "base/assert.hpp"
#include "base/file_name_utils.hpp"

View File

@@ -11,8 +11,8 @@ void AsyncGuiThreadTestWithRoutingSession::InitRoutingSession()
}
void RouteSegmentsFrom(std::vector<Segment> const & segments, std::vector<m2::PointD> const & path,
std::vector<turns::TurnItem> const & turns, std::vector<RouteSegment::RoadNameInfo> const & names,
std::vector<RouteSegment> & routeSegments)
std::vector<turns::TurnItem> const & turns,
std::vector<RouteSegment::RoadNameInfo> const & names, std::vector<RouteSegment> & routeSegments)
{
size_t size = segments.size();
if (size == 0)
@@ -31,7 +31,7 @@ void RouteSegmentsFrom(std::vector<Segment> const & segments, std::vector<m2::Po
{
geometry::PointWithAltitude point;
if (path.size() > 0)
point = geometry::PointWithAltitude(path[i+1], geometry::kDefaultAltitudeMeters);
point = geometry::PointWithAltitude(path[i + 1], geometry::kDefaultAltitudeMeters);
Segment segment({0, 0, 0, true});
if (segments.size() > 0)
segment = segments[i];

View File

@@ -23,6 +23,7 @@ public:
};
void RouteSegmentsFrom(std::vector<Segment> const & segments, std::vector<m2::PointD> const & path,
std::vector<turns::TurnItem> const & turns, std::vector<RouteSegment::RoadNameInfo> const & names,
std::vector<turns::TurnItem> const & turns,
std::vector<RouteSegment::RoadNameInfo> const & names,
std::vector<RouteSegment> & routeSegments);
} // namespace routing

View File

@@ -2,13 +2,13 @@
#include "routing/routing_tests/tools.hpp"
#include "routing/car_directions.hpp"
#include "routing/loaded_path_segment.hpp"
#include "routing/route.hpp"
#include "routing/routing_result_graph.hpp"
#include "routing/turns.hpp"
#include "routing/turns_generator_utils.hpp"
#include "routing/turns_generator.hpp"
#include "routing/car_directions.hpp"
#include "routing/turns_generator_utils.hpp"
#include "indexer/ftypes_matcher.hpp"
@@ -36,8 +36,8 @@ public:
TUnpackedPathSegments const & GetSegments() const override { return m_segments; }
void GetPossibleTurns(SegmentRange const & segmentRange, m2::PointD const & junctionPoint,
size_t & ingoingCount, TurnCandidates & outgoingTurns) const override
void GetPossibleTurns(SegmentRange const & segmentRange, m2::PointD const & junctionPoint, size_t & ingoingCount,
TurnCandidates & outgoingTurns) const override
{
outgoingTurns.candidates.emplace_back(0.0, Segment(), ftypes::HighwayClass::Tertiary, false);
outgoingTurns.isCandidatesAngleValid = false;
@@ -126,10 +126,8 @@ UNIT_TEST(TestParseLanes)
{
vector<SingleLaneInfo> result;
TEST(ParseLanes("through|through|through|through;right", result), ());
vector<SingleLaneInfo> const expected1 = {{LaneWay::Through},
{LaneWay::Through},
{LaneWay::Through},
{LaneWay::Through, LaneWay::Right}};
vector<SingleLaneInfo> const expected1 = {
{LaneWay::Through}, {LaneWay::Through}, {LaneWay::Through}, {LaneWay::Through, LaneWay::Right}};
TEST_EQUAL(result, expected1, ());
TEST(ParseLanes("left|left;through|through|through", result), ());
@@ -138,8 +136,7 @@ UNIT_TEST(TestParseLanes)
TEST_EQUAL(result, expected2, ());
TEST(ParseLanes("left|through|through", result), ());
vector<SingleLaneInfo> const expected3 = {
{LaneWay::Left}, {LaneWay::Through}, {LaneWay::Through}};
vector<SingleLaneInfo> const expected3 = {{LaneWay::Left}, {LaneWay::Through}, {LaneWay::Through}};
TEST_EQUAL(result, expected3, ());
TEST(ParseLanes("left|le ft| through|through | right", result), ());
@@ -153,12 +150,11 @@ UNIT_TEST(TestParseLanes)
TEST_EQUAL(result, expected5, ());
TEST(ParseLanes("left|Left|through|througH|through;right;sharp_rIght", result), ());
vector<SingleLaneInfo> const expected6 = {
{LaneWay::Left},
{LaneWay::Left},
{LaneWay::Through},
{LaneWay::Through},
{LaneWay::Through, LaneWay::Right, LaneWay::SharpRight}};
vector<SingleLaneInfo> const expected6 = {{LaneWay::Left},
{LaneWay::Left},
{LaneWay::Through},
{LaneWay::Through},
{LaneWay::Through, LaneWay::Right, LaneWay::SharpRight}};
TEST_EQUAL(result, expected6, ());
TEST(!ParseLanes("left|Leftt|through|througH|right", result), ());
@@ -176,14 +172,8 @@ UNIT_TEST(TestParseLanes)
TEST_EQUAL(result, expected7, ());
TEST(ParseLanes("|||||slight_right", result), ());
vector<SingleLaneInfo> const expected8 = {
{LaneWay::None},
{LaneWay::None},
{LaneWay::None},
{LaneWay::None},
{LaneWay::None},
{LaneWay::SlightRight}
};
vector<SingleLaneInfo> const expected8 = {{LaneWay::None}, {LaneWay::None}, {LaneWay::None},
{LaneWay::None}, {LaneWay::None}, {LaneWay::SlightRight}};
TEST_EQUAL(result, expected8, ());
}
@@ -195,46 +185,36 @@ UNIT_TEST(TestFixupTurns)
mercator::MetersToXY(kSquareCenterLonLat.x, kSquareCenterLonLat.y, kHalfSquareSideMeters);
{
// Removing a turn in case staying on a roundabout.
vector<m2::PointD> const pointsMerc1 =
{{kSquareNearZero.minX(), kSquareNearZero.minY()},
{kSquareNearZero.minX(), kSquareNearZero.minY()},
{kSquareNearZero.maxX(), kSquareNearZero.maxY()},
{kSquareNearZero.maxX(), kSquareNearZero.minY()}};
vector<m2::PointD> const pointsMerc1 = {{kSquareNearZero.minX(), kSquareNearZero.minY()},
{kSquareNearZero.minX(), kSquareNearZero.minY()},
{kSquareNearZero.maxX(), kSquareNearZero.maxY()},
{kSquareNearZero.maxX(), kSquareNearZero.minY()}};
// The constructor TurnItem(uint32_t idx, CarDirection t, uint32_t exitNum = 0)
// is used for initialization of vector<TurnItem> below.
vector<turns::TurnItem> turnsDir1 =
{{1, CarDirection::EnterRoundAbout},
{2, CarDirection::StayOnRoundAbout},
{3, CarDirection::LeaveRoundAbout}};
vector<turns::TurnItem> turnsDir1 = {
{1, CarDirection::EnterRoundAbout}, {2, CarDirection::StayOnRoundAbout}, {3, CarDirection::LeaveRoundAbout}};
vector<RouteSegment> routeSegments;
RouteSegmentsFrom({}, pointsMerc1, turnsDir1, {}, routeSegments);
FixupCarTurns(routeSegments);
vector<turns::TurnItem> const expectedTurnDir1 =
{{1, CarDirection::EnterRoundAbout, 2},
{2, CarDirection::None, 0},
{3, CarDirection::LeaveRoundAbout, 2}};
vector<turns::TurnItem> const expectedTurnDir1 = {
{1, CarDirection::EnterRoundAbout, 2}, {2, CarDirection::None, 0}, {3, CarDirection::LeaveRoundAbout, 2}};
TEST_EQUAL(routeSegments[0].GetTurn(), expectedTurnDir1[0], ());
TEST_EQUAL(routeSegments[1].GetTurn(), expectedTurnDir1[1], ());
TEST_EQUAL(routeSegments[2].GetTurn(), expectedTurnDir1[2], ());
}
{
// Merging turns which are close to each other.
vector<m2::PointD> const pointsMerc2 =
{{kSquareNearZero.minX(), kSquareNearZero.minY()},
{kSquareNearZero.minX(), kSquareNearZero.minY()},
{kSquareCenterLonLat.x, kSquareCenterLonLat.y},
{kSquareNearZero.maxX(), kSquareNearZero.maxY()}};
vector<turns::TurnItem> turnsDir2 =
{{1, CarDirection::None},
{2, CarDirection::GoStraight},
{3, CarDirection::TurnLeft}};
vector<m2::PointD> const pointsMerc2 = {{kSquareNearZero.minX(), kSquareNearZero.minY()},
{kSquareNearZero.minX(), kSquareNearZero.minY()},
{kSquareCenterLonLat.x, kSquareCenterLonLat.y},
{kSquareNearZero.maxX(), kSquareNearZero.maxY()}};
vector<turns::TurnItem> turnsDir2 = {
{1, CarDirection::None}, {2, CarDirection::GoStraight}, {3, CarDirection::TurnLeft}};
vector<RouteSegment> routeSegments2;
RouteSegmentsFrom({}, pointsMerc2, turnsDir2, {}, routeSegments2);
FixupCarTurns(routeSegments2);
vector<turns::TurnItem> const expectedTurnDir2 =
{{1, CarDirection::None},
{2, CarDirection::None},
{3, CarDirection::TurnLeft}};
vector<turns::TurnItem> const expectedTurnDir2 = {
{1, CarDirection::None}, {2, CarDirection::None}, {3, CarDirection::TurnLeft}};
TEST_EQUAL(routeSegments2[0].GetTurn(), expectedTurnDir2[0], ());
TEST_EQUAL(routeSegments2[1].GetTurn(), expectedTurnDir2[1], ());
TEST_EQUAL(routeSegments2[2].GetTurn(), expectedTurnDir2[2], ());
@@ -246,14 +226,12 @@ UNIT_TEST(TestFixupTurns)
{kSquareNearZero.minX(), kSquareNearZero.maxY()},
{kSquareNearZero.maxX(), kSquareNearZero.maxY()},
};
vector<turns::TurnItem> turnsDir3 = {{1, CarDirection::None},
{2, CarDirection::TurnRight}};
vector<turns::TurnItem> turnsDir3 = {{1, CarDirection::None}, {2, CarDirection::TurnRight}};
vector<RouteSegment> routeSegments3;
RouteSegmentsFrom({}, {}, turnsDir3, {}, routeSegments3);
FixupCarTurns(routeSegments3);
vector<turns::TurnItem> const expectedTurnDir3 = {{1, CarDirection::None},
{2, CarDirection::TurnRight}};
vector<turns::TurnItem> const expectedTurnDir3 = {{1, CarDirection::None}, {2, CarDirection::TurnRight}};
TEST_EQUAL(routeSegments3[0].GetTurn(), expectedTurnDir3[0], ());
TEST_EQUAL(routeSegments3[1].GetTurn(), expectedTurnDir3[1], ());
@@ -295,17 +273,15 @@ UNIT_TEST(TestIsLaneWayConformedTurnDirectionApproximately)
TEST(!IsLaneWayConformedTurnDirectionApproximately(LaneWay::SharpRight, CarDirection::UTurnRight), ());
TEST(!IsLaneWayConformedTurnDirection(LaneWay::Through, CarDirection::ReachedYourDestination), ());
TEST(!IsLaneWayConformedTurnDirectionApproximately(LaneWay::Through, CarDirection::TurnRight), ());
TEST(!IsLaneWayConformedTurnDirectionApproximately(LaneWay::SlightRight,
CarDirection::TurnSharpLeft), ());
TEST(!IsLaneWayConformedTurnDirectionApproximately(LaneWay::SlightRight, CarDirection::TurnSharpLeft), ());
}
UNIT_TEST(TestAddingActiveLaneInformation)
{
vector<turns::TurnItem> turns =
{{1, CarDirection::GoStraight},
{2, CarDirection::TurnLeft},
{3, CarDirection::TurnRight},
{4, CarDirection::ReachedYourDestination}};
vector<turns::TurnItem> turns = {{1, CarDirection::GoStraight},
{2, CarDirection::TurnLeft},
{3, CarDirection::TurnRight},
{4, CarDirection::ReachedYourDestination}};
turns[0].m_lanes.push_back({LaneWay::Left, LaneWay::Through});
turns[0].m_lanes.push_back({LaneWay::Right});
@@ -400,51 +376,41 @@ UNIT_TEST(TestCheckUTurnOnRoute)
pathSegments[0].m_onRoundabout = false;
pathSegments[0].m_isLink = false;
pathSegments[0].m_path = {{{0, 0}, 0}, {{0, 1}, 0}};
pathSegments[0].m_segmentRange = SegmentRange(FeatureID(), 0 /* start seg id */, 1 /* end seg id */,
true /* forward */,
pathSegments[0].m_path.front().GetPoint(),
pathSegments[0].m_path.back().GetPoint());
pathSegments[0].m_segmentRange =
SegmentRange(FeatureID(), 0 /* start seg id */, 1 /* end seg id */, true /* forward */,
pathSegments[0].m_path.front().GetPoint(), pathSegments[0].m_path.back().GetPoint());
pathSegments[1] = pathSegments[0];
pathSegments[1].m_segmentRange = SegmentRange(FeatureID(), 1 /* start seg id */, 2 /* end seg id */,
true /* forward */,
pathSegments[1].m_path.front().GetPoint(),
pathSegments[1].m_path.back().GetPoint());
pathSegments[1].m_segmentRange =
SegmentRange(FeatureID(), 1 /* start seg id */, 2 /* end seg id */, true /* forward */,
pathSegments[1].m_path.front().GetPoint(), pathSegments[1].m_path.back().GetPoint());
pathSegments[1].m_path = {{{0, 1}, 0}, {{0, 0}, 0}};
pathSegments[2] = pathSegments[0];
pathSegments[2].m_segmentRange = SegmentRange(FeatureID(), 2 /* start seg id */, 3 /* end seg id */,
true /* forward */,
pathSegments[2].m_path.front().GetPoint(),
pathSegments[2].m_path.back().GetPoint());
pathSegments[2].m_segmentRange =
SegmentRange(FeatureID(), 2 /* start seg id */, 3 /* end seg id */, true /* forward */,
pathSegments[2].m_path.front().GetPoint(), pathSegments[2].m_path.back().GetPoint());
pathSegments[2].m_path = {{{0, 0}, 0}, {{0, 1}, 0}};
pathSegments[3] = pathSegments[0];
pathSegments[3].m_segmentRange = SegmentRange(FeatureID(), 3 /* start seg id */, 4 /* end seg id */,
true /* forward */,
pathSegments[3].m_path.front().GetPoint(),
pathSegments[3].m_path.back().GetPoint());
pathSegments[3].m_segmentRange =
SegmentRange(FeatureID(), 3 /* start seg id */, 4 /* end seg id */, true /* forward */,
pathSegments[3].m_path.front().GetPoint(), pathSegments[3].m_path.back().GetPoint());
pathSegments[3].m_path.clear();
RoutingResultTest resultTest(pathSegments);
RoutingSettings const vehicleSettings = GetRoutingSettings(VehicleType::Car);
// Zigzag test.
TurnItem turn1;
TEST_EQUAL(CheckUTurnOnRoute(resultTest, 1 /* outgoingSegmentIndex */, NumMwmIds(),
vehicleSettings, turn1),
1, ());
TEST_EQUAL(CheckUTurnOnRoute(resultTest, 1 /* outgoingSegmentIndex */, NumMwmIds(), vehicleSettings, turn1), 1, ());
TEST_EQUAL(turn1.m_turn, CarDirection::UTurnLeft, ());
TurnItem turn2;
TEST_EQUAL(CheckUTurnOnRoute(resultTest, 2 /* outgoingSegmentIndex */, NumMwmIds(),
vehicleSettings, turn2),
1, ());
TEST_EQUAL(CheckUTurnOnRoute(resultTest, 2 /* outgoingSegmentIndex */, NumMwmIds(), vehicleSettings, turn2), 1, ());
TEST_EQUAL(turn2.m_turn, CarDirection::UTurnLeft, ());
// Empty path test.
TurnItem turn3;
TEST_EQUAL(CheckUTurnOnRoute(resultTest, 3 /* outgoingSegmentIndex */, NumMwmIds(),
vehicleSettings, turn3),
0, ());
TEST_EQUAL(CheckUTurnOnRoute(resultTest, 3 /* outgoingSegmentIndex */, NumMwmIds(), vehicleSettings, turn3), 0, ());
}
UNIT_TEST(GetNextRoutePointIndex)
@@ -457,47 +423,47 @@ UNIT_TEST(GetNextRoutePointIndex)
RoutePointIndex nextIndex;
// Forward direction.
TEST(GetNextRoutePointIndex(resultTest,
RoutePointIndex({0 /* m_segmentIndex */, 0 /* m_pathIndex */}),
NumMwmIds(), true /* forward */, nextIndex), ());
TEST(GetNextRoutePointIndex(resultTest, RoutePointIndex({0 /* m_segmentIndex */, 0 /* m_pathIndex */}), NumMwmIds(),
true /* forward */, nextIndex),
());
TEST_EQUAL(nextIndex, RoutePointIndex({0 /* m_segmentIndex */, 1 /* m_pathIndex */}), ());
TEST(GetNextRoutePointIndex(resultTest,
RoutePointIndex({0 /* m_segmentIndex */, 1 /* m_pathIndex */}),
NumMwmIds(), true /* forward */, nextIndex), ());
TEST(GetNextRoutePointIndex(resultTest, RoutePointIndex({0 /* m_segmentIndex */, 1 /* m_pathIndex */}), NumMwmIds(),
true /* forward */, nextIndex),
());
TEST_EQUAL(nextIndex, RoutePointIndex({0 /* m_segmentIndex */, 2 /* m_pathIndex */}), ());
// Trying to get next item after the last item of the first segment.
// False because of too sharp turn angle.
TEST(!GetNextRoutePointIndex(resultTest,
RoutePointIndex({0 /* m_segmentIndex */, 2 /* m_pathIndex */}),
NumMwmIds(), true /* forward */, nextIndex), ());
TEST(!GetNextRoutePointIndex(resultTest, RoutePointIndex({0 /* m_segmentIndex */, 2 /* m_pathIndex */}), NumMwmIds(),
true /* forward */, nextIndex),
());
// Trying to get point about the end of the route.
TEST(!GetNextRoutePointIndex(resultTest,
RoutePointIndex({1 /* m_segmentIndex */, 1 /* m_pathIndex */}),
NumMwmIds(), true /* forward */, nextIndex), ());
TEST(!GetNextRoutePointIndex(resultTest, RoutePointIndex({1 /* m_segmentIndex */, 1 /* m_pathIndex */}), NumMwmIds(),
true /* forward */, nextIndex),
());
// Backward direction.
// Moving in backward direction it's possible to get index of the first item of a segment.
TEST(GetNextRoutePointIndex(resultTest,
RoutePointIndex({1 /* m_segmentIndex */, 1 /* m_pathIndex */}),
NumMwmIds(), false /* forward */, nextIndex), ());
TEST(GetNextRoutePointIndex(resultTest, RoutePointIndex({1 /* m_segmentIndex */, 1 /* m_pathIndex */}), NumMwmIds(),
false /* forward */, nextIndex),
());
TEST_EQUAL(nextIndex, RoutePointIndex({1 /* m_segmentIndex */, 0 /* m_pathIndex */}), ());
TEST(GetNextRoutePointIndex(resultTest,
RoutePointIndex({0 /* m_segmentIndex */, 2 /* m_pathIndex */}),
NumMwmIds(), false /* forward */, nextIndex), ());
TEST(GetNextRoutePointIndex(resultTest, RoutePointIndex({0 /* m_segmentIndex */, 2 /* m_pathIndex */}), NumMwmIds(),
false /* forward */, nextIndex),
());
TEST_EQUAL(nextIndex, RoutePointIndex({0 /* m_segmentIndex */, 1 /* m_pathIndex */}), ());
TEST(GetNextRoutePointIndex(resultTest,
RoutePointIndex({0 /* m_segmentIndex */, 1 /* m_pathIndex */}),
NumMwmIds(), false /* forward */, nextIndex), ());
TEST(GetNextRoutePointIndex(resultTest, RoutePointIndex({0 /* m_segmentIndex */, 1 /* m_pathIndex */}), NumMwmIds(),
false /* forward */, nextIndex),
());
TEST_EQUAL(nextIndex, RoutePointIndex({0 /* m_segmentIndex */, 0 /* m_pathIndex */}), ());
// Trying to get point before the beginning.
TEST(!GetNextRoutePointIndex(resultTest,
RoutePointIndex({0 /* m_segmentIndex */, 0 /* m_pathIndex */}),
NumMwmIds(), false /* forward */, nextIndex), ());
TEST(!GetNextRoutePointIndex(resultTest, RoutePointIndex({0 /* m_segmentIndex */, 0 /* m_pathIndex */}), NumMwmIds(),
false /* forward */, nextIndex),
());
}
} // namespace turn_generator_test
} // namespace turn_generator_test

View File

@@ -18,18 +18,15 @@ double const kEps = 1.;
UNIT_TEST(TurnNotificationSettings_MetersTest)
{
Settings const settings(20 /* notificationTimeSeconds */, 200 /* minNotificationDistanceUnits */,
700 /* maxNotificationDistanceUnits */, 5 /* m_startBeforeSeconds */,
25 /* m_minStartBeforeMeters */, 150 /* m_maxStartBeforeMeters */,
170 /* m_minDistToSayNotificationMeters */,
{100, 200, 300, 400, 500, 600, 700} /* soundedDistancesUnits */,
measurement_utils::Units::Metric /* lengthUnits */);
Settings const settings(
20 /* notificationTimeSeconds */, 200 /* minNotificationDistanceUnits */, 700 /* maxNotificationDistanceUnits */,
5 /* m_startBeforeSeconds */, 25 /* m_minStartBeforeMeters */, 150 /* m_maxStartBeforeMeters */,
170 /* m_minDistToSayNotificationMeters */, {100, 200, 300, 400, 500, 600, 700} /* soundedDistancesUnits */,
measurement_utils::Units::Metric /* lengthUnits */);
TEST(settings.IsValid(), ());
TEST(AlmostEqualAbs(
settings.ConvertMetersPerSecondToUnitsPerSecond(20.), 20., kEps), ());
TEST(AlmostEqualAbs(
settings.ConvertMetersPerSecondToUnitsPerSecond(0.), 0., kEps), ());
TEST(AlmostEqualAbs(settings.ConvertMetersPerSecondToUnitsPerSecond(20.), 20., kEps), ());
TEST(AlmostEqualAbs(settings.ConvertMetersPerSecondToUnitsPerSecond(0.), 0., kEps), ());
TEST(AlmostEqualAbs(settings.ConvertUnitsToMeters(300. /* distanceInUnits */), 300., kEps), ());
TEST_EQUAL(settings.RoundByPresetSoundedDistancesUnits(300 /* distanceInUnits */), 300, ());
TEST_EQUAL(settings.RoundByPresetSoundedDistancesUnits(0 /* distanceInUnits */), 100, ());
@@ -49,18 +46,15 @@ UNIT_TEST(TurnNotificationSettings_MetersTest)
UNIT_TEST(TurnNotificationSettings_FeetTest)
{
Settings const settings(20 /* notificationTimeSeconds */, 500 /* minNotificationDistanceUnits */,
2000 /* maxNotificationDistanceUnits */, 5 /* m_startBeforeSeconds */,
25 /* m_minStartBeforeMeters */, 150 /* m_maxStartBeforeMeters */,
170 /* m_minDistToSayNotificationMeters */,
{200, 400, 600, 800, 1000, 1500, 2000} /* soundedDistancesUnits */,
measurement_utils::Units::Imperial /* lengthUnits */);
Settings const settings(
20 /* notificationTimeSeconds */, 500 /* minNotificationDistanceUnits */, 2000 /* maxNotificationDistanceUnits */,
5 /* m_startBeforeSeconds */, 25 /* m_minStartBeforeMeters */, 150 /* m_maxStartBeforeMeters */,
170 /* m_minDistToSayNotificationMeters */, {200, 400, 600, 800, 1000, 1500, 2000} /* soundedDistancesUnits */,
measurement_utils::Units::Imperial /* lengthUnits */);
TEST(settings.IsValid(), ());
TEST(AlmostEqualAbs(
settings.ConvertMetersPerSecondToUnitsPerSecond(20.), 65., kEps), ());
TEST(AlmostEqualAbs(
settings.ConvertMetersPerSecondToUnitsPerSecond(0.), 0., kEps), ());
TEST(AlmostEqualAbs(settings.ConvertMetersPerSecondToUnitsPerSecond(20.), 65., kEps), ());
TEST(AlmostEqualAbs(settings.ConvertMetersPerSecondToUnitsPerSecond(0.), 0., kEps), ());
TEST(AlmostEqualAbs(settings.ConvertUnitsToMeters(300. /* distanceInUnits */), 91., kEps), ());
TEST_EQUAL(settings.RoundByPresetSoundedDistancesUnits(500 /* distanceInUnits */), 600, ());
TEST_EQUAL(settings.RoundByPresetSoundedDistancesUnits(0 /* distanceInUnits */), 200, ());
@@ -68,12 +62,11 @@ UNIT_TEST(TurnNotificationSettings_FeetTest)
UNIT_TEST(TurnNotificationSettings_NotValidTest)
{
Settings settings1(20 /* notificationTimeSeconds */, 500 /* minNotificationDistanceUnits */,
2000 /* maxNotificationDistanceUnits */, 5 /* m_startBeforeSeconds */,
25 /* m_minStartBeforeMeters */, 150 /* m_maxStartBeforeMeters */,
170 /* m_minDistToSayNotificationMeters */,
{200, 400, 800, 600, 1000, 1500, 2000} /* soundedDistancesUnits */,
measurement_utils::Units::Imperial /* lengthUnits */);
Settings settings1(
20 /* notificationTimeSeconds */, 500 /* minNotificationDistanceUnits */, 2000 /* maxNotificationDistanceUnits */,
5 /* m_startBeforeSeconds */, 25 /* m_minStartBeforeMeters */, 150 /* m_maxStartBeforeMeters */,
170 /* m_minDistToSayNotificationMeters */, {200, 400, 800, 600, 1000, 1500, 2000} /* soundedDistancesUnits */,
measurement_utils::Units::Imperial /* lengthUnits */);
TEST(!settings1.IsValid(), ());
Settings settings2(20 /* notificationTimeSeconds */, 5000 /* minNotificationDistanceUnits */,
@@ -231,8 +224,7 @@ UNIT_TEST(TurnsSound_MetersTwoTurnsTest)
notificationManager.GenerateTurnNotifications(turns, turnNotifications);
TEST(turnNotifications.empty(), ());
vector<TurnItemDist> turns2 = {{{11 /* idx */, CarDirection::EnterRoundAbout,
2 /* exitNum */}, 60.}};
vector<TurnItemDist> turns2 = {{{11 /* idx */, CarDirection::EnterRoundAbout, 2 /* exitNum */}, 60.}};
// Starting nearing the second turn.
notificationManager.GenerateTurnNotifications(turns2, turnNotifications);
@@ -261,8 +253,7 @@ UNIT_TEST(TurnsSound_FeetTest)
100 /* minDistToSayNotificationMeters */, measurement_utils::Units::Imperial, engShortJson,
20 /* notificationTimeSecond */, 30.0 /* speedMeterPerSecond */);
vector<TurnItemDist> turns = {{{7 /* idx */, CarDirection::EnterRoundAbout,
3 /* exitNum */}, 1000.}};
vector<TurnItemDist> turns = {{{7 /* idx */, CarDirection::EnterRoundAbout, 3 /* exitNum */}, 1000.}};
vector<string> turnNotifications;
// Starting nearing the turnItem.
@@ -356,8 +347,7 @@ UNIT_TEST(TurnsSound_ComposedTurnTest)
turnNotifications.clear();
vector<TurnItemDist> const turns2 = {{{5 /* idx */, CarDirection::TurnRight}, 620. /* m_distMeters */},
{{10 /* idx */, CarDirection::EnterRoundAbout}, 665. /* m_distMeters */}};
vector<string> const expectedNotification2 = {{"In 600 meters. Turn right."},
{"Then. Enter the roundabout."}};
vector<string> const expectedNotification2 = {{"In 600 meters. Turn right."}, {"Then. Enter the roundabout."}};
notificationManager.GenerateTurnNotifications(turns2, turnNotifications);
TEST_EQUAL(turnNotifications, expectedNotification2, ());
TEST_EQUAL(notificationManager.GetSecondTurnNotification(), CarDirection::EnterRoundAbout, ());
@@ -374,24 +364,25 @@ UNIT_TEST(TurnsSound_ComposedTurnTest)
turnNotifications.clear();
vector<TurnItemDist> const turns4 = {{{5 /* idx */, CarDirection::TurnRight}, 20. /* m_distMeters */},
{{10 /* idx */, CarDirection::EnterRoundAbout}, 220. /* m_distMeters */}};
vector<string> const expectedNotification4 = {{"Turn right."},
{"Then. In 200 meters. Enter the roundabout."}};
vector<string> const expectedNotification4 = {{"Turn right."}, {"Then. In 200 meters. Enter the roundabout."}};
notificationManager.GenerateTurnNotifications(turns4, turnNotifications);
TEST_EQUAL(turnNotifications, expectedNotification4, ());
TEST_EQUAL(notificationManager.GetSecondTurnNotification(), CarDirection::EnterRoundAbout, ());
// After the first turn.
turnNotifications.clear();
vector<TurnItemDist> const turns5 = {{{10 /* idx */, CarDirection::EnterRoundAbout}, 180. /* m_distMeters */},
{{15 /* idx */, CarDirection::ReachedYourDestination}, 1180. /* m_distMeters */}};
vector<TurnItemDist> const turns5 = {
{{10 /* idx */, CarDirection::EnterRoundAbout}, 180. /* m_distMeters */},
{{15 /* idx */, CarDirection::ReachedYourDestination}, 1180. /* m_distMeters */}};
notificationManager.GenerateTurnNotifications(turns5, turnNotifications);
TEST(turnNotifications.empty(), ());
TEST_EQUAL(notificationManager.GetSecondTurnNotification(), CarDirection::None, ());
// Just before the second turn.
turnNotifications.clear();
vector<TurnItemDist> const turns6 = {{{10 /* idx */, CarDirection::EnterRoundAbout}, 10. /* m_distMeters */},
{{15 /* idx */, CarDirection::ReachedYourDestination}, 1010. /* m_distMeters */}};
vector<TurnItemDist> const turns6 = {
{{10 /* idx */, CarDirection::EnterRoundAbout}, 10. /* m_distMeters */},
{{15 /* idx */, CarDirection::ReachedYourDestination}, 1010. /* m_distMeters */}};
vector<string> const expectedNotification6 = {{"Enter the roundabout."}};
notificationManager.GenerateTurnNotifications(turns6, turnNotifications);
TEST_EQUAL(turnNotifications, expectedNotification6, ());
@@ -421,19 +412,17 @@ UNIT_TEST(TurnsSound_RoundaboutTurnTest)
// Starting nearing the first turn.
// 1000 meters till the first turn.
vector<TurnItemDist> const turns1 = {{{5 /* idx */, CarDirection::EnterRoundAbout, 2 /* m_exitNum */},
1000. /* m_distMeters */},
{{10 /* idx */, CarDirection::LeaveRoundAbout, 2 /* m_exitNum */},
2000. /* m_distMeters */}};
vector<TurnItemDist> const turns1 = {
{{5 /* idx */, CarDirection::EnterRoundAbout, 2 /* m_exitNum */}, 1000. /* m_distMeters */},
{{10 /* idx */, CarDirection::LeaveRoundAbout, 2 /* m_exitNum */}, 2000. /* m_distMeters */}};
notificationManager.GenerateTurnNotifications(turns1, turnNotifications);
TEST(turnNotifications.empty(), ());
TEST_EQUAL(notificationManager.GetSecondTurnNotification(), CarDirection::None, ());
// 620 meters till the first turn.
vector<TurnItemDist> const turns2 = {{{5 /* idx */, CarDirection::EnterRoundAbout, 2 /* m_exitNum */},
620. /* m_distMeters */},
{{10 /* idx */, CarDirection::LeaveRoundAbout, 2 /* m_exitNum */},
1620. /* m_distMeters */}};
vector<TurnItemDist> const turns2 = {
{{5 /* idx */, CarDirection::EnterRoundAbout, 2 /* m_exitNum */}, 620. /* m_distMeters */},
{{10 /* idx */, CarDirection::LeaveRoundAbout, 2 /* m_exitNum */}, 1620. /* m_distMeters */}};
vector<string> const expectedNotification2 = {{"In 600 meters. Enter the roundabout."},
{"Then. In 1 kilometer. Take the second exit."}};
notificationManager.GenerateTurnNotifications(turns2, turnNotifications);
@@ -441,10 +430,9 @@ UNIT_TEST(TurnsSound_RoundaboutTurnTest)
TEST_EQUAL(notificationManager.GetSecondTurnNotification(), CarDirection::None, ());
// 3 meters till the first turn.
vector<TurnItemDist> const turns3 = {{{5 /* idx */, CarDirection::EnterRoundAbout, 2 /* m_exitNum */},
3. /* m_distMeters */},
{{10 /* idx */, CarDirection::LeaveRoundAbout, 2 /* m_exitNum */},
1003. /* m_distMeters */}};
vector<TurnItemDist> const turns3 = {
{{5 /* idx */, CarDirection::EnterRoundAbout, 2 /* m_exitNum */}, 3. /* m_distMeters */},
{{10 /* idx */, CarDirection::LeaveRoundAbout, 2 /* m_exitNum */}, 1003. /* m_distMeters */}};
vector<string> const expectedNotification3 = {{"Enter the roundabout."},
{"Then. In 1 kilometer. Take the second exit."}};
notificationManager.GenerateTurnNotifications(turns3, turnNotifications);
@@ -452,61 +440,54 @@ UNIT_TEST(TurnsSound_RoundaboutTurnTest)
TEST_EQUAL(notificationManager.GetSecondTurnNotification(), CarDirection::None, ());
// 900 meters till the second turn.
vector<TurnItemDist> const turns4 = {{{10 /* idx */, CarDirection::LeaveRoundAbout, 2 /* m_exitNum */},
900. /* m_distMeters */},
{{15 /* idx */, CarDirection::EnterRoundAbout, 1 /* m_exitNum */},
1900. /* m_distMeters */}};
vector<TurnItemDist> const turns4 = {
{{10 /* idx */, CarDirection::LeaveRoundAbout, 2 /* m_exitNum */}, 900. /* m_distMeters */},
{{15 /* idx */, CarDirection::EnterRoundAbout, 1 /* m_exitNum */}, 1900. /* m_distMeters */}};
notificationManager.GenerateTurnNotifications(turns4, turnNotifications);
TEST(turnNotifications.empty(), ());
TEST_EQUAL(notificationManager.GetSecondTurnNotification(), CarDirection::None, ());
// 300 meters till the second turn.
vector<TurnItemDist> const turns5 = {{{10 /* idx */, CarDirection::LeaveRoundAbout, 2 /* m_exitNum */},
300. /* m_distMeters */},
{{15 /* idx */, CarDirection::EnterRoundAbout, 1 /* m_exitNum */},
1300. /* m_distMeters */}};
vector<TurnItemDist> const turns5 = {
{{10 /* idx */, CarDirection::LeaveRoundAbout, 2 /* m_exitNum */}, 300. /* m_distMeters */},
{{15 /* idx */, CarDirection::EnterRoundAbout, 1 /* m_exitNum */}, 1300. /* m_distMeters */}};
notificationManager.GenerateTurnNotifications(turns5, turnNotifications);
TEST(turnNotifications.empty(), ());
TEST_EQUAL(notificationManager.GetSecondTurnNotification(), CarDirection::None, ());
// 3 meters till the second turn.
vector<TurnItemDist> const turns6 = {{{10 /* idx */, CarDirection::LeaveRoundAbout, 2 /* m_exitNum */},
3. /* m_distMeters */},
{{15 /* idx */, CarDirection::EnterRoundAbout, 1 /* m_exitNum */},
1003. /* m_distMeters */}};
vector<TurnItemDist> const turns6 = {
{{10 /* idx */, CarDirection::LeaveRoundAbout, 2 /* m_exitNum */}, 3. /* m_distMeters */},
{{15 /* idx */, CarDirection::EnterRoundAbout, 1 /* m_exitNum */}, 1003. /* m_distMeters */}};
vector<string> const expectedNotification6 = {{"Leave the roundabout."}};
notificationManager.GenerateTurnNotifications(turns6, turnNotifications);
TEST_EQUAL(turnNotifications, expectedNotification6, ());
TEST_EQUAL(notificationManager.GetSecondTurnNotification(), CarDirection::None, ());
// 5 meters till the third turn.
vector<TurnItemDist> const turns7 = {{{15 /* idx */, CarDirection::EnterRoundAbout, 1 /* m_exitNum */},
5. /* m_distMeters */},
{{20 /* idx */, CarDirection::LeaveRoundAbout, 1 /* m_exitNum */},
1005. /* m_distMeters */}};
vector<TurnItemDist> const turns7 = {
{{15 /* idx */, CarDirection::EnterRoundAbout, 1 /* m_exitNum */}, 5. /* m_distMeters */},
{{20 /* idx */, CarDirection::LeaveRoundAbout, 1 /* m_exitNum */}, 1005. /* m_distMeters */}};
vector<string> const expectedNotification7 = {{"Enter the roundabout."},
{"Then. In 1 kilometer. Take the first exit."}};
notificationManager.GenerateTurnNotifications(
turns7, turnNotifications); // The first notification fast forwarding.
notificationManager.GenerateTurnNotifications(turns7, turnNotifications); // The first notification fast forwarding.
notificationManager.GenerateTurnNotifications(turns7, turnNotifications);
TEST_EQUAL(turnNotifications, expectedNotification7, ());
TEST_EQUAL(notificationManager.GetSecondTurnNotification(), CarDirection::None, ());
// 900 meters till the 4th turn.
notificationManager.Reset();
vector<TurnItemDist> const turns8 = {{{25 /* idx */, CarDirection::EnterRoundAbout, 4 /* m_exitNum */},
900. /* m_distMeters */},
{{30 /* idx */, CarDirection::LeaveRoundAbout, 4 /* m_exitNum */},
1200. /* m_distMeters */}};
vector<TurnItemDist> const turns8 = {
{{25 /* idx */, CarDirection::EnterRoundAbout, 4 /* m_exitNum */}, 900. /* m_distMeters */},
{{30 /* idx */, CarDirection::LeaveRoundAbout, 4 /* m_exitNum */}, 1200. /* m_distMeters */}};
notificationManager.GenerateTurnNotifications(turns8, turnNotifications);
TEST(turnNotifications.empty(), ());
TEST_EQUAL(notificationManager.GetSecondTurnNotification(), CarDirection::None, ());
// 620 meters till the 4th turn.
vector<TurnItemDist> const turns9 = {{{25 /* idx */, CarDirection::EnterRoundAbout, 4 /* m_exitNum */},
620. /* m_distMeters */},
{{30 /* idx */, CarDirection::LeaveRoundAbout, 4 /* m_exitNum */},
665. /* m_distMeters */}};
vector<TurnItemDist> const turns9 = {
{{25 /* idx */, CarDirection::EnterRoundAbout, 4 /* m_exitNum */}, 620. /* m_distMeters */},
{{30 /* idx */, CarDirection::LeaveRoundAbout, 4 /* m_exitNum */}, 665. /* m_distMeters */}};
vector<string> const expectedNotification9 = {{"In 600 meters. Enter the roundabout."},
{"Then. Take the fourth exit."}};
notificationManager.GenerateTurnNotifications(turns9, turnNotifications);

View File

@@ -28,8 +28,8 @@ UNIT_TEST(GetDistanceTextIdMetersTest)
{
TEST_EQUAL(GetDistanceTextId({500, 0, false, CarDirection::TurnRight, Units::Metric}), "in_500_meters", ());
// Notification const notification2(500, 0, true, CarDirection::TurnRight, Units::Metric);
// TEST_EQUAL(GetDistanceTextId(notification2), "then", ());
// Notification const notification2(500, 0, true, CarDirection::TurnRight, Units::Metric);
// TEST_EQUAL(GetDistanceTextId(notification2), "then", ());
TEST_EQUAL(GetDistanceTextId({200, 0, false, CarDirection::TurnRight, Units::Metric}), "in_200_meters", ());
TEST_EQUAL(GetDistanceTextId({2000, 0, false, CarDirection::TurnRight, Units::Metric}), "in_2_kilometers", ());
@@ -43,8 +43,8 @@ UNIT_TEST(GetDistanceTextIdFeetTest)
{
TEST_EQUAL(GetDistanceTextId({500, 0, false, CarDirection::TurnRight, Units::Imperial}), "in_500_feet", ());
// Notification const notification2(500, 0, true, CarDirection::TurnRight, Units::Imperial);
// TEST_EQUAL(GetDistanceTextId(notification2), "then", ());
// Notification const notification2(500, 0, true, CarDirection::TurnRight, Units::Imperial);
// TEST_EQUAL(GetDistanceTextId(notification2), "then", ());
TEST_EQUAL(GetDistanceTextId({800, 0, false, CarDirection::TurnRight, Units::Imperial}), "in_800_feet", ());
TEST_EQUAL(GetDistanceTextId({5000, 0, false, CarDirection::TurnRight, Units::Imperial}), "in_5000_feet", ());
@@ -54,17 +54,13 @@ UNIT_TEST(GetRoundaboutTextIdTest)
{
// Notification(uint32_t distanceUnits, uint8_t exitNum, bool useThenInsteadOfDistance,
// CarDirection turnDir, ::Settings::Units lengthUnits)
Notification const notification1(500, 0, false, CarDirection::LeaveRoundAbout,
Units::Imperial);
Notification const notification1(500, 0, false, CarDirection::LeaveRoundAbout, Units::Imperial);
TEST_EQUAL(GetRoundaboutTextId(notification1), "leave_the_roundabout", ());
Notification const notification2(0, 3, true, CarDirection::LeaveRoundAbout,
Units::Imperial);
Notification const notification2(0, 3, true, CarDirection::LeaveRoundAbout, Units::Imperial);
TEST_EQUAL(GetRoundaboutTextId(notification2), "take_the_3_exit", ());
Notification const notification3(0, 7, true, CarDirection::LeaveRoundAbout,
Units::Metric);
Notification const notification3(0, 7, true, CarDirection::LeaveRoundAbout, Units::Metric);
TEST_EQUAL(GetRoundaboutTextId(notification3), "take_the_7_exit", ());
Notification const notification4(0, 15, true, CarDirection::LeaveRoundAbout,
Units::Metric);
Notification const notification4(0, 15, true, CarDirection::LeaveRoundAbout, Units::Metric);
TEST_EQUAL(GetRoundaboutTextId(notification4), "leave_the_roundabout", ());
}
@@ -72,14 +68,11 @@ UNIT_TEST(GetYouArriveTextIdTest)
{
// Notification(uint32_t distanceUnits, uint8_t exitNum, bool useThenInsteadOfDistance,
// CarDirection turnDir, ::Settings::Units lengthUnits)
Notification const notification1(500, 0, false, CarDirection::ReachedYourDestination,
Units::Imperial);
Notification const notification1(500, 0, false, CarDirection::ReachedYourDestination, Units::Imperial);
TEST_EQUAL(GetYouArriveTextId(notification1), "destination", ());
Notification const notification2(0, 0, false, CarDirection::ReachedYourDestination,
Units::Metric);
Notification const notification2(0, 0, false, CarDirection::ReachedYourDestination, Units::Metric);
TEST_EQUAL(GetYouArriveTextId(notification2), "you_have_reached_the_destination", ());
Notification const notification3(0, 0, true, CarDirection::ReachedYourDestination,
Units::Metric);
Notification const notification3(0, 0, true, CarDirection::ReachedYourDestination, Units::Metric);
TEST_EQUAL(GetYouArriveTextId(notification3), "destination", ());
}
@@ -87,20 +80,15 @@ UNIT_TEST(GetDirectionTextIdTest)
{
// Notification(uint32_t distanceUnits, uint8_t exitNum, bool useThenInsteadOfDistance,
// CarDirection turnDir, ::Settings::Units lengthUnits)
Notification const notification1(500, 0, false, CarDirection::TurnRight,
Units::Imperial);
Notification const notification1(500, 0, false, CarDirection::TurnRight, Units::Imperial);
TEST_EQUAL(GetDirectionTextId(notification1), "make_a_right_turn", ());
Notification const notification2(1000, 0, false, CarDirection::GoStraight,
Units::Metric);
Notification const notification2(1000, 0, false, CarDirection::GoStraight, Units::Metric);
TEST_EQUAL(GetDirectionTextId(notification2), "go_straight", ());
Notification const notification3(700, 0, false, CarDirection::UTurnLeft,
Units::Metric);
Notification const notification3(700, 0, false, CarDirection::UTurnLeft, Units::Metric);
TEST_EQUAL(GetDirectionTextId(notification3), "make_a_u_turn", ());
Notification const notification4(200, 0, false, CarDirection::ReachedYourDestination,
Units::Metric);
Notification const notification4(200, 0, false, CarDirection::ReachedYourDestination, Units::Metric);
TEST_EQUAL(GetDirectionTextId(notification4), "destination", ());
Notification const notification5(0, 0, false, CarDirection::ReachedYourDestination,
Units::Metric);
Notification const notification5(0, 0, false, CarDirection::ReachedYourDestination, Units::Metric);
TEST_EQUAL(GetDirectionTextId(notification5), "you_have_reached_the_destination", ());
}
@@ -129,14 +117,10 @@ UNIT_TEST(GetTtsTextTest)
GetTtsText getTtsText;
// Notification(uint32_t distanceUnits, uint8_t exitNum, bool useThenInsteadOfDistance,
// CarDirection turnDir, Settings::Units lengthUnits)
Notification const notification1(500, 0, false, CarDirection::TurnRight,
Units::Metric);
Notification const notification2(300, 0, false, CarDirection::TurnLeft,
Units::Metric);
Notification const notification3(0, 0, false, CarDirection::ReachedYourDestination,
Units::Metric);
Notification const notification4(0, 0, true, CarDirection::TurnLeft,
Units::Metric);
Notification const notification1(500, 0, false, CarDirection::TurnRight, Units::Metric);
Notification const notification2(300, 0, false, CarDirection::TurnLeft, Units::Metric);
Notification const notification3(0, 0, false, CarDirection::ReachedYourDestination, Units::Metric);
Notification const notification4(0, 0, true, CarDirection::TurnLeft, Units::Metric);
getTtsText.ForTestingSetLocaleWithJson(engShortJson, "en");
TEST_EQUAL(getTtsText.GetTurnNotification(notification1), "In 500 meters. Make a right turn.", ());
@@ -416,10 +400,8 @@ UNIT_TEST(GetAllSoundedDistMetersTest)
VecPairDist const & allSoundedDistMeters = GetAllSoundedDistMeters();
TEST(is_sorted(allSoundedDistMeters.cbegin(), allSoundedDistMeters.cend(),
[](PairDist const & p1, PairDist const & p2)
{
return p1.first < p2.first;
}), ());
[](PairDist const & p1, PairDist const & p2) { return p1.first < p2.first; }),
());
TEST_EQUAL(allSoundedDistMeters.size(), 17, ());
PairDist const expected1 = {50, "in_50_meters"};
@@ -435,10 +417,8 @@ UNIT_TEST(GetAllSoundedDistFeet)
VecPairDist const & allSoundedDistFeet = GetAllSoundedDistFeet();
TEST(is_sorted(allSoundedDistFeet.cbegin(), allSoundedDistFeet.cend(),
[](PairDist const & p1, PairDist const & p2)
{
return p1.first < p2.first;
}), ());
[](PairDist const & p1, PairDist const & p2) { return p1.first < p2.first; }),
());
TEST_EQUAL(allSoundedDistFeet.size(), 22, ());
PairDist const expected1 = {50, "in_50_feet"};
@@ -456,12 +436,10 @@ UNIT_TEST(GetSoundedDistMeters)
TEST(is_sorted(soundedDistMeters.cbegin(), soundedDistMeters.cend()), ());
// Checking that allSounded contains any element of inst.
TEST(find_first_of(soundedDistMeters.cbegin(), soundedDistMeters.cend(),
allSoundedDistMeters.cbegin(), allSoundedDistMeters.cend(),
[](uint32_t p1, PairDist const & p2)
{
return p1 == p2.first;
}) != soundedDistMeters.cend(), ());
TEST(find_first_of(soundedDistMeters.cbegin(), soundedDistMeters.cend(), allSoundedDistMeters.cbegin(),
allSoundedDistMeters.cend(),
[](uint32_t p1, PairDist const & p2) { return p1 == p2.first; }) != soundedDistMeters.cend(),
());
TEST_EQUAL(soundedDistMeters.size(), 11, ());
TEST_EQUAL(soundedDistMeters[0], 200, ());
@@ -477,10 +455,9 @@ UNIT_TEST(GetSoundedDistFeet)
TEST(is_sorted(soundedDistFeet.cbegin(), soundedDistFeet.cend()), ());
// Checking that allSounded contains any element of inst.
TEST(find_first_of(soundedDistFeet.cbegin(), soundedDistFeet.cend(), allSoundedDistFeet.cbegin(),
allSoundedDistFeet.cend(), [](uint32_t p1, PairDist const & p2)
{
return p1 == p2.first;
}) != soundedDistFeet.cend(), ());
allSoundedDistFeet.cend(),
[](uint32_t p1, PairDist const & p2) { return p1 == p2.first; }) != soundedDistFeet.cend(),
());
TEST_EQUAL(soundedDistFeet.size(), 11, ());
TEST_EQUAL(soundedDistFeet[0], 500, ());

View File

@@ -19,15 +19,11 @@ UNIT_CLASS_TEST(NoUTurnRestrictionTest, CheckNoUTurn_1)
Segment const start(kTestNumMwmId, 3 /* fId */, 0 /* segId */, true /* forward */);
Segment const finish(kTestNumMwmId, 7 /* fId */, 0 /* segId */, true /* forward */);
std::vector<m2::PointD> const expectedGeom = {
{3.0, 0.0}, {2.0, 0.0}, {1.0, 0.0}, {1.0, 1.0}, {1.0, 2.0}
};
std::vector<m2::PointD> const expectedGeom = {{3.0, 0.0}, {2.0, 0.0}, {1.0, 0.0}, {1.0, 1.0}, {1.0, 2.0}};
TestRouteGeom(start, finish, Algorithm::Result::OK, expectedGeom);
std::vector<RestrictionUTurn> noUTurnRestrictions = {
{3 /* featureId */, false /* viaIsFirstPoint */}
};
std::vector<RestrictionUTurn> noUTurnRestrictions = {{3 /* featureId */, false /* viaIsFirstPoint */}};
SetNoUTurnRestrictions(std::move(noUTurnRestrictions));
TestRouteGeom(start, finish, Algorithm::Result::NoPath, {} /* expectedGeom */);
@@ -40,19 +36,14 @@ UNIT_CLASS_TEST(NoUTurnRestrictionTest, CheckNoUTurn_2)
Segment const start(kTestNumMwmId, 2 /* fId */, 0 /* segId */, true /* forward */);
Segment const finish(kTestNumMwmId, 7 /* fId */, 0 /* segId */, true /* forward */);
std::vector<m2::PointD> const expectedGeom = {
{2.0, 0.0}, {1.0, 0.0}, {1.0, 1.0}, {1.0, 2.0}
};
std::vector<m2::PointD> const expectedGeom = {{2.0, 0.0}, {1.0, 0.0}, {1.0, 1.0}, {1.0, 2.0}};
TestRouteGeom(start, finish, Algorithm::Result::OK, expectedGeom);
std::vector<RestrictionUTurn> noUTurnRestrictions = {
{2 /* featureId */, false /* viaIsFirstPoint */}
};
std::vector<RestrictionUTurn> noUTurnRestrictions = {{2 /* featureId */, false /* viaIsFirstPoint */}};
std::vector<m2::PointD> const expectedGeomAfterRestriction = {
{2.0, 0.0}, {3.0, 0.0}, {2.0, 0.0}, {1.0, 0.0}, {1.0, 1.0}, {1.0, 2.0}
};
std::vector<m2::PointD> const expectedGeomAfterRestriction = {{2.0, 0.0}, {3.0, 0.0}, {2.0, 0.0},
{1.0, 0.0}, {1.0, 1.0}, {1.0, 2.0}};
SetNoUTurnRestrictions(std::move(noUTurnRestrictions));
TestRouteGeom(start, finish, Algorithm::Result::OK, expectedGeomAfterRestriction);
@@ -65,19 +56,14 @@ UNIT_CLASS_TEST(NoUTurnRestrictionTest, CheckNoUTurn_3)
Segment const start(kTestNumMwmId, 2 /* fId */, 0 /* segId */, false /* forward */);
Segment const finish(kTestNumMwmId, 3 /* fId */, 0 /* segId */, true /* forward */);
std::vector<m2::PointD> const expectedGeom = {
{1.0, 0.0}, {2.0, 0.0}, {3.0, 0.0}
};
std::vector<m2::PointD> const expectedGeom = {{1.0, 0.0}, {2.0, 0.0}, {3.0, 0.0}};
TestRouteGeom(start, finish, Algorithm::Result::OK, expectedGeom);
std::vector<RestrictionUTurn> noUTurnRestrictions = {
{2 /* featureId */, true /* viaIsFirstPoint */}
};
std::vector<RestrictionUTurn> noUTurnRestrictions = {{2 /* featureId */, true /* viaIsFirstPoint */}};
std::vector<m2::PointD> const expectedGeomAfterRestriction = {
{1.0, 0.0}, {1.0, -1.0}, {1.0, 0.0}, {2.0, 0.0}, {3.0, 0.0}
};
{1.0, 0.0}, {1.0, -1.0}, {1.0, 0.0}, {2.0, 0.0}, {3.0, 0.0}};
SetNoUTurnRestrictions(std::move(noUTurnRestrictions));
TestRouteGeom(start, finish, Algorithm::Result::OK, expectedGeomAfterRestriction);
@@ -90,15 +76,11 @@ UNIT_CLASS_TEST(NoUTurnRestrictionTest, CheckOnlyUTurn_1)
Segment const start(kTestNumMwmId, 2 /* fId */, 0 /* segId */, true /* forward */);
Segment const finish(kTestNumMwmId, 3 /* fId */, 0 /* segId */, true /* forward */);
std::vector<m2::PointD> const expectedGeom = {
{2.0, 0.0}, {3.0, 0.0}
};
std::vector<m2::PointD> const expectedGeom = {{2.0, 0.0}, {3.0, 0.0}};
TestRouteGeom(start, finish, Algorithm::Result::OK, expectedGeom);
std::vector<RestrictionUTurn> onlyUTurnRestrictions = {
{2 /* featureId */, false /* viaIsFirstPoint */}
};
std::vector<RestrictionUTurn> onlyUTurnRestrictions = {{2 /* featureId */, false /* viaIsFirstPoint */}};
RestrictionVec restrictionsNo;
@@ -116,15 +98,11 @@ UNIT_CLASS_TEST(NoUTurnRestrictionTest, CheckOnlyUTurn_2)
Segment const start(kTestNumMwmId, 0 /* fId */, 0 /* segId */, false /* forward */);
Segment const finish(kTestNumMwmId, 5 /* fId */, 0 /* segId */, true /* forward */);
std::vector<m2::PointD> const expectedGeom = {
{0.0, 1.0}, {1.0, 1.0}, {2.0, 2.0}, {3.0, 2.0}
};
std::vector<m2::PointD> const expectedGeom = {{0.0, 1.0}, {1.0, 1.0}, {2.0, 2.0}, {3.0, 2.0}};
TestRouteGeom(start, finish, Algorithm::Result::OK, expectedGeom);
std::vector<RestrictionUTurn> onlyUTurnRestrictions = {
{1 /* featureId */, false /* viaIsFirstPoint */}
};
std::vector<RestrictionUTurn> onlyUTurnRestrictions = {{1 /* featureId */, false /* viaIsFirstPoint */}};
RestrictionVec restrictionsNo;
@@ -132,9 +110,8 @@ UNIT_CLASS_TEST(NoUTurnRestrictionTest, CheckOnlyUTurn_2)
ConvertRestrictionsOnlyUTurnToNo(indexGraph, onlyUTurnRestrictions, restrictionsNo);
SetRestrictions(std::move(restrictionsNo));
std::vector<m2::PointD> const expectedGeomAfterRestriction = {
{0.0, 1.0}, {-1.0, 1.0}, {-1.0, 2.0}, {0.0, 2.0}, {1.0, 2.0}, {2.0, 2.0}, {3.0, 2.0}
};
std::vector<m2::PointD> const expectedGeomAfterRestriction = {{0.0, 1.0}, {-1.0, 1.0}, {-1.0, 2.0}, {0.0, 2.0},
{1.0, 2.0}, {2.0, 2.0}, {3.0, 2.0}};
TestRouteGeom(start, finish, Algorithm::Result::OK, expectedGeomAfterRestriction);
}

View File

@@ -11,8 +11,8 @@
#include "traffic/traffic_cache.hpp"
#include <vector>
#include <utility>
#include <vector>
namespace routing_test
{
@@ -56,9 +56,9 @@ std::unique_ptr<SingleVehicleWorldGraph> BuildCrossGraph()
loader->AddRoad(7 /* featureId */, true /* oneWay */, 1.0 /* speed */,
RoadGeometry::Points({{1.0, 1.0}, {1.0, 2.0}}));
std::vector<Joint> const joints = {
MakeJoint({{0, 1}, {1, 0}}), MakeJoint({{1, 1}, {2, 0}, {4, 0}, {5, 1}, {6, 0}}),
MakeJoint({{2, 1}, {3, 0}}), MakeJoint({{4, 1}, {5, 0}}), MakeJoint({{6, 1}, {7, 0}})};
std::vector<Joint> const joints = {MakeJoint({{0, 1}, {1, 0}}), MakeJoint({{1, 1}, {2, 0}, {4, 0}, {5, 1}, {6, 0}}),
MakeJoint({{2, 1}, {3, 0}}), MakeJoint({{4, 1}, {5, 0}}),
MakeJoint({{6, 1}, {7, 0}})};
traffic::TrafficCache const trafficCache;
std::shared_ptr<EdgeEstimator> estimator = CreateEstimatorForCar(trafficCache);
@@ -95,11 +95,10 @@ std::unique_ptr<SingleVehicleWorldGraph> BuildTestGraph()
loader->AddRoad(5 /* featureId */, true /* oneWay */, 1.0 /* speed */,
RoadGeometry::Points({{2.0, 2.0}, {3.0, 2.0}}));
std::vector<Joint> const joints = {
MakeJoint({{1, 0}, {0, 0}}), // (0, 1)
MakeJoint({{0, 1}, {2, 0}}), // (-1, 1)
MakeJoint({{3, 1}, {2, 4}, {5, 0}}), // (2, 2)
MakeJoint({{1, 1}, {3, 0}, {4, 0}})}; // (1, 1)
std::vector<Joint> const joints = {MakeJoint({{1, 0}, {0, 0}}), // (0, 1)
MakeJoint({{0, 1}, {2, 0}}), // (-1, 1)
MakeJoint({{3, 1}, {2, 4}, {5, 0}}), // (2, 2)
MakeJoint({{1, 1}, {3, 0}, {4, 0}})}; // (1, 1)
traffic::TrafficCache const trafficCache;
std::shared_ptr<EdgeEstimator> estimator = CreateEstimatorForCar(trafficCache);
@@ -107,4 +106,3 @@ std::unique_ptr<SingleVehicleWorldGraph> BuildTestGraph()
return BuildWorldGraph(std::move(loader), estimator, joints);
}
} // namespace routing_test

View File

@@ -9,4 +9,3 @@ namespace routing_test
std::unique_ptr<routing::SingleVehicleWorldGraph> BuildCrossGraph();
std::unique_ptr<routing::SingleVehicleWorldGraph> BuildTestGraph();
} // namespace routing_test