Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--data/route_test1.mwmbin551 -> 0 bytes
-rw-r--r--data/route_test1.osm.bz2bin655 -> 0 bytes
-rw-r--r--data/route_test2.mwmbin1206 -> 0 bytes
-rw-r--r--data/route_test2.osm.bz2bin1230 -> 0 bytes
-rw-r--r--routing/routing_tests/features_road_graph_test.cpp264
-rw-r--r--routing/routing_tests/road_graph_nearest_turns_test.cpp101
-rw-r--r--routing/routing_tests/routing_tests.pro2
8 files changed, 102 insertions, 269 deletions
diff --git a/.gitignore b/.gitignore
index 6a20628be9..5307177d39 100644
--- a/.gitignore
+++ b/.gitignore
@@ -87,10 +87,6 @@ data/*.bz2
data/settings.ini
!data/minsk-pass.mwm
!data/minsk-pass.osm.bz2
-!data/route_test1.mwm
-!data/route_test1.osm.bz2
-!data/route_test2.mwm
-!data/route_test2.osm.bz2
data/index.idx
data/index.stamp
# local statistics storage
diff --git a/data/route_test1.mwm b/data/route_test1.mwm
deleted file mode 100644
index 28dbc2a025..0000000000
--- a/data/route_test1.mwm
+++ /dev/null
Binary files differ
diff --git a/data/route_test1.osm.bz2 b/data/route_test1.osm.bz2
deleted file mode 100644
index 20c8cdd317..0000000000
--- a/data/route_test1.osm.bz2
+++ /dev/null
Binary files differ
diff --git a/data/route_test2.mwm b/data/route_test2.mwm
deleted file mode 100644
index 8d408df873..0000000000
--- a/data/route_test2.mwm
+++ /dev/null
Binary files differ
diff --git a/data/route_test2.osm.bz2 b/data/route_test2.osm.bz2
deleted file mode 100644
index 0092c7597d..0000000000
--- a/data/route_test2.osm.bz2
+++ /dev/null
Binary files differ
diff --git a/routing/routing_tests/features_road_graph_test.cpp b/routing/routing_tests/features_road_graph_test.cpp
deleted file mode 100644
index c12fe7c2cc..0000000000
--- a/routing/routing_tests/features_road_graph_test.cpp
+++ /dev/null
@@ -1,264 +0,0 @@
-#include "testing/testing.hpp"
-
-#include "routing/routing_tests/features_road_graph_test.hpp"
-
-#include "routing/route.hpp"
-
-#include "indexer/classificator_loader.hpp"
-#include "indexer/feature.hpp"
-#include "indexer/ftypes_matcher.hpp"
-
-#include "base/logging.hpp"
-
-
-using namespace routing;
-
-namespace routing_test
-{
-
-class EqualPos
-{
- RoadPos m_pos;
- double m_distance;
-public:
- EqualPos(RoadPos const & pos, double d) : m_pos(pos), m_distance(d) {}
- bool operator() (PossibleTurn const & r) const
- {
- return r.m_pos == m_pos;
- }
-};
-
-bool TestResult(IRoadGraph::TurnsVectorT const & vec, RoadPos const & pos, double d)
-{
- return find_if(vec.begin(), vec.end(), EqualPos(pos, d)) != vec.end();
-}
-
-
-
-void Name2IdMapping::operator()(FeatureType const & ft)
-{
- if (!ftypes::IsStreetChecker::Instance()(ft))
- return;
-
- string name;
- VERIFY(ft.GetName(0, name), ());
-
- m_name2Id[name] = ft.GetID().m_offset;
- m_id2Name[ft.GetID().m_offset] = name;
-}
-
-uint32_t Name2IdMapping::GetId(string const & name)
-{
- ASSERT(m_name2Id.find(name) != m_name2Id.end(), ());
- return m_name2Id[name];
-}
-
-string const & Name2IdMapping::GetName(uint32_t id)
-{
- ASSERT(m_id2Name.find(id) != m_id2Name.end(), ());
- return m_id2Name[id];
-}
-
-
-FeatureRoadGraphTester::FeatureRoadGraphTester(string const & name)
-{
- classificator::Load();
-
- pair<MwmSet::MwmLock, bool> p = m_index.RegisterMap(name);
- if (!p.second)
- {
- LOG(LERROR, ("MWM file not found"));
- return;
- }
-
- m_graph.reset(new FeaturesRoadGraph(&m_index, 0));
-
- m_index.ForEachInRect(m_mapping, MercatorBounds::FullRect(), m_graph->GetStreetReadScale());
-}
-
-void FeatureRoadGraphTester::FeatureID2Name(routing::RoadPos & pos)
-{
- string const & name = m_mapping.GetName(pos.GetFeatureId());
- int id = 0;
- VERIFY(strings::to_int(name, id), (name));
-
- pos = RoadPos(static_cast<uint32_t>(id), pos.IsForward(), pos.GetSegId());
-}
-
-void FeatureRoadGraphTester::FeatureID2Name(IRoadGraph::TurnsVectorT & vec)
-{
- for (size_t i = 0; i < vec.size(); ++i)
- FeatureID2Name(vec[i].m_pos);
-}
-
-void FeatureRoadGraphTester::FeatureID2Name(vector<routing::RoadPos> & vec)
-{
- for (size_t i = 0; i < vec.size(); ++i)
- FeatureID2Name(vec[i]);
-}
-
-void FeatureRoadGraphTester::Name2FeatureID(vector<routing::RoadPos> & vec)
-{
- for (size_t i = 0; i < vec.size(); ++i)
- vec[i] = RoadPos(m_mapping.GetId(strings::to_string(vec[i].GetFeatureId())), vec[i].IsForward(),
- vec[i].GetSegId());
-}
-
-void FeatureRoadGraphTester::GetPossibleTurns(RoadPos const & pos, IRoadGraph::TurnsVectorT & vec)
-{
- m_graph->GetNearestTurns(RoadPos(m_mapping.GetId(strings::to_string(pos.GetFeatureId())),
- pos.IsForward(), pos.GetSegId()),
- vec);
- FeatureID2Name(vec);
-}
-
-template <size_t N>
-void FeatureRoadGraphTester::ReconstructPath(routing::RoadPos (&arr)[N], vector<m2::PointD> & vec)
-{
- vector<RoadPos> positions(arr, arr + N);
- Name2FeatureID(positions);
-
- Route route("dummy");
- m_graph->ReconstructPath(positions, route);
- vec.assign(route.GetPoly().Begin(), route.GetPoly().End());
-}
-
-}
-
-
-using namespace routing_test;
-
-
-UNIT_TEST(FRG_TurnsTest_MWM1)
-{
- FeatureRoadGraphTester tester("route_test1.mwm");
-
- {
- IRoadGraph::TurnsVectorT vec;
- tester.GetPossibleTurns(RoadPos(0, true, 1), vec);
- TEST_EQUAL(vec.size(), 1, ());
- TEST(TestResult(vec, RoadPos(0, true, 0), -1), ());
- }
-
- {
- IRoadGraph::TurnsVectorT vec;
- tester.GetPossibleTurns(RoadPos(0, false, 1), vec);
- TEST_EQUAL(vec.size(), 7, ());
- TEST(TestResult(vec, RoadPos(0, false, 2), -1), ());
- TEST(TestResult(vec, RoadPos(0, false, 3), -1), ());
- TEST(TestResult(vec, RoadPos(1, true, 1), -1), ());
- TEST(TestResult(vec, RoadPos(1, false, 2), -1), ());
- TEST(TestResult(vec, RoadPos(2, true, 0), -1), ());
- TEST(TestResult(vec, RoadPos(3, false, 0), -1), ());
- TEST(TestResult(vec, RoadPos(3, true, 2), -1), ());
- }
-
- {
- IRoadGraph::TurnsVectorT vec;
- tester.GetPossibleTurns(RoadPos(1, true, 0), vec);
- TEST_EQUAL(vec.size(), 0, ());
- }
-
- {
- IRoadGraph::TurnsVectorT vec;
- tester.GetPossibleTurns(RoadPos(1, false, 0), vec);
- TEST_EQUAL(vec.size(), 3, ());
- TEST(TestResult(vec, RoadPos(1, false, 2), 10), ());
- TEST(TestResult(vec, RoadPos(0, true, 1), 10), ());
- TEST(TestResult(vec, RoadPos(0, false, 2), 10), ());
- }
-}
-
-UNIT_TEST(FRG_TurnsTest_MWM2)
-{
- FeatureRoadGraphTester tester("route_test2.mwm");
-
- {
- IRoadGraph::TurnsVectorT vec;
- tester.GetPossibleTurns(RoadPos(0, false, 0), vec);
- TEST_EQUAL(vec.size(), 8, ());
- TEST(TestResult(vec, RoadPos(0, false, 1), -1), ());
- TEST(TestResult(vec, RoadPos(0, false, 2), -1), ());
- TEST(TestResult(vec, RoadPos(0, false, 3), -1), ());
- TEST(TestResult(vec, RoadPos(0, false, 4), -1), ());
- TEST(TestResult(vec, RoadPos(2, true, 1), -1), ());
- TEST(TestResult(vec, RoadPos(5, false, 0), -1), ());
- TEST(TestResult(vec, RoadPos(6, false, 0), -1), ());
- TEST(TestResult(vec, RoadPos(4, false, 0), -1), ());
- }
-
- {
- IRoadGraph::TurnsVectorT vec;
- tester.GetPossibleTurns(RoadPos(8, true, 0), vec);
- TEST_EQUAL(vec.size(), 2, ());
- TEST(TestResult(vec, RoadPos(1, true, 1), -1), ());
- TEST(TestResult(vec, RoadPos(8, true, 5), -1), ());
- }
-
- {
- IRoadGraph::TurnsVectorT vec;
- tester.GetPossibleTurns(RoadPos(2, true, 1), vec);
- TEST_EQUAL(vec.size(), 4, ());
- TEST(TestResult(vec, RoadPos(3, true, 0), -1), ());
- TEST(TestResult(vec, RoadPos(3, false, 1), -1), ());
- TEST(TestResult(vec, RoadPos(2, true, 0), -1), ());
- TEST(TestResult(vec, RoadPos(8, true, 4), -1), ());
- }
-
- {
- IRoadGraph::TurnsVectorT vec;
- tester.GetPossibleTurns(RoadPos(3, false, 0), vec);
- TEST_EQUAL(vec.size(), 5, ());
- TEST(TestResult(vec, RoadPos(3, false, 1), -1), ());
- TEST(TestResult(vec, RoadPos(3, false, 2), -1), ());
- TEST(TestResult(vec, RoadPos(2, true, 0), -1), ());
- TEST(TestResult(vec, RoadPos(6, true, 0), -1), ());
- TEST(TestResult(vec, RoadPos(6, false, 1), -1), ());
- }
-
- {
- IRoadGraph::TurnsVectorT vec;
- tester.GetPossibleTurns(RoadPos(7, false, 0), vec);
- TEST_EQUAL(vec.size(), 0, ());
- }
-
- {
- IRoadGraph::TurnsVectorT vec;
- tester.GetPossibleTurns(RoadPos(7, true, 0), vec);
- TEST_EQUAL(vec.size(), 1, ());
- TEST(TestResult(vec, RoadPos(8, true, 1), -1), ());
- }
-
- {
- IRoadGraph::TurnsVectorT vec;
- tester.GetPossibleTurns(RoadPos(8, true, 3), vec);
- TEST_EQUAL(vec.size(), 7, ());
- TEST(TestResult(vec, RoadPos(8, true, 2), -1), ());
- TEST(TestResult(vec, RoadPos(5, true, 0), -1), ());
- TEST(TestResult(vec, RoadPos(5, false, 1), -1), ());
- TEST(TestResult(vec, RoadPos(7, false, 0), -1), ());
- TEST(TestResult(vec, RoadPos(8, true, 1), -1), ());
- TEST(TestResult(vec, RoadPos(1, true, 1), -1), ());
- TEST(TestResult(vec, RoadPos(8, true, 5), -1), ());
- }
-}
-
-UNIT_TEST(FRG_ReconstructTest_MWM2)
-{
- // Uncomment to see debug log.
- //my::g_LogLevel = LDEBUG;
-
- FeatureRoadGraphTester tester("route_test2.mwm");
-
- {
- RoadPos arr[] = {
- RoadPos(8, true, 4),
- RoadPos(2, true, 0),
- RoadPos(3, true, 2)
- };
-
- vector<m2::PointD> vec;
- tester.ReconstructPath(arr, vec);
- TEST_EQUAL(vec.size(), 3, ());
- }
-}
diff --git a/routing/routing_tests/road_graph_nearest_turns_test.cpp b/routing/routing_tests/road_graph_nearest_turns_test.cpp
new file mode 100644
index 0000000000..167efd0db2
--- /dev/null
+++ b/routing/routing_tests/road_graph_nearest_turns_test.cpp
@@ -0,0 +1,101 @@
+#include "testing/testing.hpp"
+
+#include "routing/road_graph.hpp"
+#include "routing/routing_tests/road_graph_builder.hpp"
+#include "std/algorithm.hpp"
+
+namespace routing
+{
+UNIT_TEST(RoadGraph_NearestTurns)
+{
+ // 2nd road
+ // o
+ // |
+ // |
+ // o
+ // |
+ // | 1st road
+ // o--o--x--o--o
+ // |
+ // |
+ // o
+ // |
+ // |
+ // o
+ //
+ // Just two roads intersecting at (0, 0).
+ routing_test::RoadGraphMockSource graph;
+ {
+ IRoadGraph::RoadInfo ri0;
+ ri0.m_points.emplace_back(2, 0);
+ ri0.m_points.emplace_back(-1, 0);
+ ri0.m_points.emplace_back(0, 0);
+ ri0.m_points.emplace_back(1, 0);
+ ri0.m_points.emplace_back(2, 0);
+ ri0.m_speedKMPH = 5;
+ ri0.m_bidirectional = true;
+
+ IRoadGraph::RoadInfo ri1;
+ ri1.m_points.emplace_back(0, -2);
+ ri1.m_points.emplace_back(0, -1);
+ ri1.m_points.emplace_back(0, 0);
+ ri1.m_points.emplace_back(0, 1);
+ ri1.m_points.emplace_back(0, 2);
+ ri1.m_speedKMPH = 5;
+ ri1.m_bidirectional = true;
+
+ graph.AddRoad(move(ri0));
+ graph.AddRoad(move(ri1));
+ }
+
+ // We're standing at:
+ // ... x--o ... segment and looking to the right.
+ RoadPos const crossPos(0 /* featureId */, true /* forward */, 2 /* segId */, m2::PointD(0, 0));
+ IRoadGraph::RoadPosVectorT expected = {
+ // It's possible to get to the standing RoadPos from RoadPos'es on
+ // the first road marked with > and <.
+ //
+ // ...
+ // |
+ // ...--o>>x<<o--...
+ // |
+ // ...
+ //
+ RoadPos(0 /* first road */, true /* forward */, 1 /* segId */, m2::PointD(0, 0)),
+ RoadPos(0 /* first road */, false /* forward */, 2 /* segId */, m2::PointD(0, 0)),
+
+ // It's possible to get to the standing RoadPos from RoadPos'es on
+ // the second road marked with v and ^.
+ //
+ // ...
+ // |
+ // o
+ // v
+ // v
+ // ...-x-...
+ // ^
+ // ^
+ // o
+ // |
+ // ...
+ //
+ RoadPos(1 /* first road */, true /* forward */, 1 /* segId */, m2::PointD(0, 0)),
+ RoadPos(1 /* first road */, false /* forward */, 2 /* segId */, m2::PointD(0, 0)),
+ };
+
+ IRoadGraph::TurnsVectorT turns;
+ graph.GetNearestTurns(crossPos, turns);
+
+ IRoadGraph::RoadPosVectorT actual;
+ for (PossibleTurn const & turn : turns) {
+ actual.push_back(turn.m_pos);
+ TEST_EQUAL(5, turn.m_speedKMPH, ());
+ TEST_EQUAL(0, turn.m_metersCovered, ());
+ TEST_EQUAL(0, turn.m_secondsCovered, ());
+ }
+
+ sort(expected.begin(), expected.end());
+ sort(actual.begin(), actual.end());
+ TEST_EQUAL(expected, actual, ());
+}
+} // namespace routing
diff --git a/routing/routing_tests/routing_tests.pro b/routing/routing_tests/routing_tests.pro
index d18691f38c..02c12ea782 100644
--- a/routing/routing_tests/routing_tests.pro
+++ b/routing/routing_tests/routing_tests.pro
@@ -22,9 +22,9 @@ SOURCES += \
astar_algorithm_test.cpp \
astar_router_test.cpp \
cross_routing_tests.cpp \
- features_road_graph_test.cpp \
osrm_router_test.cpp \
road_graph_builder.cpp \
+ road_graph_nearest_turns_test.cpp \
vehicle_model_test.cpp \
HEADERS += \