Beispiel #1
0
        private Test CreateCollisionProbabilityTest()
        {
            return(new TestCase("CollisionProbabilityTest", () => AssertionHelper.Verify(() =>
            {
                HashStoreResult result;

                try
                {
                    result = GetResult();
                }
                catch (NotEnoughHashesException exception)
                {
                    return new AssertionFailureBuilder("Not enough hash code samples were provided to the hash code acceptance contract.")
                    .AddException(exception)
                    .SetStackTrace(Context.GetStackTraceData())
                    .ToAssertionFailure();
                }

                var probability = result.CollisionProbability;
                TestLog.WriteLine("Statistical Population = {0}", result.StatisticalPopulation);
                TestLog.WriteLine("Actual Collision Probability = {0} {1} {2}", probability, ((probability <= collisionProbabilityLimit) ? "≤" : ">"), collisionProbabilityLimit);

                if (probability <= collisionProbabilityLimit)
                {
                    return null;
                }

                return new AssertionFailureBuilder(String.Format("The actual collision probability {0} is higher than the specified limit of {1}.", probability, collisionProbabilityLimit))
                .AddRawExpectedValue(collisionProbabilityLimit)
                .AddRawActualValue(probability)
                .SetStackTrace(Context.GetStackTraceData())
                .ToAssertionFailure();
            })));
        }
        public void Constructs_ok()
        {
            var result = new HashStoreResult(123, 456d, 789d);

            Assert.AreEqual(123, result.StatisticalPopulation);
            Assert.AreEqual(456d, result.CollisionProbability);
            Assert.AreEqual(789d, result.UniformDistributionDeviationProbability);
        }
Beispiel #3
0
        private HashStoreResult GetResult()
        {
            if (result == null)
            {
                var store = new HashStore(GenericCollectionUtils.Select(DistinctInstances, o => o.GetHashCode()));
                result = store.Result;
            }

            return(result);
        }