From 7f7cb7d9c460bfe7fdff8ff9976952b89722a04b Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Tue, 27 Aug 2019 10:45:25 +0300 Subject: [PATCH] [routing] Test fixes. --- .../position_accumulator_tests.cpp | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/routing/routing_tests/position_accumulator_tests.cpp b/routing/routing_tests/position_accumulator_tests.cpp index 44459fd7ea..a6cf2e21e4 100644 --- a/routing/routing_tests/position_accumulator_tests.cpp +++ b/routing/routing_tests/position_accumulator_tests.cpp @@ -17,36 +17,38 @@ double constexpr kEpsMeters = 0.1; UNIT_CLASS_TEST(PositionAccumulator, Smoke) { PushNextPoint({0.0, 0.0}); - PushNextPoint({0.00002, 0.0}); + PushNextPoint({0.00005, 0.0}); + PushNextPoint({0.0001, 0.0}); TEST_EQUAL(GetPointsForTesting().size(), 2, ()); - TEST(m2::AlmostEqualAbs(GetDirection(), m2::PointD(0.00002, 0.0), kEps), ()); - TEST(base::AlmostEqualAbs(GetTrackLengthMForTesting(), 2.22, kEpsMeters), + TEST(m2::AlmostEqualAbs(GetDirection(), m2::PointD(0.0001, 0.0), kEps), (GetDirection())); + TEST(base::AlmostEqualAbs(GetTrackLengthMForTesting(), 11.13, kEpsMeters), (GetTrackLengthMForTesting())); } -// Test on using good segments. -UNIT_CLASS_TEST(PositionAccumulator, LastGoodSegment) +UNIT_CLASS_TEST(PositionAccumulator, GoodSegment) { - double constexpr kStepShortButValid = 0.00002; + double constexpr kStepShortButValid = 0.00001; - for (signed i = -10; i <= 0; ++i) + // The distance from points with i = -15 to point with i = -6 is a little more then + // |PositionAccumulator::kMinValidSegmentLengthM| meters. But the distance from + // point with i = -4 to point with i = 0 is less then |PositionAccumulator::kMinValidSegmentLengthM|. + // So the direction is calculated based on two points. + for (signed i = -15; i <= 0; ++i) PushNextPoint({kStepShortButValid * i, 0.0}); - TEST_EQUAL(GetPointsForTesting().size(), 11, ()); - TEST(m2::AlmostEqualAbs(GetDirection(), m2::PointD(10 * kStepShortButValid, 0.0), kEps), + TEST_EQUAL(GetPointsForTesting().size(), 2, ()); + TEST(m2::AlmostEqualAbs(GetDirection(), m2::PointD(9 * kStepShortButValid, 0.0), kEps), (GetDirection())); - TEST(base::AlmostEqualAbs(GetTrackLengthMForTesting(), 22.26, kEpsMeters), + TEST(base::AlmostEqualAbs(GetTrackLengthMForTesting(), 10.02, kEpsMeters), (GetTrackLengthMForTesting())); double constexpr kStepGood = 0.0001; for (size_t i = 0; i < 10; ++i) PushNextPoint({kStepGood * i, 0.0}); - TEST_EQUAL(GetPointsForTesting().size(), 2, ()); - TEST(m2::AlmostEqualAbs(GetDirection(), m2::PointD(kStepGood, 0.0), kEps), (GetDirection())); - TEST(base::AlmostEqualAbs(GetTrackLengthMForTesting(), 11.13, kEpsMeters), + TEST_EQUAL(GetPointsForTesting().size(), 8, ()); + TEST(m2::AlmostEqualAbs(GetDirection(), m2::PointD(0.0007, 0.0), kEps), (GetDirection())); + TEST(base::AlmostEqualAbs(GetTrackLengthMForTesting(), 77.92, kEpsMeters), (GetTrackLengthMForTesting())); - TEST(m2::AlmostEqualAbs({kStepGood * 8, 0.0}, GetPointsForTesting()[0], kEps), ()); - TEST(m2::AlmostEqualAbs({kStepGood * 9, 0.0}, GetPointsForTesting()[1], kEps), ()); } // Test on removing too outdated elements from the position accumulator. @@ -57,14 +59,8 @@ UNIT_CLASS_TEST(PositionAccumulator, RemovingOutdated) for (size_t i = 0; i < 100; ++i) PushNextPoint({kStep * i, 0.0}); - TEST_EQUAL(GetPointsForTesting().size(), 33, ()); - TEST(m2::AlmostEqualAbs(GetDirection(), m2::PointD(kStep * 32, 0.0), kEps), (GetDirection())); - - for (size_t i = 67; i < 100; ++i) - { - TEST(m2::AlmostEqualAbs({kStep * i, 0.0}, GetPointsForTesting()[i - 67], kEps), - (m2::PointD(kStep * i, 0.0), GetPointsForTesting()[i - 67], i)); - } + TEST_EQUAL(GetPointsForTesting().size(), 8, ()); + TEST(m2::AlmostEqualAbs(GetDirection(), m2::PointD(0.0007, 0.0), kEps), (GetDirection())); } // Test on adding segments longer than |PositionAccumulator::kMaxValidSegmentLengthM| @@ -73,15 +69,17 @@ UNIT_CLASS_TEST(PositionAccumulator, LongSegment) { PushNextPoint({0.0, 0.0}); PushNextPoint({0.001, 0.0}); // Longer than |MaxValidSegmentLengthM|. - TEST(GetPointsForTesting().empty(), ()); - PushNextPoint({0.001001, 0.0}); // Shorter than |kMinValidSegmentLengthM|, but the first one. + TEST_EQUAL(GetPointsForTesting().size(), 1, ()); + PushNextPoint({0.001001, 0.0}); // Shorter than |kMinValidSegmentLengthM|, so it's ignored. PushNextPoint({0.00102, 0.0}); PushNextPoint({0.00104, 0.0}); - PushNextPoint({0.001041, 0.0}); // Shorter than |kMinValidSegmentLengthM|, so it's ignored. - TEST_EQUAL(GetPointsForTesting().size(), 3, ()); - TEST(m2::AlmostEqualAbs(GetDirection(), m2::PointD(0.000039, 0.0), kEps), (GetDirection())); + // The distance from point {0.001, 0.0} to this one is greater then + // |PositionAccumulator::kMinValidSegmentLengthM|, so the point is added. + PushNextPoint({0.0012, 0.0}); + TEST_EQUAL(GetPointsForTesting().size(), 2, ()); + TEST(m2::AlmostEqualAbs(GetDirection(), m2::PointD(0.0002, 0.0), kEps), (GetDirection())); PushNextPoint({0.00201, 0.0}); // Longer than |PositionAccumulator::kMaxValidSegmentLengthM|. - TEST_EQUAL(GetPointsForTesting().size(), 0, ()); + TEST_EQUAL(GetPointsForTesting().size(), 1, ()); TEST(m2::AlmostEqualAbs(GetDirection(), m2::PointD(0.0, 0.0), kEps), (GetDirection())); } } // namespace