Skip to content

Commit

Permalink
deserialize CPC sketches from Java
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSaydakov committed Jul 22, 2023
1 parent 9975819 commit c8f289f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
19 changes: 13 additions & 6 deletions cpc/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ set_target_properties(cpc_test PROPERTIES
CXX_STANDARD_REQUIRED YES
)

#file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" CPC_TEST_BINARY_PATH)
#string(APPEND CPC_TEST_BINARY_PATH "/")
#target_compile_definitions(cpc_test
# PRIVATE
# TEST_BINARY_INPUT_PATH="${CPC_TEST_BINARY_PATH}"
#)
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" CPC_TEST_BINARY_PATH)
string(APPEND CPC_TEST_BINARY_PATH "/")
target_compile_definitions(cpc_test
PRIVATE
TEST_BINARY_INPUT_PATH="${CPC_TEST_BINARY_PATH}"
)

add_test(
NAME cpc_test
Expand All @@ -42,3 +42,10 @@ target_sources(cpc_test
compression_test.cpp
cpc_sketch_allocation_test.cpp
)

if (SERDE_COMPAT)
target_sources(cpc_test
PRIVATE
cpc_sketch_deserialize_from_java_test.cpp
)
endif()
40 changes: 40 additions & 0 deletions cpc/test/cpc_sketch_deserialize_from_java_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 <cpc_sketch.hpp>

namespace datasketches {

static std::string testBinaryInputPath = std::string(TEST_BINARY_INPUT_PATH) + "../../java/";

TEST_CASE("cpc sketch", "[serde_compat]") {
unsigned n_arr[] = {0, 100, 200, 2000, 20000};
for (unsigned n: n_arr) {
std::ifstream is;
is.exceptions(std::ios::failbit | std::ios::badbit);
is.open(testBinaryInputPath + "cpc_n" + std::to_string(n) + ".sk", std::ios::binary);
auto sketch = cpc_sketch::deserialize(is);
REQUIRE(sketch.is_empty() == (n == 0));
REQUIRE(sketch.get_estimate() == Approx(n).margin(n * 0.02));
}
}

} /* namespace datasketches */

0 comments on commit c8f289f

Please sign in to comment.