| 65 | }; |
| 66 | |
| 67 | UNIT_TEST(TestFixupTurns) |
| 68 | { |
| 69 | double const kHalfSquareSideMeters = 10.; |
| 70 | m2::PointD const kSquareCenterLonLat = {0., 0.}; |
| 71 | m2::RectD const kSquareNearZero = |
| 72 | mercator::MetersToXY(kSquareCenterLonLat.x, kSquareCenterLonLat.y, kHalfSquareSideMeters); |
| 73 | { |
| 74 | // Removing a turn in case staying on a roundabout. |
| 75 | vector<m2::PointD> const pointsMerc1 = {{kSquareNearZero.minX(), kSquareNearZero.minY()}, |
| 76 | {kSquareNearZero.minX(), kSquareNearZero.minY()}, |
| 77 | {kSquareNearZero.maxX(), kSquareNearZero.maxY()}, |
| 78 | {kSquareNearZero.maxX(), kSquareNearZero.minY()}}; |
| 79 | // The constructor TurnItem(uint32_t idx, CarDirection t, uint32_t exitNum = 0) |
| 80 | // is used for initialization of vector<TurnItem> below. |
| 81 | vector<turns::TurnItem> turnsDir1 = { |
| 82 | {1, CarDirection::EnterRoundAbout}, {2, CarDirection::StayOnRoundAbout}, {3, CarDirection::LeaveRoundAbout}}; |
| 83 | vector<RouteSegment> routeSegments; |
| 84 | RouteSegmentsFrom({}, pointsMerc1, turnsDir1, {}, routeSegments); |
| 85 | FixupCarTurns(routeSegments); |
| 86 | vector<turns::TurnItem> const expectedTurnDir1 = { |
| 87 | {1, CarDirection::EnterRoundAbout, 2}, {2, CarDirection::None, 0}, {3, CarDirection::LeaveRoundAbout, 2}}; |
| 88 | TEST_EQUAL(routeSegments[0].GetTurn(), expectedTurnDir1[0], ()); |
| 89 | TEST_EQUAL(routeSegments[1].GetTurn(), expectedTurnDir1[1], ()); |
| 90 | TEST_EQUAL(routeSegments[2].GetTurn(), expectedTurnDir1[2], ()); |
| 91 | } |
| 92 | { |
| 93 | // Merging turns which are close to each other. |
| 94 | vector<m2::PointD> const pointsMerc2 = {{kSquareNearZero.minX(), kSquareNearZero.minY()}, |
| 95 | {kSquareNearZero.minX(), kSquareNearZero.minY()}, |
| 96 | {kSquareCenterLonLat.x, kSquareCenterLonLat.y}, |
| 97 | {kSquareNearZero.maxX(), kSquareNearZero.maxY()}}; |
| 98 | vector<turns::TurnItem> turnsDir2 = { |
| 99 | {1, CarDirection::None}, {2, CarDirection::GoStraight}, {3, CarDirection::TurnLeft}}; |
| 100 | vector<RouteSegment> routeSegments2; |
| 101 | RouteSegmentsFrom({}, pointsMerc2, turnsDir2, {}, routeSegments2); |
| 102 | FixupCarTurns(routeSegments2); |
| 103 | vector<turns::TurnItem> const expectedTurnDir2 = { |
| 104 | {1, CarDirection::None}, {2, CarDirection::None}, {3, CarDirection::TurnLeft}}; |
| 105 | TEST_EQUAL(routeSegments2[0].GetTurn(), expectedTurnDir2[0], ()); |
| 106 | TEST_EQUAL(routeSegments2[1].GetTurn(), expectedTurnDir2[1], ()); |
| 107 | TEST_EQUAL(routeSegments2[2].GetTurn(), expectedTurnDir2[2], ()); |
| 108 | } |
| 109 | { |
| 110 | // No turn is removed. |
| 111 | vector<m2::PointD> const pointsMerc3 = { |
| 112 | {kSquareNearZero.minX(), kSquareNearZero.minY()}, |
| 113 | {kSquareNearZero.minX(), kSquareNearZero.maxY()}, |
| 114 | {kSquareNearZero.maxX(), kSquareNearZero.maxY()}, |
| 115 | }; |
| 116 | vector<turns::TurnItem> turnsDir3 = {{1, CarDirection::None}, {2, CarDirection::TurnRight}}; |
| 117 | |
| 118 | vector<RouteSegment> routeSegments3; |
| 119 | RouteSegmentsFrom({}, {}, turnsDir3, {}, routeSegments3); |
| 120 | FixupCarTurns(routeSegments3); |
| 121 | vector<turns::TurnItem> const expectedTurnDir3 = {{1, CarDirection::None}, {2, CarDirection::TurnRight}}; |
| 122 | |
| 123 | TEST_EQUAL(routeSegments3[0].GetTurn(), expectedTurnDir3[0], ()); |
| 124 | TEST_EQUAL(routeSegments3[1].GetTurn(), expectedTurnDir3[1], ()); |
nothing calls this directly
no test coverage detected