Esempio n. 1
0
        public void SingleBlockXxh64UsingSpanMatchesTheirs(string text)
        {
            var input    = System.Text.Encoding.UTF8.GetBytes(text);
            var expected = Theirs64(input);
            var actual   = XXHash64.DigestOf(input.AsSpan());

            Assert.Equal(expected, actual);
        }
Esempio n. 2
0
        public void HashMatchesPregeneratedHashesForSmallBlocks(int length, ulong expected)
        {
            var bytes = new byte[length];

            for (var i = 0; i < bytes.Length; i++)
            {
                bytes[i] = (byte)i;
            }

            var actual  = XXHash64.DigestOf(bytes, 0, bytes.Length);
            var confirm = Theirs64(bytes);

            Assert.Equal(expected, confirm);
            Assert.Equal(expected, actual);
        }
Esempio n. 3
0
        public void CalculatingHashInChunksReturnsSameResultAsInOneGo(int length, int chuck)
        {
            var bytes  = new byte[length];
            var random = new Random(0);

            random.NextBytes(bytes);

            var transform = new XXHash64();
            var i         = 0;

            while (i < length)
            {
                var l = Math.Min(chuck, length - i);
                transform.Update(bytes, i, l);
                i += l;
            }

            Assert.Equal(XXHash64.DigestOf(bytes, 0, bytes.Length), transform.Digest());
        }
Esempio n. 4
0
        public unsafe void EmptyHash()
        {
            var input = Array.Empty <byte>();

            var expected = Theirs64(input);

            var actual1 = XXHash64.DigestOf(input, 0, input.Length);

            Assert.Equal(expected, actual1);

            fixed(byte *inputPtr = input)
            {
                var actual2 = XXHash64.DigestOf(inputPtr, 0);

                Assert.Equal(expected, actual2);
            }

            var actual3 = XXHash64.EmptyHash;

            Assert.Equal(expected, actual3);
        }