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

@@ -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