Пример #1
0
        public void GenerateHash32_ForDifferentStringInputs_ProducesDifferentOutputs()
        {
            var inputs = TestGuids.Get().Select(g => g.ToString()).ToArray();

            var outputs = inputs.Select(i => HashGenerator.GenerateHash32(i).ToString()).ToArray();

            outputs.Distinct().Count().Should().Be(inputs.Length);
        }
Пример #2
0
        public void GenerateHash32(string text, int expectedHash)
        {
            var bytes = Encoding.ASCII.GetBytes(text);

            var hash = HashGenerator.GenerateHash32(bytes, Murmur3.Get32BitHashFunction());

            hash.AsInt32().Should().Be(expectedHash);
        }
Пример #3
0
        public async Task GenerateHash32AndGenerateHash32Async_SameArrayOfBytes_ProduceTheSameHash()
        {
            var inputs = TestGuids.Get().Select(g => g.ToByteArray()).ToArray();

            foreach (var input in inputs)
            {
                var hash1 = HashGenerator.GenerateHash32(input);
                var hash2 = await HashGenerator.GenerateHash32Async(new MemoryStream(input));

                hash1.ToString().Should().Be(hash2.ToString());
            }
        }
Пример #4
0
        public void GenerateHash32AndGenerateJsonHash32_SameSourceObject_ProduceTheSameHash()
        {
            var guids = TestGuids.Get();

            for (var i = 0; i < guids.Length; i++)
            {
                var obj = new TestClass {
                    A = i, B = new String(i.ToString()[0], i), C = guids[i]
                };

                var json  = JsonSerializer.Serialize(obj);
                var bytes = Encoding.ASCII.GetBytes(json);

                var bytesHash = HashGenerator.GenerateHash32(bytes);
                var jsonHash  = HashGenerator.GenerateJsonHash32(obj);

                jsonHash.AsInt32().Should().Be(bytesHash.AsInt32());
            }
        }
 public Hash32 GenerateHash32()
 {
     return(HashGenerator.GenerateHash32(InputSize == InputSize.OneKB ? _bytes_1KB : _bytes_1MB));
 }