public void RollingTokenSetCountTest(int duplicateTokenThreshold) { var rollingTokenSet = new RollingTokenSet(new SumHashCalculator(duplicateTokenThreshold)); int hash = 0; for (int i = 1; i < duplicateTokenThreshold * 2; i++) { Mock <TokenInfo> mockToken = new Mock <TokenInfo>(i); mockToken.Setup(x => x.GetLocationEnvelope()).Returns(new LocationEnvelope()); mockToken.Setup(x => x.GetHashCode()).Returns(i); (hash, _) = rollingTokenSet.Add(mockToken.Object); int Fib(int n) { if (n == 0) { return(0); } return(n + Fib(n - 1)); } if (i >= duplicateTokenThreshold) { Assert.IsTrue(rollingTokenSet.IsFull()); // E.g., Threshold = 3, i = 7, then expectedValue = 7+6+5+4+3+2+1 - (4+3+2+1) = 7+6+5 int expectedValue = Fib(i) - Fib(i - duplicateTokenThreshold); Assert.AreEqual(expectedValue, hash); } else { Assert.IsFalse(rollingTokenSet.IsFull()); int expectedValue = Fib(i); Assert.AreEqual(expectedValue, hash); } } }
private void TestDictionary(DuplicateDetectorDictionary _library, int baseModulus, int modulus) { A.Data.AsParallel().ForAll(kvp => { var rollingTokenSet = new RollingTokenSet(new RollingHashCalculator <TokenInfo>(100, baseModulus, modulus)); foreach (var list in kvp.Value) { (int hash, Evidence evidence) = rollingTokenSet.Add(new TokenInfo(list)); if (rollingTokenSet.IsFull()) { _ = _library.TryAdd(hash, evidence); } } }); }