libutil

C Utility Library
git clone http://git.omkov.net/libutil
Log | Tree | Refs | README | LICENCE | Download

libutil/src/test/test_fnv.c (36 lines, 802 B) -rw-r--r-- blame download

01234567891011121314151617181920212223242526272829303132333435
// test_fnv.c
// FNV unit test for libutil
// Copyright (C) 2021, Jakob Wakeling
// MIT Licence

#include "../fnv.h"
#include "../util.h"
#include "unit.h"

#include <stdio.h>

int main(void) {
	{
		u32 fnv32 = fnv1a32("123456789", 9);
		ASSERT("T000 HASH STRING fnv1a32()", fnv32 == 0xBB86B11C);
	}
	
	{
		u32 fnv32; fnv1a32_init(&fnv32); fnv1a32_hash(&fnv32, "123456789", 9);
		ASSERT("T001 HASH STRING fnv1a32_hash()", fnv32 == 0xBB86B11C);
	}
	
	{
		u64 fnv64 = fnv1a64("123456789", 9);
		ASSERT("T002 HASH STRING fnv1a64()", fnv64 == 0x06D5573923C6CDFC);
	}
	
	{
		u64 fnv64; fnv1a64_init(&fnv64); fnv1a64_hash(&fnv64, "123456789", 9);
		ASSERT("T003 HASH STRING fnv1a64_hash()", fnv64 == 0x06D5573923C6CDFC);
	}
	
	printf("%d of %d tests passed\n", testspassed, testsrun);
	return testsfailed;
}