Exemplo n.º 1
0
        private static void Test_CalculateEstimatedCount_ShouldBeWithinAcceptableErrorRange(
            HyperLogLog hyperLogLog,
            int n,
            double acceptablePercentError)
        {
            // Act
            int estimatedCount = hyperLogLog.CalculateEstimatedCount();

            // Assert
            Assert.That(estimatedCount, Is.EqualTo(n).Within(acceptablePercentError).Percent);
        }
Exemplo n.º 2
0
        public void SerializeDeserialize_SameEstimate(int n, byte b)
        {
            // Arrange
            HyperLogLog     hyperLogLog = CreateHyperLogLogWithHashedStrings(n, b);
            BinaryFormatter formatter   = new BinaryFormatter();
            MemoryStream    stream      = new MemoryStream();

            // Act
            formatter.Serialize(stream, hyperLogLog);
            stream.Position = 0;
            HyperLogLog deserialized = (HyperLogLog)formatter.Deserialize(stream);

            // Assert
            int originalEstimate = hyperLogLog.CalculateEstimatedCount();

            Assert.That(originalEstimate, Is.GreaterThan(0.9 * n));
            Assert.That(originalEstimate, Is.EqualTo(deserialized.CalculateEstimatedCount()));
        }