public void HllNormalMergeNullErrorTest()
        {
            HyperLogLog hll1 = new HyperLogLogNormal(10);
            hll1.Add(1);

            hll1.Merge(null);
        }
        public void HllNormalMergePrecisionErrorTest()
        {
            HyperLogLog hll1 = new HyperLogLogNormal(10);
            hll1.Add(1);
            HyperLogLog hll2 = new HyperLogLogNormal(15);
            hll2.Add(2);

            hll1.Merge(hll2);
        }
        public void HllNormalHighCardinalityTest()
        {
            HyperLogLog hll = new HyperLogLogNormal(14);
            foreach (int i in TestsHelper.GetOneMillionDifferentElements())
                hll.Add(i);

            // Test is with precision 14, so relative error is around 1.04 / sqrt(2^14) = 0.008125

            Assert.IsTrue(TestsHelper.GetRelativeError(1000000UL, hll.Cardinality) < 0.009, "relative error should be around 0.008125 (inferior to 0.009 at least)");
        }
        public void HllNormalDifferentPrecisionsTest()
        {
            const ulong expected = 10000;

            IList<int> testPrecisions = new List<int>() { 4, 12, 16, 24, 28 };
            foreach (byte p in testPrecisions)
            {
                HyperLogLog hll = new HyperLogLogNormal(p);
                for (ulong i = 0; i < expected; ++i)
                    hll.Add(i);

                double delta = TestsHelper.GetDelta(expected, p);
                TestsHelper.AssertRelativeError(expected, hll.Cardinality);
            }
        }
        public void HllNormalMergeTest()
        {
            HyperLogLog hll1 = new HyperLogLogNormal(14);
            HyperLogLog hll2 = new HyperLogLogNormal(14);

            // Init
            hll1.Add(1);
            hll1.Add(2);
            hll1.Add(3);
            hll1.Add(4);
            hll1.Add(4);

            hll2.Add(3);
            hll2.Add(3);
            hll2.Add(4);
            hll2.Add(5);
            hll2.Add(6);
            hll2.Add(7);
            hll2.Add(7);

            Assert.IsTrue(hll1.Merge(hll2), "Merge should alter some registers and return true");
            Assert.AreEqual(7UL, hll1.Cardinality, "Cardinality after merge should be up-to-date");
        }
        private bool Merge(HyperLogLogNormal hll)
        {
            bool modified = false;

            for (uint i = 0; i < hll.Registers.Count(); ++i)
                if (UpdateIfGreater(ref Registers[i], hll.Registers[i]))
                    modified = true;

            return modified;
        }
 public void HllPlusPlusNormalHllParameterErrorTest()
 {
     HyperLogLog hll2 = new HyperLogLogNormal(PRECISION_DEFAULT);
     hll1.Merge(hll2);
 }