31 lines
1,007 B
C
31 lines
1,007 B
C
#include "hash/crc32.h"
|
|
#include "hash/djb2.h"
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
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);
|
|
}
|