You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by al...@apache.org on 2020/07/07 23:53:03 UTC

[incubator-datasketches-cpp] branch tuple_sketch updated: tests

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

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


The following commit(s) were added to refs/heads/tuple_sketch by this push:
     new 7516f68  tests
7516f68 is described below

commit 7516f689b5f991efb2479ce4b75f097ebf1134b2
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Jul 7 16:52:50 2020 -0700

    tests
---
 tuple/test/tuple_a_not_b_test.cpp | 245 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 245 insertions(+)

diff --git a/tuple/test/tuple_a_not_b_test.cpp b/tuple/test/tuple_a_not_b_test.cpp
new file mode 100644
index 0000000..7e44d2e
--- /dev/null
+++ b/tuple/test/tuple_a_not_b_test.cpp
@@ -0,0 +1,245 @@
+/*
+ * 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 <iostream>
+
+#include <catch.hpp>
+#include <tuple_a_not_b.hpp>
+
+namespace datasketches {
+
+TEST_CASE("tuple a-not-b: empty", "[tuple_a_not_b]") {
+  auto a = update_tuple_sketch<float>::builder().build();
+  auto b = update_tuple_sketch<float>::builder().build();
+  tuple_a_not_b<float> a_not_b;
+  auto result = a_not_b.compute(a, b);
+  REQUIRE(result.get_num_retained() == 0);
+  REQUIRE(result.is_empty());
+  REQUIRE_FALSE(result.is_estimation_mode());
+  REQUIRE(result.get_estimate() == 0.0);
+}
+
+TEST_CASE("tuple a-not-b: non empty no retained keys", "[tuple_a_not_b]") {
+  auto a = update_tuple_sketch<float>::builder().build();
+  a.update(1, 1);
+  auto b = update_tuple_sketch<float>::builder().set_p(0.001).build();
+  tuple_a_not_b<float> a_not_b;
+
+  // B is still empty
+  auto result = a_not_b.compute(a, b);
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE_FALSE(result.is_estimation_mode());
+  REQUIRE(result.get_num_retained() == 1);
+  REQUIRE(result.get_theta() == Approx(1).margin(1e-10));
+  REQUIRE(result.get_estimate() == 1.0);
+
+  // B is not empty in estimation mode and no entries
+  b.update(1, 1);
+  REQUIRE(b.get_num_retained() == 0);
+
+  result = a_not_b.compute(a, b);
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE(result.is_estimation_mode());
+  REQUIRE(result.get_num_retained() == 0);
+  REQUIRE(result.get_theta() == Approx(0.001).margin(1e-10));
+  REQUIRE(result.get_estimate() == 0.0);
+}
+
+TEST_CASE("tuple a-not-b: exact mode half overlap", "[tuple_a_not_b]") {
+  auto a = update_tuple_sketch<float>::builder().build();
+  int value = 0;
+  for (int i = 0; i < 1000; i++) a.update(value++, 1);
+
+  auto b = update_tuple_sketch<float>::builder().build();
+  value = 500;
+  for (int i = 0; i < 1000; i++) b.update(value++, 1);
+
+  tuple_a_not_b<float> a_not_b;
+
+  // unordered inputs, ordered result
+  auto result = a_not_b.compute(a, b);
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE_FALSE(result.is_estimation_mode());
+  REQUIRE(result.is_ordered());
+  REQUIRE(result.get_estimate() == 500.0);
+
+  // unordered inputs, unordered result
+  result = a_not_b.compute(a, b, false);
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE_FALSE(result.is_estimation_mode());
+  REQUIRE_FALSE(result.is_ordered());
+  REQUIRE(result.get_estimate() == 500.0);
+
+  // ordered inputs
+  result = a_not_b.compute(a.compact(), b.compact());
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE_FALSE(result.is_estimation_mode());
+  REQUIRE(result.is_ordered());
+  REQUIRE(result.get_estimate() == 500.0);
+
+  // A is ordered, so the result is ordered regardless
+  result = a_not_b.compute(a.compact(), b, false);
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE_FALSE(result.is_estimation_mode());
+  REQUIRE(result.is_ordered());
+  REQUIRE(result.get_estimate() == 500.0);
+}
+
+TEST_CASE("tuple a-not-b: exact mode disjoint", "[tuple_a_not_b]") {
+  auto a = update_tuple_sketch<float>::builder().build();
+  int value = 0;
+  for (int i = 0; i < 1000; i++) a.update(value++, 1);
+
+  auto b = update_tuple_sketch<float>::builder().build();
+  for (int i = 0; i < 1000; i++) b.update(value++, 1);
+
+  tuple_a_not_b<float> a_not_b;
+
+  // unordered inputs
+  auto result = a_not_b.compute(a, b);
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE_FALSE(result.is_estimation_mode());
+  REQUIRE(result.get_estimate() == 1000.0);
+
+  // ordered inputs
+  result = a_not_b.compute(a.compact(), b.compact());
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE_FALSE(result.is_estimation_mode());
+  REQUIRE(result.get_estimate() == 1000.0);
+}
+
+TEST_CASE("tuple a-not-b: exact mode full overlap", "[tuple_a_not_b]") {
+  auto sketch = update_tuple_sketch<float>::builder().build();
+  int value = 0;
+  for (int i = 0; i < 1000; i++) sketch.update(value++, 1);
+
+  tuple_a_not_b<float> a_not_b;
+
+  // unordered inputs
+  auto result = a_not_b.compute(sketch, sketch);
+  REQUIRE(result.is_empty());
+  REQUIRE_FALSE(result.is_estimation_mode());
+  REQUIRE(result.get_estimate() == 0.0);
+
+  // ordered inputs
+  result = a_not_b.compute(sketch.compact(), sketch.compact());
+  REQUIRE(result.is_empty());
+  REQUIRE_FALSE(result.is_estimation_mode());
+  REQUIRE(result.get_estimate() == 0.0);
+}
+
+TEST_CASE("tuple a-not-b: estimation mode half overlap", "[tuple_a_not_b]") {
+  auto a = update_tuple_sketch<float>::builder().build();
+  int value = 0;
+  for (int i = 0; i < 10000; i++) a.update(value++, 1);
+
+  auto b = update_tuple_sketch<float>::builder().build();
+  value = 5000;
+  for (int i = 0; i < 10000; i++) b.update(value++, 1);
+
+  tuple_a_not_b<float> a_not_b;
+
+  // unordered inputs
+  auto result = a_not_b.compute(a, b);
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE(result.is_estimation_mode());
+  REQUIRE(result.get_estimate() == Approx(5000).margin(5000 * 0.02));
+
+  // ordered inputs
+  result = a_not_b.compute(a.compact(), b.compact());
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE(result.is_estimation_mode());
+  REQUIRE(result.get_estimate() == Approx(5000).margin(5000 * 0.02));
+}
+
+TEST_CASE("tuple a-not-b: estimation mode disjoint", "[tuple_a_not_b]") {
+  auto a = update_tuple_sketch<float>::builder().build();
+  int value = 0;
+  for (int i = 0; i < 10000; i++) a.update(value++, 1);
+
+  auto b = update_tuple_sketch<float>::builder().build();
+  for (int i = 0; i < 10000; i++) b.update(value++, 1);
+
+  tuple_a_not_b<float> a_not_b;
+
+  // unordered inputs
+  auto result = a_not_b.compute(a, b);
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE(result.is_estimation_mode());
+  REQUIRE(result.get_estimate() == Approx(10000).margin(10000 * 0.02));
+
+  // ordered inputs
+  result = a_not_b.compute(a.compact(), b.compact());
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE(result.is_estimation_mode());
+  REQUIRE(result.get_estimate() == Approx(10000).margin(10000 * 0.02));
+}
+
+TEST_CASE("tuple a-not-b: estimation mode full overlap", "[tuple_a_not_b]") {
+  auto sketch = update_tuple_sketch<float>::builder().build();
+  int value = 0;
+  for (int i = 0; i < 10000; i++) sketch.update(value++, 1);
+
+  tuple_a_not_b<float> a_not_b;
+
+  // unordered inputs
+  auto result = a_not_b.compute(sketch, sketch);
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE(result.is_estimation_mode());
+  REQUIRE(result.get_estimate() == 0.0);
+
+  // ordered inputs
+  result = a_not_b.compute(sketch.compact(), sketch.compact());
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE(result.is_estimation_mode());
+  REQUIRE(result.get_estimate() == 0.0);
+}
+
+TEST_CASE("tuple a-not-b: seed mismatch", "[tuple_a_not_b]") {
+  auto sketch = update_tuple_sketch<float>::builder().build();
+  sketch.update(1, 1); // non-empty should not be ignored
+  tuple_a_not_b<float> a_not_b(123);
+  REQUIRE_THROWS_AS(a_not_b.compute(sketch, sketch), std::invalid_argument);
+}
+
+TEST_CASE("tuple a-not-b: issue #152", "[tuple_a_not_b]") {
+  auto a = update_tuple_sketch<float>::builder().build();
+  int value = 0;
+  for (int i = 0; i < 10000; i++) a.update(value++, 1);
+
+  auto b = update_tuple_sketch<float>::builder().build();
+  value = 5000;
+  for (int i = 0; i < 25000; i++) b.update(value++, 1);
+
+  tuple_a_not_b<float> a_not_b;
+
+  // unordered inputs
+  auto result = a_not_b.compute(a, b);
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE(result.is_estimation_mode());
+  REQUIRE(result.get_estimate() == Approx(5000).margin(5000 * 0.03));
+
+  // ordered inputs
+  result = a_not_b.compute(a.compact(), b.compact());
+  REQUIRE_FALSE(result.is_empty());
+  REQUIRE(result.is_estimation_mode());
+  REQUIRE(result.get_estimate() == Approx(5000).margin(5000 * 0.03));
+}
+
+} /* namespace datasketches */


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org