aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2025-10-21 16:33:07 +0200
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2025-10-21 16:33:07 +0200
commita1be1b63d5899da88ef8b7ebabc185c7ae4aad6e (patch)
tree76cc8c3d7f423054d3b672fb0eafdcc22eb82c54 /tests
parent9df81bed9fc43abbc8803b21304de6ee4931e9af (diff)
[core:hash] Add CCITT CRC-16
Diffstat (limited to 'tests')
-rw-r--r--tests/core/hash/test_core_hash.odin19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/core/hash/test_core_hash.odin b/tests/core/hash/test_core_hash.odin
index 8a951b186..30ee911a8 100644
--- a/tests/core/hash/test_core_hash.odin
+++ b/tests/core/hash/test_core_hash.odin
@@ -12,6 +12,7 @@ import "base:intrinsics"
};
*/
+V16 :: struct{s: string, h: u16}
V32 :: struct{s: string, h: u32}
V64 :: struct{s: string, h: u64}
@@ -263,4 +264,22 @@ test_murmur64_vectors :: proc(t: ^testing.T) {
testing.expect_value(t, i128(#hash(vectors[3].s, "murmur64")), i128(vectors[3].h))
testing.expect_value(t, i128(#hash(vectors[4].s, "murmur64")), i128(vectors[4].h))
testing.expect_value(t, i128(#hash(vectors[5].s, "murmur64")), i128(vectors[5].h))
+}
+
+@test
+test_crc16_ccitt_0x1021_vectors :: proc(t: ^testing.T) {
+ vectors :: []V16{
+ {"" , 0x0000},
+ {"abc" , 0x9dd6},
+ {"Hello" , 0xcbd6},
+ {"world" , 0x2363},
+ {"Hello, world!", 0x7ade},
+ {"\x70\x6a\x77" , 0x3299}, // ECMA-167, 7.2.6 Descriptor CRC
+ }
+
+ for vector in vectors {
+ b := transmute([]u8)vector.s
+ crc16 := hash.crc16_ccitt_0x1021(b)
+ testing.expectf(t, crc16 == vector.h, "\n\t[CCITT CRC-16({0:q})] Expected: 0x{1:4x}, got: 0x{2:4x}", vector.s, vector.h, crc16)
+ }
} \ No newline at end of file