4
use Sereal::Encoder qw(encode_sereal);
5
use List::Util qw(shuffle);
8
# Try and find 15 hash collisions in "A".."Z"
9
# we will use the colliding keys to produce hashes
10
# with the same contents, but with different key orders,
11
# which we will use to test the "sort_keys" logic.
20
for my $x ("A" .. "Z") {
21
for my $y ( chr(ord($x)+1) .. "Z" ) {
26
if ("@{[keys %i]}" ne "@{[keys %j]}") { # collission?
28
last LOOP if keys %hash == $max;
30
last LOOP if keys %hash == $max;
36
my $copy_keys= join "", keys %copy;
39
keys(%bigger)= $max++ while scalar(%bigger) eq scalar(%hash);
42
$shuffled{$_}= $hash{$_} for shuffle keys %hash;
46
for ( \%hash, \%copy, \%bigger, \%shuffled ) {
47
my $keys= join "", keys %$_;
48
$encoded{$keys} ||= encode_sereal($_, { sort_keys => 1 } );
49
$encoded_unsorted{$keys} ||= encode_sereal($_);
51
my @keys= keys %encoded;
54
plan tests => 2 * ( (@keys * (@keys-1)) / 2 );
56
plan skip_all => "Could not generate test hashes";
59
foreach my $x ( 0 .. $#keys ) {
60
foreach my $y ($x + 1 .. $#keys) {
61
is($encoded{$keys[$x]}, $encoded{$keys[$y]},"$keys[$x] vs $keys[$y] (same: sort_keys)");
62
isnt($encoded_unsorted{$keys[$x]}, $encoded_unsorted{$keys[$y]},"$keys[$x] vs $keys[$y] (different: no sort_keys)");