Correct CRC-64 (ECMA 182) & add CRC-64 (XZ) and tests.

This commit is contained in:
Jeroen van Rijn
2021-09-21 15:17:23 +02:00
parent b3dc3f5908
commit b600ffba3b
2 changed files with 608 additions and 7 deletions
+31
View File
@@ -1,6 +1,7 @@
package test_core_hash
import "core:hash/xxhash"
import "core:hash"
import "core:time"
import "core:testing"
import "core:fmt"
@@ -32,6 +33,7 @@ main :: proc() {
t := testing.T{}
test_benchmark_runner(&t)
test_xxhash_vectors(&t)
test_crc64_vectors(&t)
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
}
@@ -253,4 +255,33 @@ test_xxhash_vectors :: proc(t: ^testing.T) {
expect(t, xxh3_128 == v.xxh3_128_secret, xxh3_128_error)
}
}
}
@test
test_crc64_vectors :: proc(t: ^testing.T) {
fmt.println("Verifying CRC-64:")
vectors := map[string][2]u64 {
"123456789" = {
0x6c40df5f0b497347, // ECMA-182,
0x995dc9bbdf1939fa, // XZ
},
"This is a test of the emergency broadcast system." = {
0x344fe1d09c983d13, // ECMA-182
0x27db187fc15bbc72, // XZ
},
}
for vector, expected in vectors {
fmt.println("\tVector:", vector)
b := transmute([]u8)vector
ecma := hash.crc64_ecma_182(b)
xz := hash.crc64_xz(b)
ecma_error := fmt.tprintf("[CRC-64 ECMA] Expected: %016x. Got: %016x.", ecma, expected[0])
xz_error := fmt.tprintf("[CRC-64 XZ ] Expected: %016x. Got: %016x.", xz, expected[1])
expect(t, ecma == expected[0], ecma_error)
expect(t, xz == expected[1], xz_error)
}
}