/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ #include #include #include namespace datasketches { // assume the binary sketches for this test have been generated by datasketches-java code // in the subdirectory called "java" in the root directory of this project static std::string testBinaryInputPath = std::string(TEST_BINARY_INPUT_PATH) + "../../java/"; TEST_CASE("cpc sketch", "[serde_compat]") { const unsigned n_arr[] = {0, 100, 200, 2000, 20000}; for (const unsigned n: n_arr) { std::ifstream is; is.exceptions(std::ios::failbit | std::ios::badbit); is.open(testBinaryInputPath + "cpc_n" + std::to_string(n) + "_java.sk", std::ios::binary); const auto sketch = cpc_sketch::deserialize(is); REQUIRE(sketch.is_empty() == (n == 0)); REQUIRE(sketch.get_estimate() == Approx(n).margin(n * 0.02)); } } TEST_CASE("cpc sketch negative one", "[serde_compat]") { std::ifstream is; is.exceptions(std::ios::failbit | std::ios::badbit); is.open(testBinaryInputPath + "cpc_negative_one_java.sk", std::ios::binary); auto sketch = cpc_sketch::deserialize(is); REQUIRE_FALSE(sketch.is_empty()); REQUIRE(sketch.get_estimate() == Approx(1).margin(0.01)); sketch.update((uint64_t) -1); sketch.update((int64_t) -1); sketch.update((uint32_t) -1); sketch.update((int32_t) -1); sketch.update((uint16_t) -1); sketch.update((int16_t) -1); sketch.update((uint8_t) -1); sketch.update((int8_t) -1); REQUIRE(sketch.get_estimate() == Approx(1).margin(0.01)); } } /* namespace datasketches */