summaryrefslogtreecommitdiff
path: root/test/text
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-12-09 15:23:12 +0200
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-12-09 17:26:13 +0200
commit89665326c2251608ac2f3408f73b781a23fb1ba5 (patch)
tree0d17ccea6e047343d347340b159fdb6b48d3910d /test/text
parentd36958997b7db19d9d5e9ec8e5ea06210a598502 (diff)
downloadqtlocation-mapboxgl-89665326c2251608ac2f3408f73b781a23fb1ba5.tar.gz
[core] Add unit test for calculateTileDistances
Diffstat (limited to 'test/text')
-rw-r--r--test/text/calculate_tile_distances.test.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/text/calculate_tile_distances.test.cpp b/test/text/calculate_tile_distances.test.cpp
new file mode 100644
index 0000000000..990de3d4ec
--- /dev/null
+++ b/test/text/calculate_tile_distances.test.cpp
@@ -0,0 +1,27 @@
+#include <mbgl/test/util.hpp>
+
+#include <mbgl/geometry/anchor.hpp>
+#include <mbgl/layout/symbol_layout.hpp>
+#include <mbgl/tile/geometry_tile_data.hpp>
+
+using namespace mbgl;
+
+TEST(calculateTileDistances, Point) {
+ const GeometryCoordinates line = {Point<int16_t>{1, 1}};
+ const auto distances = SymbolLayout::calculateTileDistances(line, Anchor(1.0f, 1.0f, .0f, 0u));
+ EXPECT_EQ(distances.size(), 1u);
+ EXPECT_EQ(distances[0], .0f);
+}
+
+TEST(calculateTileDistances, Line) {
+ const GeometryCoordinates line = {
+ Point<int16_t>{1, 1}, Point<int16_t>{1, 2}, Point<int16_t>{1, 3}, Point<int16_t>{1, 4}};
+ const auto distances = SymbolLayout::calculateTileDistances(line, Anchor(1.0f, 3.0f, .0f, 2u));
+ EXPECT_EQ(distances, std::vector<float>({2.0f, 1.0f, 0.0f, 1.0f}));
+}
+
+TEST(calculateTileDistances, EmptySegment) {
+ const GeometryCoordinates line = {};
+ const auto distances = SymbolLayout::calculateTileDistances(line, Anchor(1.0f, 1.0f, .0f));
+ EXPECT_EQ(distances.size(), 0u);
+}