Beispiel #1
0
 public void TestCopy()
 {
     long[] x = new long[] { 2, 1, 3, 2 };
     long[] y = AbstractHashGenerator.Copy(x);
     Assert.IsTrue(Common.Base.Compares.AreDeepEqual(x, y));
     Assert.AreNotSame(x, y);
 }
Beispiel #2
0
        public void TestLowestThreeBits()
        {
            Assert.AreEqual(0, AbstractHashGenerator.LowestThreeBits(0L));
            Assert.AreEqual(1, AbstractHashGenerator.LowestThreeBits(1L));
            Assert.AreEqual(2, AbstractHashGenerator.LowestThreeBits(2L));
            Assert.AreEqual(3, AbstractHashGenerator.LowestThreeBits(3L));
            Assert.AreEqual(4, AbstractHashGenerator.LowestThreeBits(4L));
            Assert.AreEqual(5, AbstractHashGenerator.LowestThreeBits(5L));
            Assert.AreEqual(6, AbstractHashGenerator.LowestThreeBits(6L));
            Assert.AreEqual(7, AbstractHashGenerator.LowestThreeBits(7L));

            // check we don't exceed 7
            Assert.AreEqual(0, AbstractHashGenerator.LowestThreeBits(8L));
            Assert.AreEqual(1, AbstractHashGenerator.LowestThreeBits(9L));
            Assert.AreEqual(2, AbstractHashGenerator.LowestThreeBits(10L));
            Assert.AreEqual(3, AbstractHashGenerator.LowestThreeBits(11L));
            Assert.AreEqual(4, AbstractHashGenerator.LowestThreeBits(12L));
            Assert.AreEqual(5, AbstractHashGenerator.LowestThreeBits(13L));
            Assert.AreEqual(6, AbstractHashGenerator.LowestThreeBits(14L));
            Assert.AreEqual(7, AbstractHashGenerator.LowestThreeBits(15L));
            Assert.AreEqual(0, AbstractHashGenerator.LowestThreeBits(16L));

            // max/min numbers
            Assert.AreEqual(7, AbstractHashGenerator.LowestThreeBits(long.MaxValue));
            Assert.AreEqual(0, AbstractHashGenerator.LowestThreeBits(long.MinValue));
        }
Beispiel #3
0
        public void TestRotate_N()
        {
            var m_pseudorandom      = new Mock <Pseudorandom>();
            AbstractHashGenerator f = new AbstractHashGenerator(m_pseudorandom.Object);

            f.Rotate(0, 5); // note 0 doesn't rotate..
            m_pseudorandom.Verify(n => n.Next(0), Times.Exactly(5));
        }
Beispiel #4
0
        public void TestRotate()
        {
            var m_pseudorandom      = new Mock <Pseudorandom>();
            AbstractHashGenerator f = new AbstractHashGenerator(m_pseudorandom.Object);

            f.Rotate(5L);
            m_pseudorandom.Verify(n => n.Next(5L), Times.Exactly(1));
        }
Beispiel #5
0
 public void TestCopy_SrcDest()
 {
     long[] x = new long[] { 42, 23, 1, 72 };
     long[] y = new long[4];
     AbstractHashGenerator.Copy(x, y);
     Assert.IsTrue(Common.Base.Compares.AreDeepEqual(x, y));
     Assert.AreNotSame(x, y);
 }
Beispiel #6
0
        public void TestDistribute()
        {
            var m_pseudorandom      = new Mock <Pseudorandom>();
            AbstractHashGenerator f = new AbstractHashGenerator(m_pseudorandom.Object);
            long x = f.Distribute(5L); // lowest 3 bits = 5, rotate 6 times

            m_pseudorandom.Verify(n => n.Next(It.IsAny <long>()), Times.Exactly(6));
            Assert.AreNotEqual(5L, x);
        }
Beispiel #7
0
        public void TestDistribute_AtLeastOnce()
        {
            var m_pseudorandom      = new Mock <Pseudorandom>();
            AbstractHashGenerator f = new AbstractHashGenerator(m_pseudorandom.Object);
            long x = f.Distribute(8L); // lowest 3 bits = 0, make sure we rotate 1

            m_pseudorandom.Verify(n => n.Next(It.IsAny <long>()), Times.Exactly(1));
            Assert.AreNotEqual(8L, x);
        }