a guest Aug 22nd, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #[cfg(test)]
  2. mod tests {
  3.     #[test]
  4.     fn basic() {
  5.         let string = "aaaabbbccd";
  6.         let out = &[0b00001010u8, 0b10111111u8, 0b11000000u8];
  7.         assert_eq!(super::huffman(string).as_slice(), out);
  8.     }
  10.     #[test]
  11.     fn kafka() {
  12.         let kafka = "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. \"What's happened to me?\" he thought. It wasn't a dream. His room, a proper human room although a little too small, lay peacefully between its four familiar walls. A collection of textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture that he had recently cut out of an illustrated magazine and housed in a nice, gilded frame. It showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards t";
  13.         let out = &[
  14.             0x0Au8, 0xEBu8, 0x1Cu8, 0x45u8, 0xF7u8, 0x84u8, 0xC3u8, 0x5Eu8, 0x0Au8, 0x3Fu8, 0xD8u8,
  15.             0x2Bu8, 0xBDu8, 0xF3u8, 0x4Fu8, 0xB1u8, 0xBBu8, 0x71u8, 0xD5u8, 0x94u8, 0x3Bu8, 0x7Fu8,
  16.             0x0Cu8, 0xDBu8, 0xC4u8, 0x9Du8, 0xBFu8, 0xB0u8, 0x2Fu8, 0x64u8, 0xCEu8, 0xFAu8, 0xE3u8,
  17.             0xAFu8, 0x07u8, 0xF8u8, 0x63u8, 0xFBu8, 0x8Cu8, 0x9Fu8, 0x48u8, 0xEBu8, 0x95u8, 0x84u8,
  18.             0xEEu8, 0xF1u8, 0xA6u8, 0x3Eu8, 0xE3u8, 0xD9u8, 0x13u8, 0x07u8, 0xD3u8, 0x44u8, 0x1Du8,
  19.             0x91u8, 0x31u8, 0x2Eu8, 0x59u8, 0xF7u8, 0xDEu8, 0xD2u8, 0x05u8, 0xE2u8, 0xA7u8, 0x6Eu8,
  20.             0x29u8, 0x8Au8, 0xA3u8, 0x67u8, 0x0Bu8, 0x74u8, 0x8Fu8, 0x83u8, 0xE9u8, 0xA2u8, 0xF7u8,
  21.             0x17u8, 0xF7u8, 0x6Du8, 0xAAu8, 0x8Du8, 0xFCu8, 0x41u8, 0x70u8, 0xB7u8, 0xF8u8, 0x2Fu8,
  22.             0x19u8, 0x11u8, 0x87u8, 0xF8u8, 0x54u8, 0x64u8, 0xF6u8, 0x4Fu8, 0xA6u8, 0x8Fu8, 0xF5u8,
  23.             0xE4u8, 0xB1u8, 0x52u8, 0x65u8, 0x78u8, 0xFFu8, 0x10u8, 0xBFu8, 0xABu8, 0x93u8, 0x5Du8,
  24.             0xC7u8, 0xD3u8, 0x44u8, 0x1Bu8, 0x7Au8, 0x30u8, 0x41u8, 0xCAu8, 0xB4u8, 0xF8u8, 0x34u8,
  25.             0xA8u8, 0xD7u8, 0xE5u8, 0x69u8, 0x32u8, 0xF1u8, 0xECu8, 0x97u8, 0x8Cu8, 0x99u8, 0x4Au8,
  26.             0x89u8, 0x9Eu8, 0xC9u8, 0x05u8, 0x25u8, 0xEEu8, 0x1Fu8, 0xF6u8, 0x84u8, 0xC4u8, 0xB9u8,
  27.             0xA9u8, 0x46u8, 0x30u8, 0xD7u8, 0x43u8, 0x28u8, 0xF8u8, 0xD5u8, 0x52u8, 0xBCu8, 0xFFu8,
  28.             0x10u8, 0x76u8, 0x72u8, 0x98u8, 0x68u8, 0xA2u8, 0xF4u8, 0x7Eu8, 0xF7u8, 0x95u8, 0xA4u8,
  29.             0xB8u8, 0x17u8, 0x89u8, 0x72u8, 0x17u8, 0xA9u8, 0xDBu8, 0x12u8, 0x4Bu8, 0xC6u8, 0x4Du8,
  30.             0x77u8, 0x47u8, 0xB2u8, 0x6Fu8, 0xAFu8, 0x34u8, 0x92u8, 0xE6u8, 0x95u8, 0x33u8, 0xC3u8,
  31.             0xB1u8, 0x85u8, 0xE2u8, 0x92u8, 0x2Fu8, 0x1Eu8, 0xC4u8, 0xD5u8, 0x1Bu8, 0x13u8, 0x44u8,
  32.             0x6Fu8, 0x14u8, 0x8Bu8, 0xCDu8, 0x6Bu8, 0xC1u8, 0xE5u8, 0x25u8, 0x19u8, 0xEAu8, 0xADu8,
  33.             0x24u8, 0xFDu8, 0x30u8, 0x42u8, 0xF1u8, 0xF3u8, 0x7Bu8, 0xECu8, 0x94u8, 0x24u8, 0xFCu8,
  34.             0x9Fu8, 0xF1u8, 0xA4u8, 0xACu8, 0x70u8, 0xECu8, 0x27u8, 0xFCu8, 0x6Fu8, 0xB5u8, 0x23u8,
  35.             0xB0u8, 0xFAu8, 0x47u8, 0xC1u8, 0x45u8, 0xD4u8, 0xECu8, 0x97u8, 0x03u8, 0xFBu8, 0x27u8,
  36.             0xF9u8, 0x7Cu8, 0xAFu8, 0x6Bu8, 0x4Bu8, 0x49u8, 0x7Au8, 0x3Fu8, 0xC2u8, 0xBBu8, 0xB7u8,
  37.             0xF6u8, 0x6Au8, 0x95u8, 0x9Au8, 0xD5u8, 0x7Bu8, 0xFBu8, 0x9Au8, 0xDEu8, 0x8Fu8, 0xDFu8,
  38.             0x9Fu8, 0x3Du8, 0x8Eu8, 0xC9u8, 0x2Eu8, 0x47u8, 0xABu8, 0xEAu8, 0xCDu8, 0x68u8, 0xFFu8,
  39.             0x13u8, 0xF7u8, 0xF5u8, 0xAFu8, 0xCDu8, 0x52u8, 0xB9u8, 0x25u8, 0x17u8, 0xACu8, 0x56u8,
  40.             0xE4u8, 0xB3u8, 0x3Bu8, 0xEBu8, 0x8Du8, 0x51u8, 0xB1u8, 0x34u8, 0x6Du8, 0xDEu8, 0x3Eu8,
  41.             0x0Bu8, 0x3Cu8, 0xEDu8, 0xFCu8, 0xF6u8, 0xCFu8, 0xFBu8, 0x1Bu8, 0xC1u8, 0xB7u8, 0x78u8,
  42.             0x96u8, 0xB3u8, 0xF7u8, 0xF5u8, 0xAFu8, 0x96u8, 0x2Au8, 0x4Cu8, 0xAFu8, 0x12u8, 0xEEu8,
  43.             0x6Au8, 0x36u8, 0xABu8, 0xE0u8, 0x5Bu8, 0xA4u8, 0xF3u8, 0xD7u8, 0x0Fu8, 0x33u8, 0xD5u8,
  44.             0x5Au8, 0x48u8, 0x3Au8, 0x68u8, 0xEEu8, 0xC0u8, 0x93u8, 0xA1u8, 0x8Fu8, 0xEEu8, 0xC6u8,
  45.             0x5Cu8, 0x51u8, 0x52u8, 0xF6u8, 0x51u8, 0x6Au8, 0xBAu8, 0xAAu8, 0x57u8, 0xE4u8, 0x2Eu8,
  46.             0xABu8, 0xD0u8, 0xCAu8, 0x3Eu8, 0x07u8, 0x61u8, 0x3Cu8, 0xDCu8, 0x94u8, 0x5Eu8, 0x35u8,
  47.             0x71u8, 0xF2u8, 0xBDu8, 0xA1u8, 0x6Eu8, 0x93u8, 0x5Eu8, 0x77u8, 0xD7u8, 0x91u8, 0xFDu8,
  48.             0x91u8, 0xF0u8, 0x4Fu8, 0xF8u8, 0x9Bu8, 0x81u8, 0x78u8, 0x6Du8, 0x1Bu8, 0xB7u8, 0x1Du8,
  49.             0x59u8, 0x45u8, 0xE8u8, 0xB2u8, 0x77u8, 0x75u8, 0x39u8, 0x55u8, 0x30u8, 0xD1u8, 0xABu8,
  50.             0x5Eu8, 0xD4u8, 0x6Fu8, 0x03u8, 0x69u8, 0x78u8, 0xC9u8, 0x70u8, 0x3Du8, 0x4Eu8, 0x12u8,
  51.             0x49u8, 0xFFu8, 0x6Fu8, 0x8Fu8, 0xFBu8, 0x86u8, 0x8Bu8, 0x3Cu8, 0xA4u8, 0x33u8, 0xEEu8,
  52.             0xF8u8, 0x9Fu8, 0xDCu8, 0x9Fu8, 0xE3u8, 0xF7u8, 0x93u8, 0x7Du8, 0x0Fu8, 0x62u8, 0x56u8,
  53.             0x92u8, 0x1Fu8, 0x64u8, 0x7Fu8, 0x64u8, 0x76u8, 0x17u8, 0x81u8, 0x15u8, 0x7Du8, 0xD4u8,
  54.             0xEEu8, 0xE7u8, 0xB2u8, 0x46u8, 0xDAu8, 0xBAu8, 0xC2u8, 0x63u8, 0x8Bu8, 0xC6u8, 0x4Fu8,
  55.             0xBFu8, 0xBAu8, 0xECu8, 0x89u8, 0x82u8, 0xCCu8, 0x24u8, 0x3Du8, 0xE0u8, 0x69u8, 0x17u8,
  56.             0x3Du8, 0x91u8, 0x9Bu8, 0xB8u8, 0xF5u8, 0x52u8, 0xB9u8, 0x26u8, 0xBEu8, 0xF4u8, 0x76u8,
  57.             0x4Bu8, 0x16u8, 0xF3u8, 0x48u8, 0xC4u8, 0x99u8, 0xECu8, 0x8Fu8, 0xECu8, 0x94u8, 0x24u8,
  58.             0xFCu8, 0xB1u8, 0x9Eu8, 0xECu8, 0xFDu8, 0xC9u8, 0x78u8, 0xC8u8, 0xCFu8, 0x76u8, 0x40u8,
  59.             0xF6u8, 0x51u8, 0xF7u8, 0x35u8, 0x72u8, 0x7Bu8, 0xE7u8, 0x68u8, 0xD7u8, 0xE7u8, 0xC1u8,
  60.             0xBBu8, 0x4Du8, 0x26u8, 0x1Au8, 0x2Cu8, 0xFFu8, 0x5Du8, 0x4Au8, 0x46u8, 0x7Bu8, 0xB2u8,
  61.             0x3Eu8, 0xB1u8, 0x84u8, 0xFEu8, 0xE4u8, 0x85u8, 0xEAu8, 0x76u8, 0xFBu8, 0x24u8, 0xFFu8,
  62.             0x8Au8, 0x3Eu8, 0xEBu8, 0xC3u8, 0xB0u8, 0xFFu8, 0x6Cu8, 0x57u8, 0xA3u8, 0xB6u8, 0x5Eu8,
  63.             0xE2u8, 0x4Bu8, 0xD1u8, 0x7Bu8, 0xCEu8, 0x89u8,
  64.         ];
  65.         assert_eq!(super::huffman(kafka).as_slice(), out);
  66.     }
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand