mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-22 15:37:51 +00:00
Correct CRC-64 (ECMA 182) & add CRC-64 (XZ) and tests.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user