mirror of
https://github.com/urbit/shrub.git
synced 2024-12-24 20:47:27 +03:00
adds basic tests for u3r_mur
This commit is contained in:
parent
1974eca515
commit
2240edd354
12
meson.build
12
meson.build
@ -364,8 +364,6 @@ install: false)
|
||||
|
||||
test('test-hashtable', test_hashtable)
|
||||
|
||||
test_mem_sources = noun_src + jets_all_src + vere_sans_main + ['tests/test.c']
|
||||
|
||||
test_mem = executable('test-mem',
|
||||
sources : test_sources + ['tests/test.c'],
|
||||
include_directories : incdir,
|
||||
@ -375,3 +373,13 @@ dependencies: deps + os_deps,
|
||||
install: false)
|
||||
|
||||
test('test-mem', test_mem, should_fail: true)
|
||||
|
||||
test_hash = executable('test-hash',
|
||||
sources : test_sources + ['tests/hash_tests.c'],
|
||||
include_directories : incdir,
|
||||
c_args : os_c_flags,
|
||||
link_args: os_link_flags,
|
||||
dependencies: deps + os_deps,
|
||||
install: false)
|
||||
|
||||
test('test_hash', test_hash)
|
||||
|
68
tests/hash_tests.c
Normal file
68
tests/hash_tests.c
Normal file
@ -0,0 +1,68 @@
|
||||
#include "all.h"
|
||||
|
||||
/* _setup(): prepare for tests.
|
||||
*/
|
||||
static void
|
||||
_setup(void)
|
||||
{
|
||||
u3m_init(c3y);
|
||||
u3m_pave(c3y, c3n);
|
||||
}
|
||||
|
||||
/* _test_mur(): spot check u3r_mur hashes.
|
||||
*/
|
||||
static void
|
||||
_test_mur(void)
|
||||
{
|
||||
if ( 0x4d441035 != u3r_mur_string("Hello, world!") ) {
|
||||
fprintf(stderr, "fail\r\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( 0x4d441035 != u3r_mur(u3i_string("Hello, world!")) ) {
|
||||
fprintf(stderr, "fail\r\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( 0x79ff04e8 != u3r_mur_bytes(0, 0) ) {
|
||||
fprintf(stderr, "fail\r\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( 0x64dfda5c != u3r_mur(u3i_string("xxxxxxxxxxxxxxxxxxxxxxxxxxxx")) ) {
|
||||
fprintf(stderr, "fail\r\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( 0x389ca03a != u3r_mur_cell(0, 0) ) {
|
||||
fprintf(stderr, "fail\r\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( 0x389ca03a != u3r_mur_cell(1, 1) ) {
|
||||
fprintf(stderr, "fail\r\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( 0x5258a6c0 != u3r_mur_cell(0, u3qc_bex(32)) ) {
|
||||
fprintf(stderr, "fail\r\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( 0x2ad39968 != u3r_mur_cell(u3qa_dec(u3qc_bex(128)), 1) ) {
|
||||
fprintf(stderr, "fail\r\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* main(): run all test cases.
|
||||
*/
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
_setup();
|
||||
|
||||
_test_mur();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user