#include <catch2/catch.hpp>
#include <fstream>
#include "array_of_doubles_sketch.hpp"
namespace datasketches {
static std::string testBinaryInputPath = std::string(TEST_BINARY_INPUT_PATH) + "../../java/";
TEST_CASE("aod sketch one value", "[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 + "aod_1_n" + std::to_string(n) + "_java.sk", std::ios::binary);
const auto sketch = compact_array_of_doubles_sketch::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));
REQUIRE(sketch.get_num_values() == 1);
for (const auto& entry: sketch) {
REQUIRE(entry.first < sketch.get_theta64());
}
}
}
TEST_CASE("aod sketch three values", "[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 + "aod_3_n" + std::to_string(n) + "_java.sk", std::ios::binary);
const auto sketch = compact_array_of_doubles_sketch::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));
REQUIRE(sketch.get_num_values() == 3);
for (const auto& entry: sketch) {
REQUIRE(entry.first < sketch.get_theta64());
REQUIRE(entry.second[0] == entry.second[1]);
REQUIRE(entry.second[0] == entry.second[2]);
}
}
}
TEST_CASE("aod sketch non-empty no entries", "[serde_compat]") {
std::ifstream is;
is.exceptions(std::ios::failbit | std::ios::badbit);
is.open(testBinaryInputPath + "aod_1_non_empty_no_entries_java.sk", std::ios::binary);
const auto sketch = compact_array_of_doubles_sketch::deserialize(is);
REQUIRE_FALSE(sketch.is_empty());
REQUIRE(sketch.get_num_retained() == 0);
}
}