Huffman encoding with tests