예제 #1
0
        public void NonIncrementalSeed0()
        {
            var input      = Encoding.ASCII.GetBytes(TestString);
            var hash       = MetroHash128.Hash(0, input, 0, input.Length);
            var secondHash = OldMetroHash128.Hash(0, input, 0, input.Length);
            var comparison = new byte[]
            {
                0xC7, 0x7C, 0xE2, 0xBF, 0xA4, 0xED, 0x9F, 0x9B,
                0x05, 0x48, 0xB2, 0xAC, 0x50, 0x74, 0xA2, 0x97
            };

            Assert.Equal(comparison, hash);
            Assert.Equal(comparison, secondHash);
        }
예제 #2
0
        public void NonIncrementalSeed1()
        {
            var input      = Encoding.ASCII.GetBytes(TestString);
            var hash       = MetroHash128.Hash(1, input, 0, input.Length);
            var secondHash = OldMetroHash128.Hash(1, input, 0, input.Length);
            var comparison = new byte[]
            {
                0x45, 0xA3, 0xCD, 0xB8, 0x38, 0x19, 0x9D, 0x7F,
                0xBD, 0xD6, 0x8D, 0x86, 0x7A, 0x14, 0xEC, 0xEF
            };

            Assert.Equal(comparison, hash);
            Assert.Equal(comparison, secondHash);
        }
예제 #3
0
        public void MultipleSizes(int size)
        {
            var prng  = new Random();
            var input = new byte[size];

            prng.NextBytes(input);

            for (var i = 0; i < size; i++)
            {
                var firstHash = MetroHash128.Hash(0, input, 0, input.Length);
                var metroHash = new MetroHash128(0);
                metroHash.Update(input, 0, input.Length);
                var secondHash = metroHash.FinalizeHash();
                Assert.Equal(firstHash, secondHash);
                var thirdHash = OldMetroHash128.Hash(0, input, 0, input.Length);
                Assert.Equal(firstHash, thirdHash);
            }
        }
예제 #4
0
 public void RandomSizesSpan()
 {
     for (var i = 0; i < 1000; i++)
     {
         var prng  = new Random();
         var size  = prng.Next(10000);
         var input = new byte[size];
         prng.NextBytes(input);
         Span <byte> firstOutput = stackalloc byte[16];
         MetroHash128.Hash(0, input, firstOutput);
         var metroHash = new MetroHash128(0);
         metroHash.Update(input);
         Span <byte> secondOutput = stackalloc byte[16];
         metroHash.FinalizeHash(secondOutput);
         Assert.True(firstOutput.SequenceEqual(secondOutput));
         var thirdHash = OldMetroHash128.Hash(0, input, 0, input.Length);
         Assert.True(firstOutput.SequenceEqual(thirdHash));
     }
 }
예제 #5
0
        public void MultipleSizesSpan(int size)
        {
            var prng  = new Random();
            var input = new byte[size];

            prng.NextBytes(input);

            for (var i = 0; i < size; i++)
            {
                Span <byte> firstHash = stackalloc byte[16];
                MetroHash128.Hash(0, input.AsSpan(), firstHash);
                var metroHash = new MetroHash128(0);
                metroHash.Update(input.AsSpan());
                var secondHash = metroHash.FinalizeHash();
                Assert.Equal(firstHash.ToArray(), secondHash);
                var thirdHash = OldMetroHash128.Hash(0, input, 0, input.Length);
                Assert.Equal(firstHash.ToArray(), thirdHash);
            }
        }