Пример #1
0
        public void Decode(string inputFilePath, string outputFilePath)
        {
            IHuffmanDecoderInterface huffmanDecoderInterface;

            using (IDecoderReader input = new DecoderReader(inputFilePath))
            {
                IDecoderFileWriter output = new DecoderFileWriter(outputFilePath);
                if (input.HuffmanEncodeModel == HuffmanEncodeModel.Standard)
                {
                    huffmanDecoderInterface = new StandardHuffmanDecoderInterface(input, output);
                }
                else if (input.HuffmanEncodeModel == HuffmanEncodeModel.Block)
                {
                    huffmanDecoderInterface = new PairHuffmanDecoderInterface(input, output, input.IsByteCountEven);
                }
                else
                {
                    huffmanDecoderInterface = new MarkowHuffmanDecoderInterface(input, output);
                }
                huffmanDecoderInterface.Decode();
                output.Save();
            }
        }
Пример #2
0
        public void MarkowDecoderDecodeOutput()
        {
            //given
            int[] input = new int[] { 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0 };
            MockDecoderFileWriter mockDecoderFileWriter = new MockDecoderFileWriter();
            var symbolQuantityDic = new Dictionary <string, ushort>()
            {
                { "A", 1 },
                { "AA", 2 },
                { "AB", 1 },
                { "AC", 1 },
                { "BC", 1 },
                { "BA", 1 },
                { "CA", 1 },
                { "CD", 1 },
                { "DB", 1 }
            };
            //{
            //    { new DefaultableSymbol<byte>(true), new Dictionary<byte, int>()
            //        {
            //            {(byte) 'A', 1}
            //        }
            //    },
            //    { new DefaultableSymbol<byte>((byte) 'A'), new Dictionary<byte, int>()
            //        {
            //            {(byte) 'A', 2},
            //            {(byte) 'B', 1},
            //            {(byte) 'C', 1}
            //        }
            //    },
            //    { new DefaultableSymbol<byte>((byte) 'B'), new Dictionary<byte, int>()
            //        {
            //            {(byte) 'C', 1},
            //            {(byte) 'A', 1}
            //        }
            //    },
            //    { new DefaultableSymbol<byte>((byte) 'C'), new Dictionary<byte, int>()
            //        {
            //            {(byte) 'A', 1},
            //            {(byte) 'D', 1}
            //        }
            //    },
            //    { new DefaultableSymbol<byte>((byte) 'D'), new Dictionary<byte, int>()
            //        {
            //            {(byte) 'B', 1}
            //        }
            //    },
            //};

            MockDecoderReader mockDecoderReader = new MockDecoderReader(input, symbolQuantityDic);

            //when
            MarkowHuffmanDecoderInterface markowHuffmanDecoder = new MarkowHuffmanDecoderInterface(mockDecoderReader, mockDecoderFileWriter);

            markowHuffmanDecoder.Decode();

            //then
            mockDecoderFileWriter.AssertEquals(new List <byte>()
            {
                (byte)'A', (byte)'A', (byte)'B', (byte)'C', (byte)'A', (byte)'C', (byte)'D', (byte)'B', (byte)'A', (byte)'A'
            });
        }