lz77_bwt_obh.t 987 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!perl -T
  2. use 5.036;
  3. use Test::More;
  4. use Compression::Util qw(:all);
  5. plan tests => 2;
  6. foreach my $file (__FILE__) {
  7. my $str = do {
  8. local $/;
  9. open my $fh, '<:raw', $file;
  10. <$fh>;
  11. };
  12. # Compression
  13. my $enc = do {
  14. my ($uncompressed, $distances, $lengths, $matches) = lz77_encode($str);
  15. bwt_compress(symbols2string($uncompressed))
  16. . fibonacci_encode($lengths)
  17. . create_huffman_entry($matches)
  18. . obh_encode($distances, \&mrl_compress_symbolic);
  19. };
  20. # Decompression
  21. my $dec = do {
  22. open my $fh, '<:raw', \$enc;
  23. my $uncompressed = string2symbols(bwt_decompress($fh));
  24. my $lengths = fibonacci_decode($fh);
  25. my $matches = decode_huffman_entry($fh);
  26. my $distances = obh_decode($fh, \&mrl_decompress_symbolic);
  27. lz77_decode($uncompressed, $distances, $lengths, $matches);
  28. };
  29. ok(length($enc) < length($str));
  30. is($str, $dec);
  31. }