From 5a334d4acdc28a1d99182ed15db21655cab56422 Mon Sep 17 00:00:00 2001 From: AlexanderSaydakov Date: Fri, 26 Jul 2024 18:05:36 -0700 Subject: [PATCH] minor cleanup --- kll/test/kll_sketch_custom_type_test.cpp | 11 ++++++----- theta/test/bit_packing_test.cpp | 17 +++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/kll/test/kll_sketch_custom_type_test.cpp b/kll/test/kll_sketch_custom_type_test.cpp index 784197db..f9d6f3cd 100644 --- a/kll/test/kll_sketch_custom_type_test.cpp +++ b/kll/test/kll_sketch_custom_type_test.cpp @@ -31,11 +31,14 @@ using alloc = test_allocator; TEST_CASE("kll sketch custom type", "[kll_sketch]") { - // setup section test_allocator_total_bytes = 0; + test_allocator_net_allocations = 0; SECTION("compact level zero") { kll_test_type_sketch sketch(8, test_type_less(), 0); + REQUIRE(test_allocator_total_bytes != 0); + REQUIRE(test_allocator_net_allocations != 0); + REQUIRE_THROWS_AS(sketch.get_quantile(0), std::runtime_error); REQUIRE_THROWS_AS(sketch.get_min_item(), std::runtime_error); REQUIRE_THROWS_AS(sketch.get_max_item(), std::runtime_error); @@ -146,10 +149,8 @@ TEST_CASE("kll sketch custom type", "[kll_sketch]") { REQUIRE(sketch2.get_n() == 11); } - // cleanup - if (test_allocator_total_bytes != 0) { - REQUIRE(test_allocator_total_bytes == 0); - } + REQUIRE(test_allocator_total_bytes == 0); + REQUIRE(test_allocator_net_allocations == 0); } } /* namespace datasketches */ diff --git a/theta/test/bit_packing_test.cpp b/theta/test/bit_packing_test.cpp index 0273280c..2e25a4af 100644 --- a/theta/test/bit_packing_test.cpp +++ b/theta/test/bit_packing_test.cpp @@ -30,29 +30,30 @@ static const uint64_t IGOLDEN64 = 0x9e3779b97f4a7c13ULL; TEST_CASE("pack unpack bits") { for (uint8_t bits = 1; bits <= 63; ++bits) { + int n = 8; const uint64_t mask = (1ULL << bits) - 1; - std::vector input(8, 0); + std::vector input(n, 0); const uint64_t igolden64 = IGOLDEN64; uint64_t value = 0xaa55aa55aa55aa55ULL; // arbitrary starting value - for (int i = 0; i < 8; ++i) { + for (int i = 0; i < n; ++i) { input[i] = value & mask; value += igolden64; } - std::vector bytes(8 * sizeof(uint64_t), 0); + std::vector bytes(n * sizeof(uint64_t), 0); uint8_t offset = 0; uint8_t* ptr = bytes.data(); - for (int i = 0; i < 8; ++i) { + for (int i = 0; i < n; ++i) { offset = pack_bits(input[i], bits, ptr, offset); } - std::vector output(8, 0); + std::vector output(n, 0); offset = 0; const uint8_t* cptr = bytes.data(); - for (int i = 0; i < 8; ++i) { + for (int i = 0; i < n; ++i) { offset = unpack_bits(output[i], bits, cptr, offset); } - for (int i = 0; i < 8; ++i) { - REQUIRE((input[i] & mask) == output[i]); + for (int i = 0; i < n; ++i) { + REQUIRE(input[i] == output[i]); } } }