diff --git a/routing/routing_tests/CMakeLists.txt b/routing/routing_tests/CMakeLists.txt index 60678d3434..9f62ac611a 100644 --- a/routing/routing_tests/CMakeLists.txt +++ b/routing/routing_tests/CMakeLists.txt @@ -26,6 +26,7 @@ set( road_graph_builder.hpp road_graph_nearest_edges_test.cpp route_tests.cpp + routing_helpers_tests.cpp routing_mapping_test.cpp routing_session_test.cpp turns_generator_test.cpp diff --git a/routing/routing_tests/routing_helpers_tests.cpp b/routing/routing_tests/routing_helpers_tests.cpp new file mode 100644 index 0000000000..ae067a7309 --- /dev/null +++ b/routing/routing_tests/routing_helpers_tests.cpp @@ -0,0 +1,66 @@ +#include "testing/testing.hpp" + +#include "routing/road_graph.hpp" +#include "routing/route.hpp" +#include "routing/routing_helpers.hpp" +#include "routing/segment.hpp" +#include "routing/turns.hpp" + +#include "indexer/feature_altitude.hpp" + +#include "geometry/point2d.hpp" + +#include + +namespace routing_test +{ +using namespace routing::turns; +using namespace routing; +using namespace std; + +UNIT_TEST(FillSegmentInfoSmokeTest) +{ + vector const segments = { + {0 /* mwmId */, 1 /* featureId */, 0 /* segmentIdx */, true /* forward */}}; + vector const junctions = { + {m2::PointD(0.0 /* x */, 0.0 /* y */), feature::kInvalidAltitude}, + {m2::PointD(0.1 /* x */, 0.0 /* y */), feature::kInvalidAltitude}}; + Route::TTurns const & turnDirs = {{1 /* point index */, TurnDirection::ReachedYourDestination}}; + Route::TStreets const streets = {}; + Route::TTimes const times = {{0 /* point index */, 0.0 /* time in seconds */}, {1, 1.0}}; + + vector segmentInfo; + FillSegmentInfo(segments, junctions, turnDirs, streets, times, nullptr, segmentInfo); + + TEST_EQUAL(segmentInfo.size(), 1, ()); + TEST_EQUAL(segmentInfo[0].m_turn.m_turn, TurnDirection::ReachedYourDestination, ()); + TEST(segmentInfo[0].m_street.empty(), ()); +} + +UNIT_TEST(FillSegmentInfoTest) +{ + vector const segments = { + {0 /* mwmId */, 1 /* featureId */, 0 /* segmentIdx */, true /* forward */}, {0, 2, 0, true}}; + vector const junctions = { + {m2::PointD(0.0 /* x */, 0.0 /* y */), feature::kInvalidAltitude}, + {m2::PointD(0.1 /* x */, 0.0 /* y */), feature::kInvalidAltitude}, + {m2::PointD(0.2 /* x */, 0.0 /* y */), feature::kInvalidAltitude}}; + Route::TTurns const & turnDirs = {{1 /* point index */, TurnDirection::TurnRight}, + {2 /* point index */, TurnDirection::ReachedYourDestination}}; + Route::TStreets const streets = {{0 /* point index */, "zero"}, {1, "first"}, {2, "second"}}; + Route::TTimes const times = { + {0 /* point index */, 0.0 /* time in seconds */}, {1, 1.0}, {2, 2.0}}; + + vector segmentInfo; + FillSegmentInfo(segments, junctions, turnDirs, streets, times, nullptr, segmentInfo); + + TEST_EQUAL(segmentInfo.size(), 2, ()); + TEST_EQUAL(segmentInfo[0].m_turn.m_turn, TurnDirection::TurnRight, ()); + TEST_EQUAL(segmentInfo[0].m_street, string("first"), ()); + TEST_EQUAL(segmentInfo[0].m_segment, segments[0], ()); + + TEST_EQUAL(segmentInfo[1].m_turn.m_turn, TurnDirection::ReachedYourDestination, ()); + TEST_EQUAL(segmentInfo[1].m_street, string("second"), ()); + TEST_EQUAL(segmentInfo[1].m_segment, segments[1], ()); +} +} // namespace routing_test \ No newline at end of file diff --git a/routing/routing_tests/routing_tests.pro b/routing/routing_tests/routing_tests.pro index bb689fa5c0..997a0c9eed 100644 --- a/routing/routing_tests/routing_tests.pro +++ b/routing/routing_tests/routing_tests.pro @@ -41,6 +41,7 @@ SOURCES += \ road_graph_builder.cpp \ road_graph_nearest_edges_test.cpp \ route_tests.cpp \ + routing_helpers_tests.cpp \ routing_mapping_test.cpp \ routing_session_test.cpp \ turns_generator_test.cpp \ diff --git a/xcode/routing/routing.xcodeproj/project.pbxproj b/xcode/routing/routing.xcodeproj/project.pbxproj index 2e8dc1116c..a1a7299590 100644 --- a/xcode/routing/routing.xcodeproj/project.pbxproj +++ b/xcode/routing/routing.xcodeproj/project.pbxproj @@ -63,6 +63,8 @@ 56555E561D897C90009D786D /* libalohalitics.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6742ACE61C68A23B009CB89E /* libalohalitics.a */; }; 56555E581D897C9D009D786D /* liboauthcpp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6742ACFA1C68A2D7009CB89E /* liboauthcpp.a */; }; 56555E591D897D28009D786D /* testingmain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6742ACDE1C68A13F009CB89E /* testingmain.cpp */; }; + 568194751F03A32400450EC3 /* road_access_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 568194731F03A32400450EC3 /* road_access_test.cpp */; }; + 568194761F03A32400450EC3 /* routing_helpers_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 568194741F03A32400450EC3 /* routing_helpers_tests.cpp */; }; 5694CECA1EBA25F7004576D3 /* road_access_serialization.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5694CEC51EBA25F7004576D3 /* road_access_serialization.cpp */; }; 5694CECB1EBA25F7004576D3 /* road_access_serialization.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 5694CEC61EBA25F7004576D3 /* road_access_serialization.hpp */; }; 5694CECC1EBA25F7004576D3 /* road_access.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5694CEC71EBA25F7004576D3 /* road_access.cpp */; }; @@ -322,6 +324,8 @@ 56099E301CC9247E00A7772A /* bicycle_directions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = bicycle_directions.cpp; sourceTree = ""; }; 56099E311CC9247E00A7772A /* bicycle_directions.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = bicycle_directions.hpp; sourceTree = ""; }; 56099E321CC9247E00A7772A /* directions_engine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = directions_engine.cpp; sourceTree = ""; }; + 568194731F03A32400450EC3 /* road_access_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = road_access_test.cpp; sourceTree = ""; }; + 568194741F03A32400450EC3 /* routing_helpers_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = routing_helpers_tests.cpp; sourceTree = ""; }; 5694CEC51EBA25F7004576D3 /* road_access_serialization.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = road_access_serialization.cpp; sourceTree = ""; }; 5694CEC61EBA25F7004576D3 /* road_access_serialization.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = road_access_serialization.hpp; sourceTree = ""; }; 5694CEC71EBA25F7004576D3 /* road_access.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = road_access.cpp; sourceTree = ""; }; @@ -596,6 +600,8 @@ 6742ACA01C68A07C009CB89E /* routing_tests */ = { isa = PBXGroup; children = ( + 568194731F03A32400450EC3 /* road_access_test.cpp */, + 568194741F03A32400450EC3 /* routing_helpers_tests.cpp */, 56CA09DE1E30E73B00D05C9A /* applying_traffic_test.cpp */, 56CA09DF1E30E73B00D05C9A /* cumulative_restriction_test.cpp */, 56CA09E01E30E73B00D05C9A /* index_graph_tools.cpp */, @@ -1196,7 +1202,9 @@ 67AB92E61B7B3E6E00AB5194 /* turns_tts_text.cpp in Sources */, 0C5FEC601DDE192A0017688C /* index_graph.cpp in Sources */, 0C5FEC6D1DDE19A40017688C /* index_graph_test.cpp in Sources */, + 568194751F03A32400450EC3 /* road_access_test.cpp in Sources */, 56CA09E41E30E73B00D05C9A /* cumulative_restriction_test.cpp in Sources */, + 568194761F03A32400450EC3 /* routing_helpers_tests.cpp in Sources */, 0C12ED231E5C822A0080D0F4 /* index_router.cpp in Sources */, 6753441E1A3F644F00A0A8C3 /* turns.cpp in Sources */, 670B84C01A9381D900CE4492 /* cross_routing_context.cpp in Sources */,