Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions kll/test/kll_sketch_deserialize_from_java_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,28 @@ TEST_CASE("kll string", "[serde_compat]") {
}
}

TEST_CASE("kll long", "[serde_compat]") {
const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
for (const unsigned n: n_arr) {
std::ifstream is;
is.exceptions(std::ios::failbit | std::ios::badbit);
is.open(testBinaryInputPath + "kll_long_n" + std::to_string(n) + "_java.sk", std::ios::binary);
const auto sketch = kll_sketch<long>::deserialize(is);
REQUIRE(sketch.is_empty() == (n == 0));
REQUIRE(sketch.is_estimation_mode() == (n > kll_constants::DEFAULT_K));
REQUIRE(sketch.get_n() == n);
if (n > 0) {
REQUIRE(sketch.get_min_item() == 1);
REQUIRE(sketch.get_max_item() == static_cast<long>(n));
uint64_t weight = 0;
for (const auto pair: sketch) {
REQUIRE(pair.first >= sketch.get_min_item());
REQUIRE(pair.first <= sketch.get_max_item());
weight += pair.second;
}
REQUIRE(weight == sketch.get_n());
}
}
}

} /* namespace datasketches */
10 changes: 10 additions & 0 deletions kll/test/kll_sketch_serialize_for_java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ TEST_CASE("kll sketch double generate", "[serialize_for_java]") {
}
}

TEST_CASE("kll sketch long generate", "[serialize_for_java]") {
const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
for (const unsigned n: n_arr) {
kll_sketch<long> sketch;
for (unsigned i = 1; i <= n; ++i) sketch.update(i);
std::ofstream os("kll_long_n" + std::to_string(n) + "_cpp.sk", std::ios::binary);
sketch.serialize(os);
}
}

struct compare_as_number {
bool operator()(const std::string& a, const std::string& b) const {
return std::stoi(a) < std::stoi(b);
Expand Down