Algorithm-Huffman

 view release on metacpan or  search on metacpan

t/encode_bitstring.t  view on Meta::CPAN

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use Test::More tests => 5 * 20 + 2;
use List::Util qw/max/;
 
use constant MAX_COUNT            =>  1_000;
use constant MAX_SUBSTRING_LENGTH =>     10;
use constant HUFFMAN_ELEMENTS     =>  5_000;
use constant LONG_STRING_LENGTH   => 10_000;
 
sub myrand($) {
    return int( rand( int rand shift() ) + 1 );
}
 
# Create a random counting
my %counting = map {   random_string('c' x myrand MAX_SUBSTRING_LENGTH)
                    => myrand(MAX_COUNT)
                   }
                   (1 .. HUFFMAN_ELEMENTS);
$counting{$_} = myrand(MAX_COUNT) for ('a' .. 'z');
my $huff = Algorithm::Huffman->new(\%counting);



( run in 0.237 second using v1.01-cache-2.11-cpan-ec4f86ec37b )