Skip to content

Commit 852b26b

Browse files
committed
test: add missing kll long sketch compatibility cases
1 parent 5a05552 commit 852b26b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

kll/test/kll_sketch_deserialize_from_java_test.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,28 @@ TEST_CASE("kll string", "[serde_compat]") {
100100
}
101101
}
102102

103+
TEST_CASE("kll long", "[serde_compat]") {
104+
const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
105+
for (const unsigned n: n_arr) {
106+
std::ifstream is;
107+
is.exceptions(std::ios::failbit | std::ios::badbit);
108+
is.open(testBinaryInputPath + "kll_long_n" + std::to_string(n) + "_java.sk", std::ios::binary);
109+
const auto sketch = kll_sketch<long>::deserialize(is);
110+
REQUIRE(sketch.is_empty() == (n == 0));
111+
REQUIRE(sketch.is_estimation_mode() == (n > kll_constants::DEFAULT_K));
112+
REQUIRE(sketch.get_n() == n);
113+
if (n > 0) {
114+
REQUIRE(sketch.get_min_item() == 1);
115+
REQUIRE(sketch.get_max_item() == static_cast<long>(n));
116+
uint64_t weight = 0;
117+
for (const auto pair: sketch) {
118+
REQUIRE(pair.first >= sketch.get_min_item());
119+
REQUIRE(pair.first <= sketch.get_max_item());
120+
weight += pair.second;
121+
}
122+
REQUIRE(weight == sketch.get_n());
123+
}
124+
}
125+
}
126+
103127
} /* namespace datasketches */

kll/test/kll_sketch_serialize_for_java.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ TEST_CASE("kll sketch double generate", "[serialize_for_java]") {
4343
}
4444
}
4545

46+
TEST_CASE("kll sketch long generate", "[serialize_for_java]") {
47+
const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
48+
for (const unsigned n: n_arr) {
49+
kll_sketch<long> sketch;
50+
for (unsigned i = 1; i <= n; ++i) sketch.update(i);
51+
std::ofstream os("kll_long_n" + std::to_string(n) + "_cpp.sk", std::ios::binary);
52+
sketch.serialize(os);
53+
}
54+
}
55+
4656
struct compare_as_number {
4757
bool operator()(const std::string& a, const std::string& b) const {
4858
return std::stoi(a) < std::stoi(b);

0 commit comments

Comments
 (0)