{ "cells": [ { "cell_type": "code", "execution_count": 17, "id": "dbcd1beb", "metadata": {}, "outputs": [], "source": [ "minimum_precision = 4\n", "# THIS IS AN INCLUSIVE RANGE!!\n", "maximum_precision = 17" ] }, { "cell_type": "code", "execution_count": 18, "id": "a3291467", "metadata": {}, "outputs": [], "source": [ "header = \"\"\"\n", "use hyperloglog_rs::prelude::*;\n", "\n", "\"\"\"\n", "\n", "test = \"\"\"\n", "#[test]\n", "pub fn test_hyper_log_log_at_precision_{precision}_and_bits_{bits}() {{\n", " type P = Precision{precision};\n", " const BITS: usize = {bits};\n", " \n", " for number_of_elements in [\n", " 5, 10, 15, 100, 200, 1000, 10_000, 100_000, 1_000_000\n", " ]{{\n", " if BITS <= 4 && {precision} <= 5 && number_of_elements > 10_000{{\n", " continue;\n", " }}\n", " \n", " let mut hll: HyperLogLog<P, BITS> = HyperLogLog::default();\n", " let hll_default: HyperLogLog<P, BITS> = HyperLogLog::default();\n", " \n", " assert_eq!(hll, hll_default);\n", " \n", " assert_eq!(hll.get_number_of_bits(), BITS);\n", " assert!(hll.is_empty());\n", "\n", " for i in 0..number_of_elements {{\n", " hll.insert(i);\n", " assert!(hll.may_contain(&i));\n", " }}\n", " \n", " assert!(!hll.is_empty());\n", "\n", " assert!(\n", " hll.estimate_cardinality() >= number_of_elements as f32 * 7.0_f32 / 10.0_f32,\n", " concat!(\n", " \"Obtained: {{}}, Expected around: {{}}. \",\n", " ),\n", " hll.estimate_cardinality(), number_of_elements,\n", " );\n", "\n", " assert!(\n", " hll.estimate_cardinality() <= number_of_elements as f32 * 14.0_f32 / 10.0_f32,\n", " concat!(\n", " \"Obtained: {{}}, Expected around: {{}}. \",\n", " ),\n", " hll.estimate_cardinality(), number_of_elements,\n", " );\n", " }}\n", "}}\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": 19, "id": "466efaab", "metadata": {}, "outputs": [], "source": [ "for precision in range(minimum_precision, maximum_precision + 1):\n", " tests=[]\n", " for bits_per_register in (4, 5, 6):\n", " tests.append(test.format(\n", " precision=precision,\n", " bits=bits_per_register\n", " ))\n", " with open(f\"tests/test_hll_{precision}.rs\", \"w\") as f:\n", " f.write(header + \"\\n\\n\".join(tests))" ] }, { "cell_type": "code", "execution_count": null, "id": "94e14613", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.13" } }, "nbformat": 4, "nbformat_minor": 5 }