public void TestWithPolynomBase(int polynomBase)
        {
            var hasher = new PolynomialSequenceHasher(polynomBase);

            hasher.Enqueue("first");
            Assert.AreEqual("first".GetHashCode(), hasher.GetCurrentHash());
            hasher.Enqueue("second");
            Assert.AreEqual(unchecked (polynomBase * "first".GetHashCode() + "second".GetHashCode()), hasher.GetCurrentHash());
            hasher.Dequeue();
            Assert.AreEqual("second".GetHashCode(), hasher.GetCurrentHash());
        }
Example #2
0
        public void WorkWithPolynomBase1()
        {
            var hasher = new PolynomialSequenceHasher(1);

            hasher.Enqueue("first");
            Assert.AreEqual("first".GetHashCode(), hasher.GetCurrentHash());
            hasher.Enqueue("second");
            Assert.AreEqual("first".GetHashCode() + "second".GetHashCode(), hasher.GetCurrentHash());
            hasher.Dequeue();
            Assert.AreEqual("second".GetHashCode(), hasher.GetCurrentHash());
        }
Example #3
0
        public void NotDequeFromEmptyQueue()
        {
            var hasher = new PolynomialSequenceHasher(137);

            hasher.Enqueue("some_string");
            hasher.Dequeue();
            Assert.Throws <InvalidOperationException>(() => hasher.Dequeue());
        }
        public void TestReset(int count)
        {
            var hasher = new PolynomialSequenceHasher(137);

            for (var i = 0; i < count; i++)
            {
                hasher.Enqueue("some_string");
                Assert.AreEqual("some_string".GetHashCode(), hasher.GetCurrentHash());
                hasher.Reset();
            }
        }
        public void TestWithManyAdds(int count, int polynomBase)
        {
            var hasher      = new PolynomialSequenceHasher(polynomBase);
            var currentHash = 0;

            for (var i = 0; i < count; i++)
            {
                hasher.Enqueue("some_string");
                currentHash = unchecked (currentHash * polynomBase + "some_string".GetHashCode());
                Assert.AreEqual(currentHash, hasher.GetCurrentHash());
            }
        }
        public void TestDequeue()
        {
            const int count  = 100;
            var       hasher = new PolynomialSequenceHasher(137);

            for (var i = 0; i < count; i++)
            {
                hasher.Enqueue("some_string");
            }
            for (var i = 0; i < count - 1; i++)
            {
                hasher.Dequeue();
            }
            Assert.AreEqual("some_string".GetHashCode(), hasher.GetCurrentHash());
        }