You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by jm...@apache.org on 2019/09/17 22:51:34 UTC
[incubator-datasketches-cpp] 01/04: partial hll test coverage in
python
This is an automated email from the ASF dual-hosted git repository.
jmalkin pushed a commit to branch py_test
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-cpp.git
commit b5346d0ef9b2c8154677daeb82c224892cc15b4b
Author: jmalkin <jm...@users.noreply.github.com>
AuthorDate: Wed Aug 28 15:12:37 2019 -0700
partial hll test coverage in python
---
python/CMakeLists.txt | 1 -
python/tests/__init__.py | 0
python/tests/hll_test.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++
python/tests/hll_test.py~ | 14 ++++++++++
setup.py | 1 +
5 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index cce67cc..ad004d7 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -6,7 +6,6 @@ else()
endif()
add_subdirectory(pybind11)
-message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIRS}")
pybind11_add_module(python MODULE EXCLUDE_FROM_ALL SYSTEM THIN_LTO)
diff --git a/python/tests/__init__.py b/python/tests/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/python/tests/hll_test.py b/python/tests/hll_test.py
new file mode 100644
index 0000000..431c543
--- /dev/null
+++ b/python/tests/hll_test.py
@@ -0,0 +1,66 @@
+import unittest
+from datasketches import hll_sketch, hll_union, tgt_hll_type
+
+class HllTest(unittest.TestCase):
+ def test_hll_sketch(self):
+ k = 8
+ n = 117
+ hll = generate_sketch(n, k, tgt_hll_type.HLL_6)
+ hll.update('string data')
+ hll.update(3.14159) # double data
+
+ self.assertLessEqual(hll.get_lower_bound(1), hll.get_estimate())
+ self.assertLessEqual(hll.get_lower_bound(1), hll.get_composite_estimate())
+ self.assertGreaterEqual(hll.get_upper_bound(1), hll.get_estimate())
+ self.assertGreaterEqual(hll.get_upper_bound(1), hll.get_composite_estimate())
+
+ self.assertEqual(hll.lg_config_k, k)
+ self.assertEqual(hll.tgt_type, tgt_hll_type.HLL_6)
+
+ bytes_compact = hll.serialize_compact()
+ bytes_update = hll.serialize_updatable()
+ self.assertEqual(len(bytes_compact), hll.get_compact_serialization_bytes())
+ self.assertEqual(len(bytes_update), hll.get_updatable_serialization_bytes())
+
+ self.assertFalse(hll.is_compact())
+ self.assertFalse(hll.is_empty())
+
+ self.assertIsNotNone(hll_sketch.get_rel_err(True, False, 12, 1))
+ self.assertIsNotNone(hll_sketch.get_max_updatable_serialization_bytes(20, tgt_hll_type.HLL_6))
+
+ hll.reset()
+ self.assertTrue(hll.is_empty())
+
+ def generate_sketch(self, n, k, type=tgt_hll_type.HLL_4, st_idx=0):
+ sk = hll_sketch(k, type)
+ for i in range(st_idx, st_idx + n):
+ sk.update(i)
+ return sk
+
+ def test_hll_union(self):
+ k = 7
+ n = 53
+ union = hll_union(k)
+
+ sk = self.generate_sketch(n, k, tgt_hll_type.HLL_4, 0)
+ union.update(sk)
+ sk = self.generate_sketch(3 * n, k, tgt_hll_type.HLL_4, n)
+ union.update(sk)
+ union.update('string data')
+ union.update(1.4142136)
+
+ self.assertLessEqual(union.get_lower_bound(1), union.get_estimate())
+ self.assertLessEqual(union.get_lower_bound(1), union.get_composite_estimate())
+ self.assertGreaterEqual(union.get_upper_bound(1), union.get_estimate())
+ self.assertGreaterEqual(union.get_upper_bound(1), union.get_composite_estimate())
+
+ self.assertEqual(union.lg_config_k, k)
+ self.assertFalse(union.is_compact())
+ self.assertFalse(union.is_empty())
+
+
+
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/python/tests/hll_test.py~ b/python/tests/hll_test.py~
new file mode 100644
index 0000000..9847169
--- /dev/null
+++ b/python/tests/hll_test.py~
@@ -0,0 +1,14 @@
+import unittest
+import datasketches # our `pybind11`-based extension module
+
+class MainTest(unittest.TestCase):
+ def test_add(self):
+ # test that 1 + 1 = 2
+ self.assertEqual(python_cpp_example.add(1, 1), 2)
+
+ def test_subtract(self):
+ # test that 1 - 1 = 0
+ self.assertEqual(python_cpp_example.subtract(1, 1), 0)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/setup.py b/setup.py
index c941ade..aaa9015 100644
--- a/setup.py
+++ b/setup.py
@@ -75,6 +75,7 @@ setup(
long_description=open('python/README.md').read(),
packages=find_packages('python'), # python pacakges only in this dir
package_dir={'':'python'},
+ test_suite='python.tests',
# may need to add all source paths for sdist packages w/o MANIFEST.in
ext_modules=[CMakeExtension('datasketches')],
cmdclass={'build_ext': CMakeBuild},
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org