Esempio n. 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();
            }
        }
Esempio n. 2
0
        public void PairDecoderDecodeOutput()
        {
            //given
            int[] input = new int[] { 1, 1, 0, 1, 0, 1, 1, 0 };
            MockDecoderFileWriter mockDecoderFileWriter = new MockDecoderFileWriter();
            var symbolQuantityDic = new Dictionary <string, ushort>()
            {
                { "AB", 2 },
                { "CA", 2 },
                { "BD", 1 }
            };
            MockDecoderReader mockDecoderReader = new MockDecoderReader(input, symbolQuantityDic);

            //when
            PairHuffmanDecoderInterface pairHuffmanDecoder = new PairHuffmanDecoderInterface(mockDecoderReader, mockDecoderFileWriter, true);

            pairHuffmanDecoder.Decode();

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