Beispiel #1
0
        private static int AddMethod(Span <byte> data)
        {
            var hc = new ByteHashCode();

            for (int i = 0; i < data.Length; i++)
            {
                hc.Add(data[i]);
            }
            return(hc.ToHashCode());
        }
Beispiel #2
0
        public static void ByteHashCode_ToHashCode()
        {
            byte[] arr = new byte[128];
            for (int i = 1; i < arr.Length; i++)
            {
                var span = new Span <byte>(arr, 0, i);

                arr[i - 1] = (byte)(i * 2);
                int combine2 = ByteHashCode.Combine(span);
                int add2     = AddMethod(span);

                arr[i - 1] = (byte)i;
                int combine1 = ByteHashCode.Combine(span);
                int add1     = AddMethod(span);

                Assert.Equal(combine1, add1);
                Assert.Equal(combine2, add2);
                Assert.NotEqual(combine1, combine2);

                int combinePrevious = ByteHashCode.Combine(span.Slice(0, span.Length - 1));
                Assert.NotEqual(combinePrevious, combine1);
            }
        }