diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /vespalib/src/tests/zcurve/zcurve_ranges_test.cpp |
Publish
Diffstat (limited to 'vespalib/src/tests/zcurve/zcurve_ranges_test.cpp')
-rw-r--r-- | vespalib/src/tests/zcurve/zcurve_ranges_test.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
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 <vespa/vespalib/testkit/test_kit.h> +#include <vespa/vespalib/geo/zcurve.h> +#include <vector> + +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<int> 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(); } |