public static void FnvHashCode_Combine_3() { foreach (var a in Expected) { foreach (var b in Expected) { foreach (var c in Expected) { var aSpan = new[] { a, b, c }.AsSpan().NonPortableCast <int, byte>(); var bSpan = new[] { c, b, a }.AsSpan().NonPortableCast <int, byte>(); if (System.Linq.Enumerable.SequenceEqual(new[] { a, b, c }, new[] { c, b, a })) { Assert.Equal(FnvHashCode.Combine(a, b, c), FnvHashCode.Combine(c, b, a)); Assert.Equal(FnvHashCode.Combine(aSpan), FnvHashCode.Combine(bSpan)); } else { Assert.NotEqual(FnvHashCode.Combine(a, b, c), FnvHashCode.Combine(c, b, a)); Assert.NotEqual(FnvHashCode.Combine(bSpan), FnvHashCode.Combine(aSpan)); } } } } }
public static void FnvHashCode_TestVectors(ulong expected, string value) { // Using 'FNV-1a 32' test vectors from http://www.isthe.com/chongo/tech/comp/fnv var bytes = Encoding.UTF8.GetBytes(value); var actual = FnvHashCode.Combine(bytes); Assert.Equal(expected, (uint)actual); }
public static void FnvHashCode_Check_2(int expected, int a, int b) { var actual = FnvHashCode.Combine(a, b); Assert.Equal(expected, actual); if (a == b) { Assert.Equal(FnvHashCode.Combine(a, b), FnvHashCode.Combine(b, a)); } else { Assert.NotEqual(FnvHashCode.Combine(a, b), FnvHashCode.Combine(b, a)); } }
public static void FnvHashCode_Combine_2() { foreach (var a in Expected) { foreach (var b in Expected) { if (a == b) { Assert.Equal(FnvHashCode.Combine(a, b), FnvHashCode.Combine(b, a)); } else { Assert.NotEqual(FnvHashCode.Combine(a, b), FnvHashCode.Combine(b, a)); } } } }