Exemplo n.º 1
0
        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
        }
Exemplo n.º 2
0
        public void Decoding()
        {
            NetHuffman.Coder coder = new NetHuffman.Coder(HuffmanTableDefinition.Basic_abcd);

            byte[] decoded = new byte[] { 97, 98, 99, 100 };
            byte[] buffer  = coder.Decode(new byte[] { 27 });

            Assert.AreEqual(decoded.Length, buffer.Length);
            for (int i = 0; i < buffer.Length; i++)
            {
                Assert.AreEqual(buffer[i], decoded[i]);
            }
        }
Exemplo n.º 3
0
        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]);
            }
        }
Exemplo n.º 4
0
        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));
        }