예제 #1
0
 public override int GetHashCode()
 {
     unchecked
     {
         return((_email.GetHashCode() * 397) ^ _domain);
     }
 }
예제 #2
0
        public static void GetHashCode_ReturnsRandomized()
        {
            Utf8String a = u8("Hello");
            Utf8String b = new Utf8String(a.AsBytes());

            Assert.NotSame(a, b);
            Assert.Equal(a.GetHashCode(), b.GetHashCode());

            Utf8String c = u8("Goodbye");
            Utf8String d = new Utf8String(c.AsBytes());

            Assert.NotSame(c, d);
            Assert.Equal(c.GetHashCode(), d.GetHashCode());

            Assert.NotEqual(a.GetHashCode(), c.GetHashCode());
        }
예제 #3
0
        public static void GetHashCode_Ordinal()
        {
            // Generate 17 all-null strings and make sure they have unique hash codes.
            // Assuming Marvin32 is a good PRF and has a full 32-bit output domain, we should
            // expect this test to fail only once every ~30 million runs due to the birthday paradox.
            // That should be good enough for inclusion as a unit test.

            HashSet <int> seenHashCodes = new HashSet <int>();

            for (int i = 0; i <= 16; i++)
            {
                Utf8String ustr = new Utf8String(new byte[i]);

                Assert.True(seenHashCodes.Add(ustr.GetHashCode()), "This hash code was previously seen.");
            }
        }
예제 #4
0
        private void TestHashesSameForEquivalentString(Utf8String a, Utf8String b)
        {
            // for sanity
            Assert.Equal(a.Length, b.Length);
            TestHelper.Validate(a, b);

            for (int i = 0; i < a.Length; i++)
            {
                Utf8String prefixOfA = a.Substring(i, a.Length - i);
                Utf8String prefixOfB = b.Substring(i, b.Length - i);
                // sanity
                TestHelper.Validate(prefixOfA, prefixOfB);
                Assert.Equal(prefixOfA.GetHashCode(), prefixOfB.GetHashCode());

                // for all suffixes
                Utf8String suffixOfA = a.Substring(a.Length - i, i);
                Utf8String suffixOfB = b.Substring(b.Length - i, i);
                TestHelper.Validate(suffixOfA, suffixOfB);
            }
        }
예제 #5
0
 public override int GetHashCode(Utf8String obj) => obj.GetHashCode();
예제 #6
0
 public override int GetHashCode() => Name.GetHashCode();