Files
c3c/test/unit/stdlib/hash/crc32.c3
soerlemans cf03215564 Added unit tests for Crc32 hashing. (#2833)
* Adding crc32 unit tests.

* Fix formatting in crc32 test cases

---------

Co-authored-by: soerlemans <sebasoerlemans+git@gmail.com>
Co-authored-by: Christoffer Lerno <christoffer.lerno@gmail.com>
2026-01-25 13:16:44 +01:00

65 lines
1.3 KiB
Plaintext

module crc32_test @test;
import std::hash::crc32;
import std::io;
fn void test_crc32_empty()
{
const uint EXPECTED = 0x00000000;
Crc32 crc;
crc.init();
crc.update("");
uint final = crc.final();
test::@check(final == EXPECTED, "Actual crc32: 0x%x == 0x%x", final, EXPECTED);
}
fn void test_crc32_a()
{
const uint EXPECTED = 0xe8b7be43;
Crc32 crc;
crc.init();
crc.updatec('a');
uint final = crc.final();
test::@check(final == EXPECTED, "Actual crc32: 0x%x == 0x%x", final, EXPECTED);
}
fn void test_crc32_abc()
{
const uint EXPECTED = 0x352441c2;
Crc32 crc;
crc.init();
crc.update("abc");
uint final = crc.final();
test::@check(final == EXPECTED, "Actual crc32: 0x%x == 0x%x", final, EXPECTED);
}
fn void test_crc32_longer()
{
const uint EXPECTED = 0x656e49ed;
Crc32 crc;
crc.init();
crc.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");
uint final = crc.final();
test::@check(final == EXPECTED, "Actual crc32: 0x%x == 0x%x", final, EXPECTED);
}
fn void test_crc32_alphabet()
{
const uint EXPECTED = 0x4c2750bd;
Crc32 crc;
crc.init();
crc.update("abcdefghijklmnopqrstuvwxyz");
uint final = crc.final();
test::@check(final == EXPECTED, "Actual crc32: 0x%x == 0x%x", final, EXPECTED);
}