This is an automated email from the ASF dual-hosted git repository.

alsay pushed a commit to branch generate_sketches_for_java
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git

commit 69eef1a73440961fdf8f098122f74f14ebb5d16b
Author: AlexanderSaydakov <[email protected]>
AuthorDate: Wed Aug 23 17:57:05 2023 -0700

    generate binary sketches to test compatibility
---
 cpc/test/CMakeLists.txt                            |  7 ++
 cpc/test/cpc_sketch_serialize_for_java.cpp         | 38 ++++++++++
 fi/test/CMakeLists.txt                             |  7 ++
 .../frequent_items_sketch_serialize_for_java.cpp   | 83 ++++++++++++++++++++++
 hll/test/CMakeLists.txt                            |  7 ++
 hll/test/hll_sketch_serialize_for_java.cpp         | 52 ++++++++++++++
 kll/test/CMakeLists.txt                            |  7 ++
 kll/test/kll_sketch_serialize_for_java.cpp         | 62 ++++++++++++++++
 8 files changed, 263 insertions(+)

diff --git a/cpc/test/CMakeLists.txt b/cpc/test/CMakeLists.txt
index 2d3af9b..645ce12 100644
--- a/cpc/test/CMakeLists.txt
+++ b/cpc/test/CMakeLists.txt
@@ -49,3 +49,10 @@ target_sources(cpc_test
     cpc_sketch_deserialize_from_java_test.cpp
 )
 endif()
+
+if (GENERATE)
+target_sources(cpc_test
+  PRIVATE
+    cpc_sketch_serialize_for_java.cpp
+)
+endif()
diff --git a/cpc/test/cpc_sketch_serialize_for_java.cpp 
b/cpc/test/cpc_sketch_serialize_for_java.cpp
new file mode 100644
index 0000000..d46fa04
--- /dev/null
+++ b/cpc/test/cpc_sketch_serialize_for_java.cpp
@@ -0,0 +1,38 @@
+/*
+ * 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 {
+
+TEST_CASE("cpc sketch generate", "[serialize_for_java]") {
+  const unsigned n_arr[] = {0, 100, 200, 2000, 20000};
+  for (const unsigned n: n_arr) {
+    cpc_sketch sketch;
+    for (unsigned i = 1; i <= n; ++i) sketch.update(i);
+    REQUIRE(sketch.is_empty() == (n == 0));
+    REQUIRE(sketch.get_estimate() == Approx(n).margin(n * 0.02));
+    std::ofstream os("cpc_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+    sketch.serialize(os);
+  }
+}
+
+} /* namespace datasketches */
diff --git a/fi/test/CMakeLists.txt b/fi/test/CMakeLists.txt
index fc8780d..0279b03 100644
--- a/fi/test/CMakeLists.txt
+++ b/fi/test/CMakeLists.txt
@@ -48,3 +48,10 @@ target_sources(fi_test
    frequent_items_sketch_deserialize_from_java_test.cpp
 )
 endif()
+
+if (GENERATE)
+target_sources(fi_test
+  PRIVATE
+   frequent_items_sketch_serialize_for_java.cpp
+)
+endif()
diff --git a/fi/test/frequent_items_sketch_serialize_for_java.cpp 
b/fi/test/frequent_items_sketch_serialize_for_java.cpp
new file mode 100644
index 0000000..a2a7735
--- /dev/null
+++ b/fi/test/frequent_items_sketch_serialize_for_java.cpp
@@ -0,0 +1,83 @@
+/*
+ * 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 <frequent_items_sketch.hpp>
+
+namespace datasketches {
+
+TEST_CASE("frequent longs sketch generate", "[serialize_for_java]") {
+  const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+  for (const unsigned n: n_arr) {
+    frequent_items_sketch<long> sketch(6);
+    for (unsigned i = 1; i <= n; ++i) sketch.update(i);
+    REQUIRE(sketch.is_empty() == (n == 0));
+    if (n > 10) {
+      REQUIRE(sketch.get_maximum_error() > 0);
+    } else {
+      REQUIRE(sketch.get_maximum_error() == 0);
+    }
+    REQUIRE(sketch.get_total_weight() == n);
+    std::ofstream os("frequent_long_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+    sketch.serialize(os);
+  }
+}
+
+TEST_CASE("frequent strings sketch generate", "[serialize_for_java]") {
+  const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+  for (const unsigned n: n_arr) {
+    frequent_items_sketch<std::string> sketch(6);
+    for (unsigned i = 1; i <= n; ++i) sketch.update(std::to_string(i));
+    REQUIRE(sketch.is_empty() == (n == 0));
+    if (n > 10) {
+//      REQUIRE(sketch.get_maximum_error() > 0);
+    } else {
+      REQUIRE(sketch.get_maximum_error() == 0);
+    }
+    REQUIRE(sketch.get_total_weight() == n);
+    std::ofstream os("frequent_string_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+    sketch.serialize(os);
+  }
+}
+
+TEST_CASE("frequent strings sketch ascii", "[serialize_for_java]") {
+  frequent_items_sketch<std::string> sketch(6);
+  sketch.update("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1);
+  sketch.update("bbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 2);
+  sketch.update("ccccccccccccccccccccccccccccc", 3);
+  sketch.update("ddddddddddddddddddddddddddddd", 4);
+  std::ofstream os("frequent_string_ascii_cpp.sk", std::ios::binary);
+  sketch.serialize(os);
+}
+
+TEST_CASE("frequent strings sketch utf8", "[serialize_for_java]") {
+  frequent_items_sketch<std::string> sketch(6);
+  sketch.update("абвгд", 1);
+  sketch.update("еёжзи", 2);
+  sketch.update("йклмн", 3);
+  sketch.update("опрст", 4);
+  sketch.update("уфхцч", 5);
+  sketch.update("шщъыь", 6);
+  sketch.update("эюя", 7);
+  std::ofstream os("frequent_string_utf8_cpp.sk", std::ios::binary);
+  sketch.serialize(os);
+}
+
+} /* namespace datasketches */
diff --git a/hll/test/CMakeLists.txt b/hll/test/CMakeLists.txt
index 202560f..efdc521 100644
--- a/hll/test/CMakeLists.txt
+++ b/hll/test/CMakeLists.txt
@@ -55,3 +55,10 @@ target_sources(hll_test
    hll_sketch_deserialize_from_java_test.cpp
 )
 endif()
+
+if (GENERATE)
+target_sources(hll_test
+  PRIVATE
+   hll_sketch_serialize_for_java.cpp
+)
+endif()
diff --git a/hll/test/hll_sketch_serialize_for_java.cpp 
b/hll/test/hll_sketch_serialize_for_java.cpp
new file mode 100644
index 0000000..e329c58
--- /dev/null
+++ b/hll/test/hll_sketch_serialize_for_java.cpp
@@ -0,0 +1,52 @@
+/*
+ * 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 <hll.hpp>
+
+namespace datasketches {
+
+TEST_CASE("hll sketch generate", "[serialize_for_java]") {
+  const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+  for (const unsigned n: n_arr) {
+    hll_sketch hll4(12, HLL_4);
+    hll_sketch hll6(12, HLL_6);
+    hll_sketch hll8(12, HLL_8);
+    for (unsigned i = 0; i < n; ++i) {
+      hll4.update(i);
+      hll6.update(i);
+      hll8.update(i);
+    }
+    {
+      std::ofstream os("hll4_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+      hll4.serialize_compact(os);
+    }
+    {
+      std::ofstream os("hll6_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+      hll6.serialize_compact(os);
+    }
+    {
+      std::ofstream os("hll8_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+      hll8.serialize_compact(os);
+    }
+  }
+}
+
+} /* namespace datasketches */
diff --git a/kll/test/CMakeLists.txt b/kll/test/CMakeLists.txt
index 1701853..1e6f6f9 100644
--- a/kll/test/CMakeLists.txt
+++ b/kll/test/CMakeLists.txt
@@ -49,3 +49,10 @@ target_sources(kll_test
     kll_sketch_deserialize_from_java_test.cpp
 )
 endif()
+
+if (GENERATE)
+target_sources(kll_test
+  PRIVATE
+    kll_sketch_serialize_for_java.cpp
+)
+endif()
diff --git a/kll/test/kll_sketch_serialize_for_java.cpp 
b/kll/test/kll_sketch_serialize_for_java.cpp
new file mode 100644
index 0000000..00b8913
--- /dev/null
+++ b/kll/test/kll_sketch_serialize_for_java.cpp
@@ -0,0 +1,62 @@
+/*
+ * 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 <kll_sketch.hpp>
+
+namespace datasketches {
+
+TEST_CASE("kll sketch float generate", "[serialize_for_java]") {
+  const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+  for (const unsigned n: n_arr) {
+    kll_sketch<float> sketch;
+    for (unsigned i = 1; i <= n; ++i) sketch.update(i);
+    std::ofstream os("kll_float_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+    sketch.serialize(os);
+  }
+}
+
+TEST_CASE("kll sketch double generate", "[serialize_for_java]") {
+  const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+  for (const unsigned n: n_arr) {
+    kll_sketch<double> sketch;
+    for (unsigned i = 1; i <= n; ++i) sketch.update(i);
+    std::ofstream os("kll_double_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+    sketch.serialize(os);
+  }
+}
+
+struct compare_as_number {
+  bool operator()(const std::string& a, const std::string& b) const {
+    return std::stoi(a) < std::stoi(b);
+  }
+};
+
+TEST_CASE("kll sketch string generate", "[serialize_for_java]") {
+  const unsigned n_arr[] = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
+  for (const unsigned n: n_arr) {
+    kll_sketch<std::string, compare_as_number> sketch;
+    for (unsigned i = 1; i <= n; ++i) sketch.update(std::to_string(i));
+    std::ofstream os("kll_string_n" + std::to_string(n) + "_cpp.sk", 
std::ios::binary);
+    sketch.serialize(os);
+  }
+}
+
+} /* namespace datasketches */


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to