2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/hash/fasthash.hpp>
|
|
|
|
#include <cruft/util/tap.hpp>
|
2015-05-28 12:17:25 +10:00
|
|
|
|
|
|
|
#include <cstring>
|
2018-08-13 14:51:33 +10:00
|
|
|
#include <cinttypes>
|
2015-05-28 12:17:25 +10:00
|
|
|
|
2018-01-13 13:48:58 +11:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-05-28 12:17:25 +10:00
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2015-05-28 12:17:25 +10:00
|
|
|
|
|
|
|
static const struct {
|
|
|
|
uint32_t seed32;
|
|
|
|
uint32_t hash32;
|
|
|
|
uint64_t seed64;
|
|
|
|
uint64_t hash64;
|
2018-05-03 17:34:19 +10:00
|
|
|
const char *data;
|
2015-05-28 12:17:25 +10:00
|
|
|
} TESTS[] = {
|
2018-05-03 17:34:19 +10:00
|
|
|
{ 0x00000000, 0x00000000, 0x0000000000000000, 0x0000000000000000, "" },
|
|
|
|
{ 0x00000001, 0xd30ac4de, 0x0000000000000001, 0x2127599bf4321e79, "" },
|
|
|
|
{ 0xffffffff, 0xf5c7b4b0, 0xffffffffffffffff, 0x9b4792000001368f, "" },
|
|
|
|
{ 0xf5c7b4b0, 0x228128b7, 0x9b4792000001368f, 0x67a642098cc81da6, "a" },
|
|
|
|
{ 0x228128b7, 0x8400568d, 0x67a642098cc81da6, 0xc906440e03ce99a8, "abc" },
|
|
|
|
{ 0x8400568d, 0x12b4858b, 0x67a642098cc81da6, 0x1a36fbf3d71b0737, "message digest" },
|
|
|
|
{ 0x12b4858b, 0x730b822e, 0x1a36fbf3d71b0737, 0x7b48e31e3ac40a0f, "abcdefghijklmnopqrstuvwxyz" },
|
2015-05-28 12:17:25 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
bool success32 = true;
|
|
|
|
bool success64 = true;
|
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::hash::fasthash<uint32_t> h32{};
|
|
|
|
cruft::hash::fasthash<uint64_t> h64{};
|
2018-01-13 13:48:58 +11:00
|
|
|
|
2015-05-28 12:17:25 +10:00
|
|
|
for (const auto &t: TESTS) {
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::view data { t.data };
|
2018-05-03 17:34:19 +10:00
|
|
|
|
2021-04-13 16:05:08 +10:00
|
|
|
tap.expect_eq (t.hash32, h32 (t.seed32, data.cast<uint8_t const*> ()), "h32({:#04x})", t.seed32);
|
|
|
|
tap.expect_eq (t.hash64, h64 (t.seed64, data.cast<uint8_t const*> ()), "h64({:#08x})", t.seed64);
|
2015-05-28 12:17:25 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
tap.expect (success32, "fasthash32");
|
|
|
|
tap.expect (success64, "fasthash64");
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|