From 08a1c588c36a31d5c793b1fa3ed42d02c6e6d2f7 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Mon, 15 Sep 2025 18:58:31 +0200 Subject: [PATCH] Some tests --- test.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 test.c diff --git a/test.c b/test.c new file mode 100644 index 0000000..bf69dbc --- /dev/null +++ b/test.c @@ -0,0 +1,31 @@ +#include "hash/crc32.h" +#include "hash/djb2.h" +#include +#include +#include + +int main(void) { + assert(crc32("123456789", 9) == 0xCBF43926); + assert(crc32("", 0) == 0x00000000); + assert(crc32("a", 1) == 0xE8B7BE43); + assert(crc32("A", 1) == 0xD3D99E8B); + assert(crc32("hello", 5) == 0x3610A686); + assert(crc32("The quick brown fox jumps over the lazy dog", 43) == 0x414FA339); + assert(crc32("The quick brown fox jumps over the lazy dog.", 44) == 0x519025E9); + + /* Keep in mind the update api requires initialization and finalization */ + uint32_t crc = crc32_init(); + crc = crc32_update_raw(crc, "a", 1); + crc = crc32_finalize(crc); + + assert(crc == crc32("a", 1)); + assert(crc == 0xE8B7BE43); + + assert(djb2("Hello") == 0x000000310D4F2079); + assert(djb2("a") == 0x000000000002B606); + assert(djb2("A") == 0x000000000002B5E6); + assert(djb2("123456789") == 0x0377821035CDBB82); + + printf("All good!\n"); + exit(EXIT_SUCCESS); +}