1 |
root |
1.1 |
BEGIN { $| = 1; print "1..24\n"; } |
2 |
|
|
|
3 |
|
|
use Digest::FNV::XS; |
4 |
|
|
|
5 |
|
|
sub tst { |
6 |
|
|
my ($name, $data, $hash) = @_; |
7 |
|
|
|
8 |
|
|
my $func = defined &{"Digest::FNV::XS::$name"} |
9 |
|
|
? \&{"Digest::FNV::XS::$name"} |
10 |
|
|
: sub { $hash }; |
11 |
|
|
|
12 |
|
|
my $hex = unpack "H*", $data; |
13 |
|
|
my $h = $func->($data); |
14 |
|
|
|
15 |
|
|
print $h == $hash ? "" : "not ", "ok ", ++$count, " # plain $name($hex) == $h ($hash)\n"; |
16 |
|
|
|
17 |
|
|
my $h; |
18 |
|
|
$h = $func->($_, $h) |
19 |
|
|
for split //, $data; |
20 |
|
|
|
21 |
|
|
print $h == $hash ? "" : "not ", "ok ", ++$count, " # split $name($hex) == $h ($hash)\n"; |
22 |
|
|
} |
23 |
|
|
|
24 |
|
|
tst fnv0_32 => "\x00", 0; |
25 |
|
|
tst fnv0_64 => "\x00\x00", 0; |
26 |
|
|
tst fnv0_32 => "chongo <Landon Curt Noll> /\\../\\", 2166136261; |
27 |
|
|
tst fnv0_64 => "chongo <Landon Curt Noll> /\\../\\", 14695981039346656037; |
28 |
|
|
tst fnv1_32 => "\x01\x47\x6c\x10\xf3", 0; |
29 |
|
|
tst fnv1a_32 => "\xcc\x24\x31\xc4", 0; |
30 |
|
|
tst fnv1_64 => "\x92\x06\x77\x4c\xe0\x2f\x89\x2a\xd2", 0; |
31 |
|
|
tst fnv1a_64 => "\xd5\x6b\xb9\x53\x42\x87\x08\x36", 0; |
32 |
|
|
tst fnv1_32 => "03SB[", 0; |
33 |
|
|
tst fnv1_64 => "!v)EYwYVk&", 0; |
34 |
|
|
tst fnv1a_32 => "3pjNqM", 0; |
35 |
|
|
tst fnv1a_64 => "77kepQFQ8Kl", 0; |
36 |
|
|
|