forked from organicmaps/organicmaps
[routing] Tests for GetDistanceM method.
This commit is contained in:
parent
7ed2944c73
commit
958008d5c6
2 changed files with 24 additions and 3 deletions
|
@ -17,7 +17,6 @@ Iter FollowedPolyline::End() const
|
|||
return Iter(m_poly.Back(), m_poly.GetSize() - 1);
|
||||
}
|
||||
|
||||
// TODO (ldragunov) Write tests for this code.
|
||||
double FollowedPolyline::GetDistanceM(Iter const & it1, Iter const & it2) const
|
||||
{
|
||||
ASSERT(IsValid(), ());
|
||||
|
|
|
@ -57,8 +57,30 @@ UNIT_TEST(FollowedPolylineFollowingTestByPrediction)
|
|||
MercatorBounds::RectByCenterXYAndSizeInMeters({0.002, 0.003}, 20000), dist);
|
||||
TEST_EQUAL(polyline.GetCurrentIter().m_ind, 1, ());
|
||||
TEST_LESS_OR_EQUAL(MercatorBounds::DistanceOnEarth(polyline.GetCurrentIter().m_pt,
|
||||
m2::PointD(0.003, 0.003)),
|
||||
0.1, ());
|
||||
m2::PointD(0.003, 0.003)), 0.1, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(FollowedPolylineDistanceCalculationTest)
|
||||
{
|
||||
// Test full length case.
|
||||
FollowedPolyline polyline(kTestDirectedPolyline.Begin(), kTestDirectedPolyline.End());
|
||||
double distance = polyline.GetDistanceM(polyline.Begin(), polyline.End());
|
||||
double masterDistance = MercatorBounds::DistanceOnEarth(kTestDirectedPolyline.Front(),
|
||||
kTestDirectedPolyline.Back());
|
||||
ASSERT_LESS(pow(distance - masterDistance, 2), 0.001, (distance, masterDistance));
|
||||
|
||||
// Test partial length case.
|
||||
polyline.UpdateProjection(MercatorBounds::RectByCenterXYAndSizeInMeters({3, 0}, 2));
|
||||
distance = polyline.GetDistanceM(polyline.GetCurrentIter(), polyline.End());
|
||||
masterDistance = MercatorBounds::DistanceOnEarth(kTestDirectedPolyline.GetPoint(1),
|
||||
kTestDirectedPolyline.Back());
|
||||
ASSERT_LESS(pow(distance - masterDistance, 2), 0.001, (distance, masterDistance));
|
||||
|
||||
// Test point in the middle case.
|
||||
polyline.UpdateProjection(MercatorBounds::RectByCenterXYAndSizeInMeters({4, 0}, 2));
|
||||
distance = polyline.GetDistanceM(polyline.GetCurrentIter(), polyline.End());
|
||||
masterDistance = MercatorBounds::DistanceOnEarth(m2::PointD(4, 0),
|
||||
kTestDirectedPolyline.Back());
|
||||
ASSERT_LESS(pow(distance - masterDistance, 2), 0.001, (distance, masterDistance));
|
||||
}
|
||||
} // namespace routing_test
|
||||
|
|
Loading…
Add table
Reference in a new issue