From b5954ef2de4f205108be0cf5a06f88540194bed9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 19 Aug 2018 14:58:14 +0200 Subject: Tighten up size constraints --- test/test_gray_code_rank.cpp | 47 ++++++++++++++++++++------------------------ test/test_hilbert.cpp | 6 +++--- test/test_utils.hpp | 2 +- 3 files changed, 25 insertions(+), 30 deletions(-) (limited to 'test') diff --git a/test/test_gray_code_rank.cpp b/test/test_gray_code_rank.cpp index 7980bf3..a421159 100644 --- a/test/test_gray_code_rank.cpp +++ b/test/test_gray_code_rank.cpp @@ -31,11 +31,11 @@ #include #include -template +template T get_mask(const std::array& ms, const size_t d, const size_t step) { - T mask = make_zero_bitvec(); + T mask = make_zero_bitvec(); size_t b; chilbert::extractMask(ms.data(), D, d, step, mask, b); @@ -44,15 +44,15 @@ get_mask(const std::array& ms, const size_t d, const size_t step) return mask; } -template +template void test_extract_mask(Context& ctx) { for (size_t d = 0; d < D; ++d) { - const auto ms = make_random_precisions(ctx); + const auto ms = make_random_precisions(ctx); const auto max_m = *std::max_element(std::begin(ms), std::end(ms)); const size_t step = rand_between(ctx, 0, max_m); - const auto mask = get_mask(ms, d, step); + const auto mask = get_mask(ms, d, step); for (size_t i = 0; i < D; ++i) { assert(mask.test(i) == (ms[(d + i) % D] > step)); @@ -60,20 +60,17 @@ test_extract_mask(Context& ctx) } } -template +template void test_gray_code_rank(Context& ctx) { for (size_t d = 0; d < D; ++d) { // Generate random mask - const auto ms = make_random_precisions(ctx); - const auto max_m = *std::max_element(std::begin(ms), std::end(ms)); - const size_t step = rand_between(ctx, 0, max_m); - const auto mask = get_mask(ms, d, step); + const auto mask = make_random_bitvec(ctx); // Generate two random values and their gray codes - const auto a = make_random_bitvec(ctx); - const auto b = make_random_bitvec(ctx); + const auto a = make_random_bitvec(ctx); + const auto b = make_random_bitvec(ctx); auto ga = a; grayCode(ga); @@ -82,19 +79,17 @@ test_gray_code_rank(Context& ctx) grayCode(gb); // Calculate gray code ranks - auto ra = make_zero_bitvec(); + auto ra = make_zero_bitvec(); chilbert::grayCodeRank(mask, ga, D, ra); - auto rb = make_zero_bitvec(); + auto rb = make_zero_bitvec(); chilbert::grayCodeRank(mask, gb, D, rb); // Ensure ranks have at most mask.count() bits - if (mask.count() < N) { - auto max = make_zero_bitvec(); - setBit(max, mask.count(), 1); - assert(ra < max); - assert(rb < max); - } + auto max = make_zero_bitvec(); + setBit(max, mask.count(), 1); + assert(ra < max); + assert(rb < max); // Test fundamental property of gray code ranks const auto mga = ga & mask; @@ -103,8 +98,8 @@ test_gray_code_rank(Context& ctx) // Test inversion const auto pat = ~mask; - auto ga_out = make_zero_bitvec(); - auto gag_out = make_zero_bitvec(); + auto ga_out = make_zero_bitvec(); + auto gag_out = make_zero_bitvec(); grayCodeRankInv(mask, pat, ra, D, mask.count(), gag_out, ga_out); assert((ga_out & mask) == (ga & mask)); @@ -114,12 +109,12 @@ test_gray_code_rank(Context& ctx) } } -template +template void test(Context& ctx) { - test_extract_mask(ctx); - test_gray_code_rank(ctx); + test_extract_mask(ctx); + test_gray_code_rank(ctx); } int @@ -140,7 +135,7 @@ main() test(ctx); test(ctx); test(ctx); - test(ctx); + test(ctx); test(ctx); return 0; diff --git a/test/test_hilbert.cpp b/test/test_hilbert.cpp index 20646a2..6a3d1b8 100644 --- a/test/test_hilbert.cpp +++ b/test/test_hilbert.cpp @@ -94,7 +94,7 @@ from_big_int(const mpz_class& num) return vec; } -template +template void test_standard(Context& ctx) { @@ -103,7 +103,7 @@ test_standard(Context& ctx) // Generate random point and its hilbert index const auto pa = make_random_point(ctx); - T ha = make_zero_bitvec(); + H ha = make_zero_bitvec(); assert(ha.size() >= D * M); chilbert::coordsToIndex(pa.data(), M, D, ha); @@ -119,7 +119,7 @@ test_standard(Context& ctx) // Generate the next hilbert index const auto ib = ia + 1; - const auto hb = from_big_int(ib); + const auto hb = from_big_int(ib); // Unmap next hilbert index to a point auto pb = make_random_point(ctx); diff --git a/test/test_utils.hpp b/test/test_utils.hpp index a695134..37db804 100644 --- a/test/test_utils.hpp +++ b/test/test_utils.hpp @@ -66,7 +66,7 @@ rand_between(Context& ctx, const size_t min, const size_t max) return r; } -/// Return an array of D precisions with sum at most N and each at most Max +/// Return an array of D precisions each at most Max and with sum at most N template std::array make_random_precisions(Context& ctx) -- cgit v1.2.1