12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
0
|
// test_fnv.c |
98e5939 |
Jamozed |
2021-11-27 17:53:46 |
1
|
// FNV unit test for libutil |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
2
|
// Copyright (C) 2021, Jakob Wakeling |
7f427d9 |
Jamozed |
2022-03-06 12:55:13 |
3
|
// MIT Licence |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
4
|
|
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
5
|
#include "../fnv.h" |
7d31e3a |
Jamozed |
2021-12-08 13:59:42 |
6
|
#include "../util.h" |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
7
|
#include "unit.h" |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
8
|
|
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
9
|
#include <stdio.h> |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
10
|
|
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
11
|
int main(void) { |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
12
|
{ |
7d31e3a |
Jamozed |
2021-12-08 13:59:42 |
13
|
u32 fnv32 = fnv1a32("123456789", 9); |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
14
|
ASSERT("T000 HASH STRING fnv1a32()", fnv32 == 0xBB86B11C); |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
15
|
} |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
16
|
|
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
17
|
{ |
7d31e3a |
Jamozed |
2021-12-08 13:59:42 |
18
|
u32 fnv32; fnv1a32_init(&fnv32); fnv1a32_hash(&fnv32, "123456789", 9); |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
19
|
ASSERT("T001 HASH STRING fnv1a32_hash()", fnv32 == 0xBB86B11C); |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
20
|
} |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
21
|
|
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
22
|
{ |
7d31e3a |
Jamozed |
2021-12-08 13:59:42 |
23
|
u64 fnv64 = fnv1a64("123456789", 9); |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
24
|
ASSERT("T002 HASH STRING fnv1a64()", fnv64 == 0x06D5573923C6CDFC); |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
25
|
} |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
26
|
|
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
27
|
{ |
7d31e3a |
Jamozed |
2021-12-08 13:59:42 |
28
|
u64 fnv64; fnv1a64_init(&fnv64); fnv1a64_hash(&fnv64, "123456789", 9); |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
29
|
ASSERT("T003 HASH STRING fnv1a64_hash()", fnv64 == 0x06D5573923C6CDFC); |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
30
|
} |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
31
|
|
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
32
|
printf("%d of %d tests passed\n", testspassed, testsrun); |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
33
|
return testsfailed; |
12c01d4 |
Jamozed |
2021-09-04 14:07:48 |
34
|
} |
|
|
|
35
|
|