mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Optimized adler32 hashing algorithm. (#2948)
* Optimized adler32 implementations. - Adapted adler32 implementation from Crypto++ public domain library. - Added unit tests for adler32 hashing algorithm. * tabified adler32 implementation to match stdlib. * Formatting to be consistent. Make unrolling use macro. --------- Co-authored-by: soerlemans <sebasoerlemans+git@gmail.com> Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
This commit is contained in:
64
test/unit/stdlib/hash/adler32.c3
Normal file
64
test/unit/stdlib/hash/adler32.c3
Normal file
@@ -0,0 +1,64 @@
|
||||
module adler32_test @test;
|
||||
|
||||
import std::hash::adler32;
|
||||
import std::io;
|
||||
|
||||
fn void test_adler32_empty()
|
||||
{
|
||||
const uint EXPECTED = 0x1;
|
||||
|
||||
Adler32 adl;
|
||||
adl.init();
|
||||
adl.update("");
|
||||
|
||||
uint final = adl.final();
|
||||
test::@check(final == EXPECTED, "Actual Adler32: 0x%x == 0x%x", final, EXPECTED);
|
||||
}
|
||||
|
||||
fn void test_adler32_a()
|
||||
{
|
||||
const uint EXPECTED = 0x00620062;
|
||||
|
||||
Adler32 adl;
|
||||
adl.init();
|
||||
adl.updatec('a');
|
||||
|
||||
uint final = adl.final();
|
||||
test::@check(final == EXPECTED, "Actual Adler32: 0x%x == 0x%x", final, EXPECTED);
|
||||
}
|
||||
|
||||
fn void test_adler32_abc()
|
||||
{
|
||||
const uint EXPECTED = 0x024d0127;
|
||||
|
||||
Adler32 adl;
|
||||
adl.init();
|
||||
adl.update("abc");
|
||||
|
||||
uint final = adl.final();
|
||||
test::@check(final == EXPECTED, "Actual Adler32: 0x%x == 0x%x", final, EXPECTED);
|
||||
}
|
||||
|
||||
fn void test_adler32_longer()
|
||||
{
|
||||
const uint EXPECTED = 0x07822df1;
|
||||
|
||||
Adler32 adl;
|
||||
adl.init();
|
||||
adl.update("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq");
|
||||
|
||||
uint final = adl.final();
|
||||
test::@check(final == EXPECTED, "Actual Adler32: 0x%x == 0x%x", final, EXPECTED);
|
||||
}
|
||||
|
||||
fn void test_adler32_alphabet()
|
||||
{
|
||||
const uint EXPECTED = 0x90860b20;
|
||||
|
||||
Adler32 adl;
|
||||
adl.init();
|
||||
adl.update("abcdefghijklmnopqrstuvwxyz");
|
||||
|
||||
uint final = adl.final();
|
||||
test::@check(final == EXPECTED, "Actual Adler32: 0x%x == 0x%x", final, EXPECTED);
|
||||
}
|
||||
Reference in New Issue
Block a user