lzssf_symbolic.t 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!perl -T
  2. use utf8;
  3. use 5.036;
  4. use Test::More;
  5. use Compression::Util qw(:all);
  6. plan tests => 6;
  7. foreach my $file (__FILE__) {
  8. my $str = do {
  9. local $/;
  10. open my $fh, '<:utf8', $file;
  11. <$fh>;
  12. };
  13. my @symbols = (map { ord($_) } $str =~ /(\X)/g);
  14. my $enc1 = lzss_compress(\@symbols, \&create_huffman_entry, \&lzss_encode_fast);
  15. my $dec1 = lzss_decompress_symbolic($enc1, \&decode_huffman_entry);
  16. my $enc2 = lz77_compress(\@symbols, \&create_huffman_entry, \&lzss_encode_fast);
  17. my $dec2 = lz77_decompress_symbolic($enc2);
  18. my $dec3 = lzss_decode_symbolic(lzss_encode_fast(\@symbols));
  19. my $dec4 = lz77_decode_symbolic(lz77_encode(\@symbols, \&lzss_encode_fast));
  20. ok(length($enc1) < length($str));
  21. ok(length($enc2) < length($str));
  22. is($str, join('', map { chr($_) } @$dec1));
  23. is($str, join('', map { chr($_) } @$dec2));
  24. is($str, join('', map { chr($_) } @$dec3));
  25. is($str, join('', map { chr($_) } @$dec4));
  26. }
  27. __END__
  28. # International class; name and street
  29. class 国際( なまえ, Straße ) {
  30. # Say who am I!
  31. method 言え {
  32. say "I am #{self.なまえ} from #{self.Straße}";
  33. }
  34. }
  35. # all the people of the world!
  36. var 民族 = [
  37. 国際( "高田 Friederich", "台湾" ),
  38. 国際( "Smith Σωκράτης", "Cantù" ),
  39. 国際( "Stanisław Lec", "południow" ),
  40. ];
  41. 民族.each { |garçon|
  42. garçon.言え;
  43. }