From 72231250ed81e10d66bfe70701e64fa5fe50f712 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Wed, 15 Jun 2016 23:09:44 +0200 Subject: Publish --- vespalib/src/tests/zcurve/zcurve_ranges_test.cpp | 57 ++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 vespalib/src/tests/zcurve/zcurve_ranges_test.cpp (limited to 'vespalib/src/tests/zcurve/zcurve_ranges_test.cpp') diff --git a/vespalib/src/tests/zcurve/zcurve_ranges_test.cpp b/vespalib/src/tests/zcurve/zcurve_ranges_test.cpp new file mode 100644 index 00000000000..06112045dc2 --- /dev/null +++ b/vespalib/src/tests/zcurve/zcurve_ranges_test.cpp @@ -0,0 +1,57 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include +#include +#include + +typedef vespalib::geo::ZCurve Z; + +bool inside(int x, int y, const Z::RangeVector &ranges) { + int64_t z = Z::encode(x, y); + for (auto range: ranges) { + if (z >= range.min() && z <= range.max()) { + return true; + } + } + fprintf(stderr, "FAILED: (%d, %d) -> (%ld) not in:\n", x, y, z); + for (auto range: ranges) { + fprintf(stderr, " [%ld, %ld]\n", range.min(), range.max()); + } + return false; +} + +bool verify_ranges(int min_x, int min_y, int max_x, int max_y) { + Z::RangeVector ranges = Z::find_ranges(min_x, min_y, max_x, max_y); + for (int x = min_x; x <= max_x; ++x) { + for (int y = min_y; y <= max_y; ++y) { + if (!EXPECT_TRUE(inside(x, y, ranges))) { + return false; + } + } + } + return true; +} + +TEST("require that returned ranges contains bounding box") { + std::vector values({-13, -1, 0, 1, 13}); + for (auto min_x: values) { + for (auto min_y: values) { + for (auto max_x: values) { + for (auto max_y: values) { + if (max_x >= min_x && max_y >= min_y) { + if (!EXPECT_TRUE(verify_ranges(min_x, min_y, max_x, max_y))) { + fprintf(stderr, "BOX: (%d, %d) -> (%d, %d)\n", + min_x, min_y, max_x, max_y); + } + } + } + } + } + } +} + +TEST("require that silly bounding box does not explode") { + Z::RangeVector ranges = Z::find_ranges(-105, -7000000, 105, 7000000); + EXPECT_EQUAL(42u, ranges.size()); +} + +TEST_MAIN() { TEST_RUN_ALL(); } -- cgit v1.2.3