Sha256: cd740cbef2c7ae5759915b934dfd9d255aa57c653036be75b15a5b2c45431ae8

Contents?: true

Size: 1.94 KB

Versions: 5

Compression:

Stored size: 1.94 KB

Contents

/*
 * 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 <catch2/catch.hpp>
#include <fstream>
#include <var_opt_union.hpp>

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("var opt union double", "[serde_compat]") {
  const double EPS = 1e-13;

  std::ifstream is;
  is.exceptions(std::ios::failbit | std::ios::badbit);
  is.open(testBinaryInputPath + "varopt_union_double_sampling_java.sk", std::ios::binary);
  auto u = var_opt_union<double>::deserialize(is);

  // must reduce k in the process
  const auto result = u.get_result();
  REQUIRE_FALSE(result.is_empty());
  REQUIRE(result.get_n() == 97);

  const double expected_wt = 96.0; // light items -- ignoring the heavy one
  const subset_summary ss = result.estimate_subset_sum([](double x){return x >= 0;});
  REQUIRE(ss.estimate == Approx(expected_wt).margin(EPS));
  REQUIRE(ss.total_sketch_weight == Approx(expected_wt + 1024.0).margin(EPS));
  REQUIRE(result.get_k() < 128);
}

} /* namespace datasketches */

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
datasketches-0.4.4 vendor/datasketches-cpp/sampling/test/var_opt_union_deserialize_from_java_test.cpp
datasketches-0.4.3 vendor/datasketches-cpp/sampling/test/var_opt_union_deserialize_from_java_test.cpp
datasketches-0.4.2 vendor/datasketches-cpp/sampling/test/var_opt_union_deserialize_from_java_test.cpp
datasketches-0.4.1 vendor/datasketches-cpp/sampling/test/var_opt_union_deserialize_from_java_test.cpp
datasketches-0.4.0 vendor/datasketches-cpp/sampling/test/var_opt_union_deserialize_from_java_test.cpp