#include <catch2/catch.hpp>
#include <fstream>
#include <tuple_sketch.hpp>
namespace datasketches {
static std::string testBinaryInputPath = std::string(TEST_BINARY_INPUT_PATH) + "../../java/";
TEST_CASE("tuple sketch int", "[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 + "tuple_int_n" + std::to_string(n) + "_java.sk", std::ios::binary);
const auto sketch = compact_tuple_sketch<int>::deserialize(is);
REQUIRE(sketch.is_empty() == (n == 0));
REQUIRE(sketch.is_estimation_mode() == (n > 1000));
REQUIRE(sketch.get_estimate() == Approx(n).margin(n * 0.03));
for (const auto& entry: sketch) {
REQUIRE(entry.first < sketch.get_theta64());
REQUIRE(entry.second < static_cast<int>(n));
}
}
}
}