diff options
author | Yuri Gorshenin <y@maps.me> | 2017-09-27 17:44:05 +0300 |
---|---|---|
committer | mpimenov <mpimenov@users.noreply.github.com> | 2017-09-28 18:54:14 +0300 |
commit | e04d25505fb37abff651434ed4e29e7692af808f (patch) | |
tree | 72ff1216127379085f9141eec89165e09172896b /indexer/indexer_tests | |
parent | 6737cd92217fdd9e02ee0e19eddc45156e7b104a (diff) |
[indexer] Simplified boundaries encoding/decoding.
Diffstat (limited to 'indexer/indexer_tests')
-rw-r--r-- | indexer/indexer_tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | indexer/indexer_tests/boundary_boxes_serdes_tests.cpp | 114 | ||||
-rw-r--r-- | indexer/indexer_tests/indexer_tests.pro | 1 |
3 files changed, 116 insertions, 0 deletions
diff --git a/indexer/indexer_tests/CMakeLists.txt b/indexer/indexer_tests/CMakeLists.txt index ffadc3d332..43e299568e 100644 --- a/indexer/indexer_tests/CMakeLists.txt +++ b/indexer/indexer_tests/CMakeLists.txt @@ -2,6 +2,7 @@ project(indexer_tests) set( SRC + boundary_boxes_serdes_tests.cpp categories_test.cpp cell_coverer_test.cpp cell_id_test.cpp diff --git a/indexer/indexer_tests/boundary_boxes_serdes_tests.cpp b/indexer/indexer_tests/boundary_boxes_serdes_tests.cpp new file mode 100644 index 0000000000..1a5511d5bf --- /dev/null +++ b/indexer/indexer_tests/boundary_boxes_serdes_tests.cpp @@ -0,0 +1,114 @@ +#include "testing/testing.hpp" + +#include "indexer/boundary_boxes.hpp" +#include "indexer/boundary_boxes_serdes.hpp" +#include "indexer/coding_params.hpp" + +#include "coding/reader.hpp" +#include "coding/writer.hpp" + +#include "geometry/mercator.hpp" +#include "geometry/point2d.hpp" + +#include <cstdint> +#include <vector> + +using namespace indexer; +using namespace m2; +using namespace serial; +using namespace std; + +namespace +{ +using Boundary = vector<BoundaryBoxes>; +using Boundaries = vector<Boundary>; + +void TestEqual(BoundingBox const & lhs, BoundingBox const & rhs, double eps) +{ + TEST(AlmostEqualAbs(lhs.Min(), rhs.Min(), eps), (lhs, rhs)); + TEST(AlmostEqualAbs(lhs.Max(), rhs.Max(), eps), (lhs, rhs)); +} + +void TestEqual(CalipersBox const & lhs, CalipersBox const & rhs, double eps) {} +void TestEqual(DiamondBox const & lhs, DiamondBox const & rhs, double eps) +{ + auto const lps = lhs.Points(); + auto const rps = rhs.Points(); + TEST_EQUAL(lps.size(), 4, (lhs)); + TEST_EQUAL(rps.size(), 4, (rhs)); + for (size_t i = 0; i < 4; ++i) + { + TEST(AlmostEqualAbs(lps[i], rps[i], eps), (lhs, rhs)); + } +} + +void TestEqual(BoundaryBoxes const & lhs, BoundaryBoxes const & rhs, double eps) +{ + TestEqual(lhs.m_bbox, rhs.m_bbox, eps); + TestEqual(lhs.m_cbox, rhs.m_cbox, eps); + TestEqual(lhs.m_dbox, rhs.m_dbox, eps); +} + +void TestEqual(Boundary const & lhs, Boundary const & rhs, double eps) +{ + TEST_EQUAL(lhs.size(), rhs.size(), (lhs, rhs)); + for (size_t i = 0; i < lhs.size(); ++i) + TestEqual(lhs[i], rhs[i], eps); +} + +void TestEqual(Boundaries const & lhs, Boundaries const & rhs, double eps) +{ + TEST_EQUAL(lhs.size(), rhs.size(), (lhs, rhs)); + for (size_t i = 0; i < lhs.size(); ++i) + TestEqual(lhs[i], rhs[i], eps); +} + +Boundaries EncodeDecode(Boundaries const & boundaries, CodingParams const & params) +{ + vector<uint8_t> buffer; + { + MemWriter<decltype(buffer)> sink(buffer); + BoundaryBoxesEncoder<decltype(sink)> encoder(sink, params); + encoder(boundaries); + } + + { + Boundaries boundaries; + MemReader reader(buffer.data(), buffer.size()); + NonOwningReaderSource source(reader); + BoundaryBoxesDecoder<decltype(source)> decoder(source, params); + decoder(boundaries); + return boundaries; + } +} + +void TestEncodeDecode(Boundaries const & expected, CodingParams const & params, double eps) +{ + Boundaries const actual = EncodeDecode(expected, params); + TestEqual(expected, actual, eps); +} + +UNIT_TEST(BoundaryBoxesSerDes_Smoke) +{ + CodingParams const params(19 /* coordBits */, PointD(MercatorBounds::minX, MercatorBounds::minY)); + double const kEps = 1e-3; + + { + Boundaries const expected; + TestEncodeDecode(expected, params, kEps); + } + + { + Boundary boundary0; + boundary0.emplace_back(vector<PointD>{{PointD(0.1234, 5.6789)}}); + boundary0.emplace_back(vector<PointD>{{PointD(3.1415, 2.1828), PointD(2.1828, 3.1415)}}); + + Boundary boundary1; + boundary1.emplace_back( + vector<PointD>{{PointD(1.000, 1.000), PointD(1.002, 1.000), PointD(1.002, 1.003)}}); + + Boundaries const expected = {{boundary0, boundary1}}; + TestEncodeDecode(expected, params, kEps); + } +} +} // namespace diff --git a/indexer/indexer_tests/indexer_tests.pro b/indexer/indexer_tests/indexer_tests.pro index 78d6fe1d5f..1220c484c2 100644 --- a/indexer/indexer_tests/indexer_tests.pro +++ b/indexer/indexer_tests/indexer_tests.pro @@ -28,6 +28,7 @@ HEADERS += \ SOURCES += \ ../../testing/testingmain.cpp \ + boundary_boxes_serdes_tests.cpp \ categories_test.cpp \ cell_coverer_test.cpp \ cell_id_test.cpp \ |