diff --git a/indexer/indexer_tests/CMakeLists.txt b/indexer/indexer_tests/CMakeLists.txt index dd118cadc3..84b93e7758 100644 --- a/indexer/indexer_tests/CMakeLists.txt +++ b/indexer/indexer_tests/CMakeLists.txt @@ -20,6 +20,7 @@ set( index_builder_test.cpp index_test.cpp interval_index_test.cpp + locality_index_test.cpp mwm_set_test.cpp osm_editor_test.cpp osm_editor_test.hpp diff --git a/indexer/indexer_tests/locality_index_test.cpp b/indexer/indexer_tests/locality_index_test.cpp new file mode 100644 index 0000000000..2394712fc4 --- /dev/null +++ b/indexer/indexer_tests/locality_index_test.cpp @@ -0,0 +1,68 @@ +#include "testing/testing.hpp" + +#include "indexer/cell_id.hpp" +#include "indexer/locality_index.hpp" +#include "indexer/locality_index_builder.hpp" +#include "indexer/locality_object.hpp" + +#include "coding/file_container.hpp" +#include "coding/mmap_reader.hpp" +#include "coding/reader.hpp" + +#include "geometry/rect2d.hpp" + +#include "base/osm_id.hpp" + +#include +#include +#include +#include +#include + +using namespace indexer; +using namespace std; + +namespace +{ +struct LocalityObjectVector +{ + template + void ForEach(ToDo && toDo) const + { + for_each(m_objects.cbegin(), m_objects.cend(), forward(toDo)); + } + + vector m_objects; +}; + +using Ids = set; + +template +Ids GetIds(LocalityIndex const & index, m2::RectD const & rect) +{ + Ids ids; + index.ForEachInRect([&ids](osm::Id const & id) { ids.insert(id.EncodedId()); }, rect); + return ids; +}; + +UNIT_TEST(LocalityIndexTest) +{ + LocalityObjectVector objects; + objects.m_objects.resize(4); + objects.m_objects[0].SetForTests(1, m2::PointD{0, 0}); + objects.m_objects[1].SetForTests(2, m2::PointD{1, 0}); + objects.m_objects[2].SetForTests(3, m2::PointD{1, 1}); + objects.m_objects[3].SetForTests(4, m2::PointD{0, 1}); + + vector localityIndex; + MemWriter> writer(localityIndex); + covering::BuildLocalityIndex(objects, writer, "tmp"); + MemReader reader(localityIndex.data(), localityIndex.size()); + + indexer::LocalityIndex index(reader); + + TEST_EQUAL(GetIds(index, m2::RectD{-0.5, -0.5, 0.5, 0.5}), (Ids{1}), ()); + TEST_EQUAL(GetIds(index, m2::RectD{0.5, -0.5, 1.5, 1.5}), (Ids{2, 3}), ()); + TEST_EQUAL(GetIds(index, m2::RectD{-0.5, -0.5, 1.5, 1.5}), (Ids{1, 2, 3, 4}), ()); +} +} // namespace diff --git a/indexer/locality_object.hpp b/indexer/locality_object.hpp index b89b030ec2..c366dcc409 100644 --- a/indexer/locality_object.hpp +++ b/indexer/locality_object.hpp @@ -38,6 +38,13 @@ public: toDo(m_triangles[i - 2], m_triangles[i - 1], m_triangles[i]); } + void SetForTests(uint64_t id, m2::PointD point) + { + m_id = id; + m_points.clear(); + m_points.push_back(point); + } + private: uint64_t m_id = 0; std::vector m_points; diff --git a/xcode/indexer/indexer.xcodeproj/project.pbxproj b/xcode/indexer/indexer.xcodeproj/project.pbxproj index 97f5648706..13e3223911 100644 --- a/xcode/indexer/indexer.xcodeproj/project.pbxproj +++ b/xcode/indexer/indexer.xcodeproj/project.pbxproj @@ -77,6 +77,7 @@ 4095DEB22020AC0000C591A3 /* locality_index.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 4095DEB12020AC0000C591A3 /* locality_index.hpp */; }; 4099F6491FC7142A002A7B05 /* fake_feature_ids.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4099F6471FC71429002A7B05 /* fake_feature_ids.cpp */; }; 4099F64A1FC7142A002A7B05 /* fake_feature_ids.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 4099F6481FC7142A002A7B05 /* fake_feature_ids.hpp */; }; + 40A1C30A202B321000F71672 /* locality_index_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 40A1C309202B321000F71672 /* locality_index_test.cpp */; }; 456B3FB41EDEEB65009B3D1F /* scales_patch.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 456B3FB31EDEEB65009B3D1F /* scales_patch.hpp */; }; 456E1B181F90E5B7009C32E1 /* cities_boundaries_serdes.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 456E1B141F90E5B6009C32E1 /* cities_boundaries_serdes.hpp */; }; 456E1B191F90E5B7009C32E1 /* ftypes_sponsored.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 456E1B151F90E5B6009C32E1 /* ftypes_sponsored.cpp */; }; @@ -313,6 +314,7 @@ 4095DEB12020AC0000C591A3 /* locality_index.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = locality_index.hpp; sourceTree = ""; }; 4099F6471FC71429002A7B05 /* fake_feature_ids.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = fake_feature_ids.cpp; sourceTree = ""; }; 4099F6481FC7142A002A7B05 /* fake_feature_ids.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = fake_feature_ids.hpp; sourceTree = ""; }; + 40A1C309202B321000F71672 /* locality_index_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = locality_index_test.cpp; sourceTree = ""; }; 456B3FB31EDEEB65009B3D1F /* scales_patch.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = scales_patch.hpp; sourceTree = ""; }; 456E1B141F90E5B6009C32E1 /* cities_boundaries_serdes.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cities_boundaries_serdes.hpp; sourceTree = ""; }; 456E1B151F90E5B6009C32E1 /* ftypes_sponsored.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ftypes_sponsored.cpp; sourceTree = ""; }; @@ -611,6 +613,7 @@ 670C60F81AB0657700C38A8C /* indexer_tests */ = { isa = PBXGroup; children = ( + 40A1C309202B321000F71672 /* locality_index_test.cpp */, 3D74EF231F8F559D0081202C /* ugc_types_test.cpp */, 3D452AF71EE6D9F5009EAB9B /* wheelchair_tests.cpp */, 3D452AF81EE6D9F5009EAB9B /* feature_names_test.cpp */, @@ -1113,6 +1116,7 @@ 6753411A1A3F540F00A0A8C3 /* feature_impl.cpp in Sources */, 56C74C1C1C749E4700B71B9F /* categories_holder_loader.cpp in Sources */, 3D74EF241F8F559D0081202C /* ugc_types_test.cpp in Sources */, + 40A1C30A202B321000F71672 /* locality_index_test.cpp in Sources */, 6753410D1A3F540F00A0A8C3 /* drawing_rules.cpp in Sources */, 675341301A3F540F00A0A8C3 /* index.cpp in Sources */, 34664CF61D49FEC1003D7096 /* centers_table.cpp in Sources */,