Algorithm-Huffman

 view release on metacpan or  search on metacpan

t/encode_bitstring.t  view on Meta::CPAN

    is $huff->decode($encoded_with_huffman_bitvector),
       $s,
       "Decoding of encoding (packed) bitvector should be the same as the orig";
}

my $string    = random_string('c' x LONG_STRING_LENGTH);

UNKNOWN_CHAR_IN_BITSTRING_SHOULD_PRODUCE_AN_EXCEPTION: {
    my $bitstring = $huff->encode_bitstring($string);
    substr($bitstring,length($string)/2,1) = "a";
    throws_ok {$huff->decode_bitstring($bitstring)} 
              qr/unknown/i, 
              "Unknown character (an a instead 0/1) into the bitstring";
}

BITSTRING_TOO_SHORT: {
    my $bitstring = $huff->encode_bitstring($string);
    $bitstring = substr($bitstring,0,length($bitstring-1));
    dies_ok {$huff->decode_bitstring($bitstring)}
            "Removed the last bit of the bitstring -> should die";
}

t/wrong_parameter.t  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use warnings;

use Algorithm::Huffman;
use Test::Exception;
use Test::More tests => 10;

throws_ok {
    Algorithm::Huffman->new();    
} qr/undefined counting hash/i,
  "->new()";
  
throws_ok {
    Algorithm::Huffman->new(undef); 
} qr/undefined counting hash/i,
  "->new(undef)";
  
throws_ok {
    Algorithm::Huffman->new(\undef);    
} qr/not (a )?hash ref/i,
  "->new(\\undef)";
  
throws_ok {
    Algorithm::Huffman->new([]);    
} qr/not (a )?hash ref/i,
  "->new([])";

throws_ok {
    Algorithm::Huffman->new({});
} qr/counting hash must have at least (two|2) keys/i,
  "->new({})";

throws_ok {
    Algorithm::Huffman->new({a => 1});
} qr/counting hash must have at least (two|2) keys/i,
  "->new({a => 1})";
  
lives_ok {
    Algorithm::Huffman->new({a => 1, b => 1});    
} "->new({a => 1, b => 1})";

throws_ok {
    Algorithm::Huffman->new({a => 1, b => 1, c => 'one'})
} qr/number/i,
  "->new({a => 1, b => 1, c => one})";
  
lives_ok {
    Algorithm::Huffman->new({a => 1, b => 1, c => 0})
} "->new({a => 1, b => 1, c => 0})";  

throws_ok {
    Algorithm::Huffman->new({a => 1, b => 1, c => -1})
} qr/positive/i,
  "->new({a => 1, b => 1, c => -1})";



( run in 0.384 second using v1.01-cache-2.11-cpan-496ff517765 )