public void CompressContentTest() { Stream s = File.OpenWrite(@"D:\MFF\ZS_2019\c#_repos\Huffman1\Huffman1Tests\bin\Debug\netcoreapp3.0\TestFiles\Huff2\Outs\Compressed.out"); BinaryWriter writer = new BinaryWriter(s); Stream ins = File.OpenRead(@"D:\MFF\ZS_2019\c#_repos\Huffman1\Huffman1Tests\bin\Debug\netcoreapp3.0\TestFiles\Huff2\Ins\simple4.in"); BinaryReader reader = new BinaryReader(ins); HuffmanReader HuffReader = new HuffmanReader(reader); bool NotEmpty = HuffReader.ReadFileUsingBuffer(); //Build Huffman tree TreeBuilder Builder = new TreeBuilder(HuffReader.ProvideSymbolsWihtWeights()); Node Root = Builder.BuildHuffTree(); ins.Seek(0, 0); HuffCompresor.CompressContent(Root, writer, reader); writer.Close(); reader.Close(); bool same = Utils.FileDiff(@"D:\MFF\ZS_2019\c#_repos\Huffman1\Huffman1Tests\bin\Debug\netcoreapp3.0\TestFiles\Huff2\Outs\Compressed.huff", @"D:\MFF\ZS_2019\c#_repos\Huffman1\Huffman1Tests\bin\Debug\netcoreapp3.0\TestFiles\Huff2\Outs\Compressed.out"); Assert.IsTrue(same); }
public void CodeBytesTest() //no assert! { Stream ins = File.OpenRead(@"D:\MFF\ZS_2019\c#_repos\Huffman1\Huffman1Tests\bin\Debug\netcoreapp3.0\TestFiles\Huff2\Ins\simple4.in"); BinaryReader reader = new BinaryReader(ins); HuffmanReader HuffReader = new HuffmanReader(reader); bool NotEmpty = HuffReader.ReadFileUsingBuffer(); //Build Huffman tree TreeBuilder Builder = new TreeBuilder(HuffReader.ProvideSymbolsWihtWeights()); Node Root = Builder.BuildHuffTree(); TreePrinter.PrintNiceTree(Root, 0); Stack <byte> path = new Stack <byte>(); HuffCompresor.CodeBytes(Root, path); for (int i = 0; i < HuffCompresor.Codes.Length; i++) { if (HuffCompresor.Codes[i] != null) { Console.Write($"{i}: "); for (int j = 0; j < HuffCompresor.Codes[i].Length; j++) { Console.Write($"{HuffCompresor.Codes[i][j]} "); } Console.WriteLine(); } } }
public void PrintNiceTreeTest() { ulong[] Test = new ulong[256]; Test[97] = 6; Test[98] = 2; Test[32] = 5; Test[99] = 5; Test[100] = 1; Test[101] = 2; Test[102] = 2; Test[52] = 2; TreeBuilder builder = new TreeBuilder(Test); Node Root = builder.BuildHuffTree(); TreePrinter.PrintNiceTree(Root, 0); }
public void PrintCompresedTreeTest() { ulong[] Test = new ulong[256]; Test[97] = 6; Test[98] = 2; Test[32] = 5; Test[99] = 5; Test[100] = 1; Test[101] = 2; Test[102] = 2; Test[52] = 2; TreeBuilder builder = new TreeBuilder(Test); Node Root = builder.BuildHuffTree(); StreamWriter sw = new StreamWriter(@"TestFiles\myCompresTree.txt"); TreePrinter.PrintCompresedTree(Root, sw); //sw.Flush(); }
public void JustPrintTree() { string inputFile = @"TestFiles\Huff3Tests\simple4.in"; string[] args = new string[1]; args[0] = inputFile; bool opened = Program.OpenFile(args, out BinaryReader Reader, out BinaryWriter Writer); if (!opened) { return; } //create HuffmanReader, that is going to count occurences of bytes in input file HuffmanReader HuffReader = new HuffmanReader(Reader); bool NotEmpty = HuffReader.ReadFileUsingBuffer(); //Build Huffman tree TreeBuilder Builder = new TreeBuilder(HuffReader.ProvideSymbolsWihtWeights()); Node Root = Builder.BuildHuffTree(); TreePrinter.PrintNiceTree(Root, 0); Reader.Close(); Writer.Close(); }