Exemple #1
0
        public unsafe void TestVectors()
        {
            if (!BitConverter.IsLittleEndian)
            {
                return; // this test is only valid on little-endian platforms
            }

            // Arrange
            byte *keyBytes = stackalloc byte[16];

            for (int i = 0; i < 16; i++)
            {
                keyBytes[i] = (byte)i;
            }
            ulong k0 = *(ulong *)&keyBytes[0];
            ulong k1 = *(ulong *)&keyBytes[8];

            const int INPUT_SIZE = 63;
            byte *    pbInput    = stackalloc byte[INPUT_SIZE];

            for (int i = 0; i < INPUT_SIZE; i++)
            {
                pbInput[i] = (byte)i;
            }

            var comparer = new SipHashBasedStringEqualityComparer(k0, k1);

            // Act & assert
            for (int i = 0; i < INPUT_SIZE; i++)
            {
                int hashCode = comparer.GetHashCode(pbInput, (uint)i);
                fixed(byte *pVector = &vectors[i, 0])
                {
                    int v = *(int *)pVector;

                    Assert.Equal(hashCode, v);
                }
            }
        }
        public unsafe void TestVectors()
        {
            if (!BitConverter.IsLittleEndian)
            {
                return; // this test is only valid on little-endian platforms
            }

            // Arrange
            byte* keyBytes = stackalloc byte[16];
            for (int i = 0; i < 16; i++)
            {
                keyBytes[i] = (byte)i;
            }
            ulong k0 = *(ulong*)&keyBytes[0];
            ulong k1 = *(ulong*)&keyBytes[8];

            const int INPUT_SIZE = 63;
            byte* pbInput = stackalloc byte[INPUT_SIZE];
            for (int i = 0; i < INPUT_SIZE; i++)
            {
                pbInput[i] = (byte)i;
            }

            var comparer = new SipHashBasedStringEqualityComparer(k0, k1);

            // Act & assert
            for (int i = 0; i < INPUT_SIZE; i++)
            {
                int hashCode = comparer.GetHashCode(pbInput, (uint)i);
                fixed (byte* pVector = &vectors[i, 0])
                {
                    int v = *(int*)pVector;
                    Assert.Equal(hashCode, v);
                }
            }
        }
Exemple #3
0
        public void NullInputReturns0()
        {
            var comparer = new SipHashBasedStringEqualityComparer();

            Assert.Equal(0, comparer.GetHashCode(null));
        }
 public void NullInputReturns0()
 {
     var comparer = new SipHashBasedStringEqualityComparer();
     Assert.Equal(0, comparer.GetHashCode(null));
 }