Example #1
0
 public void Parsing()
 {
     Assert.False(HashCode128.TryParse(null, out HashCode128 hash));
     Assert.False(HashCode128.TryParse("", out hash));
     Assert.False(HashCode128.TryParse("123456789ABCDE", out hash));
     Assert.False(HashCode128.TryParse("Well, this isn't likely to work, is it?", out hash));
     Assert.False(HashCode128.TryParse("123456789abcdef01", out hash));
     Assert.Equal(hash, HashCode128.Zero);
     Assert.Equal(default(HashCode128), hash);
     Assert.True(HashCode128.TryParse("123456789abcdef00fedcba987654321", out hash));
     Assert.Equal(hash, HashCode128.Parse("  123456789ABCD EF0  0fe DCB a98 765 4321   "));
     Assert.Equal(HashCode128.Parse("00000000000000000000000000000000"), HashCode128.Zero);
     Assert.Equal(hash.GetHashCode(), HashCode128.Parse("123456789abcdef00fedcba987654321").GetHashCode());
     Assert.NotEqual(hash.GetHashCode(), HashCode128.Zero.GetHashCode());
     Assert.Equal(0, HashCode128.Zero.GetHashCode());
     Assert.Equal <ulong>(0x123456789abcdef0, hash.UHash1);
     Assert.Equal <ulong>(0x0fedcba987654321, hash.UHash2);
     Assert.Equal(0x123456789abcdef0, hash.Hash1);
     Assert.Equal(0x0fedcba987654321, hash.Hash2);
     Assert.Equal(hash, new HashCode128(0x123456789abcdef0u, 0x0fedcba987654321));
     Assert.Equal(hash, new HashCode128(0x123456789abcdef0, 0x0fedcba987654321));
     Assert.Equal(hash, HashCode128.Parse("0x123456789abcdef00fedcba987654321"));
     Assert.Equal(hash, HashCode128.Parse("0x123456789abcdef00fedcba987654321"));
     Assert.False(HashCode128.TryParse("x123456789abcdef00fedcba987654321", out hash));
     Assert.False(HashCode128.TryParse("0xx123456789abcdef00fedcba987654321", out hash));
     Assert.False(HashCode128.TryParse("1234x6789abcdef00fedcba987654321", out hash));
 }
        public static HashCode128 ToHashCode128(this IHashValue hashVal, bool strictMode = true)
        {
            if (hashVal is null)
            {
                return(HashCode128.Zero);
            }
            var hex = hashVal.GetHexString();

            return(strictMode ? HashCode128.Parse(hex) : HashCode128.ParseLoosely(hex));
        }
Example #3
0
        public void EqualsObj()
        {
            Assert.Equal(HashCode128.Zero, (object)HashCode128.Zero);
            object boxed = HashCode128.Parse("0123456789abcdef0123456789ABCDEF");

            Assert.True(boxed.Equals(HashCode128.Parse("0123456789ABCDEF0123456789ABCDEF")));
            Assert.False(boxed.Equals(HashCode128.Zero));
            Assert.False(boxed.Equals("not a hash code"));
            Assert.True(
                Equals(
                    HashCode128.Parse("fed c b a9876543210 0123456789ABCDEF"),
                    HashCode128.Parse("FE DCBA 98765 432 10 0123456789ABCD EF     ")));
        }
Example #4
0
 public void ToStringTests()
 {
     Assert.Equal(
         "0123456789ABCDEF0123456789ABCDEF", HashCode128.Parse("0123456789abcdef0123456789ABCDEF").ToString());
 }