public Statistics Encode(string inputFilePath, string outputFilePath, HuffmanEncodeModel huffmanEncodeModel) { Statistics statiscs; IHuffmanCoderInterface huffmanCoderInterface; IStatisticsBuilder statisticsBuilder = new StatisticsBuilder(); using (IInputReader input = new InputReader(inputFilePath)) { ICoderOutputWriter output = new CoderOutputWriter(new ByteCreator(), new HeaderCreator()); if (huffmanEncodeModel == HuffmanEncodeModel.Standard) { huffmanCoderInterface = new StandardHuffmanCoderInterface(input, output); } else if (huffmanEncodeModel == HuffmanEncodeModel.Block) { huffmanCoderInterface = new PairHuffmanCoderInterface(input, output); } else { huffmanCoderInterface = new MarkowHuffmanCoderInterface(input, output); } huffmanCoderInterface.Encode(); System.IO.File.WriteAllBytes(outputFilePath, output.FileBytes); statiscs = statisticsBuilder.BuildStatistics(output.SymbolMap, output.Header, input.Size, output.Size); if (huffmanEncodeModel == HuffmanEncodeModel.Standard) { IHistogramBuilder histogramBuilder = new HistogramBuilder(); histogramBuilder.BuildHistogram(output.SymbolMap, outputFilePath); } } return(statiscs); }
public void MarkowCoderEncodeInput() { //given byte[] input = new byte[] { (byte)'A', (byte)'A', (byte)'B', (byte)'C', (byte)'A', (byte)'C', (byte)'D', (byte)'B', (byte)'A', (byte)'A' }; MockInputReader inputReader = new MockInputReader(input); MockCoderOutputWriter outputWriter = new MockCoderOutputWriter(); //when MarkowHuffmanCoderInterface markowHuffmanCoderInterface = new MarkowHuffmanCoderInterface(inputReader, outputWriter); markowHuffmanCoderInterface.Encode(); //then outputWriter.AssertSize(12); }