Skip to content

Commit

Permalink
Merge pull request #437 from apache/minor_cleanup
Browse files Browse the repository at this point in the history
minor cleanup
  • Loading branch information
AlexanderSaydakov authored Jul 29, 2024
2 parents a8348c2 + 5a334d4 commit 7d3f7df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
11 changes: 6 additions & 5 deletions kll/test/kll_sketch_custom_type_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ using alloc = test_allocator<test_type>;

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);
Expand Down Expand Up @@ -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 */
17 changes: 9 additions & 8 deletions theta/test/bit_packing_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t> input(8, 0);
std::vector<uint64_t> 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<uint8_t> bytes(8 * sizeof(uint64_t), 0);
std::vector<uint8_t> 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<uint64_t> output(8, 0);
std::vector<uint64_t> 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]);
}
}
}
Expand Down

0 comments on commit 7d3f7df

Please sign in to comment.