public void Encoding() { NetHuffman.Coder coder = new NetHuffman.Coder(HuffmanTableDefinition.Basic_abcd); byte[] buffer = coder.Encode(System.Text.Encoding.UTF8.GetBytes("abcd")); Assert.AreEqual(buffer.Length, 1); Assert.AreEqual(buffer[0], 27); // Index 0 should be 27 if encoded correctly }
public void EncodingAndDecoding() { NetHuffman.Coder coder = new NetHuffman.Coder(HuffmanTableDefinition.Basic_abcd); byte[] buffer = System.Text.Encoding.UTF8.GetBytes("abcd"); byte[] decoded = coder.Decode(coder.Encode(buffer)); Assert.AreEqual(buffer.Length, decoded.Length); for (int i = 0; i < buffer.Length; i++) { Assert.AreEqual(buffer[i], decoded[i]); } }
static void Main(string[] args) { NetHuffman.Tree tree = new NetHuffman.Tree(); tree.BuildDictionary("this is just a test"); NetHuffman.Coder coder = new NetHuffman.Coder(tree); byte[] decoded = Encoding.UTF8.GetBytes("this is just a test"); Console.WriteLine(decoded.Length); byte[] encoded; uint size = coder.Encode(decoded, out encoded); Console.WriteLine(encoded.Length); coder.Decode(encoded, out decoded, size); Console.WriteLine(Encoding.UTF8.GetString(decoded)); }