예제 #1
0
        private static void Test(string input)
        {
            var encoder      = new HuffmanCode.Encoder();
            var inStream     = new MemoryStream(Encoding.Default.GetBytes(input));
            var outStream    = new MemoryStream();
            var resultStream = new MemoryStream();

            encoder.Encode(inStream, outStream);
            encoder.Decode(outStream, resultStream);
            var result = Encoding.Default.GetString(resultStream.GetBuffer()
                                                    .Take(input.Length)
                                                    .ToArray());

            Assert.AreEqual(input, result);
        }
예제 #2
0
        private static void BigTest(string path)
        {
            var encoder  = new HuffmanCode.Encoder();
            var inStream = new FileStream(path, FileMode.Open, FileAccess.Read);
            var bytes    = new byte[inStream.Length];

            inStream.Read(bytes);
            inStream.Seek(0, SeekOrigin.Begin);
            var file         = Encoding.Default.GetString(bytes);
            var outStream    = new MemoryStream();
            var resultStream = new MemoryStream();

            encoder.Encode(inStream, outStream);
            encoder.Decode(outStream, resultStream);
            var result = Encoding.Default.GetString(resultStream.GetBuffer()
                                                    .Take((int)inStream.Length)
                                                    .ToArray());

            Assert.AreEqual(file, result);
        }