public void TestCompressionWithConfig(int size) { var strategy = new ArithmeticCodingStrategy(size); var data = new byte[TestBlockSize]; for (int i = 0; i < TestBlockSize; i++) { data[i] = (byte)(i * 128 + 1); } var memStream = new MemoryStream(); var compressingStream = new BruteCompressingStream(new BinaryWriter(memStream), TestBlockSize, strategy); compressingStream.Write(data, 0, TestBlockSize); compressingStream.Flush(); memStream.Seek(0, SeekOrigin.Begin); var decompressingStream = new BruteUncompressingStream(new BinaryReader(memStream)); var decompressingReader = new BinaryReader(decompressingStream); var readBlock = decompressingReader.ReadBytes(TestBlockSize); Assert.AreEqual(data, readBlock); }
public void TestCompressionWithConfig(ExternalCompressorConfig externalCompressorConfig, bool checkReduction) { var catCompressionConfig = externalCompressorConfig; var strategy = new ExternalCompressionStrategy(catCompressionConfig); var data = new byte[TestBlockSize]; for (int i = 0; i < TestBlockSize; i++) { data[i] = (byte)(i * 5); } var memStream = new MemoryStream(); var compressingStream = new BruteCompressingStream(new BinaryWriter(memStream), 65000, strategy); compressingStream.Write(data, 0, TestBlockSize); compressingStream.Flush(); if (checkReduction) { Assert.Less(memStream.Position, TestBlockSize); Console.WriteLine("Compressed {0} to {1} ({2}%)", TestBlockSize, memStream.Position, memStream.Position * 100 / TestBlockSize); } memStream.Seek(0, SeekOrigin.Begin); var decompressingStream = new BruteUncompressingStream(new BinaryReader(memStream)); var decompressingReader = new BinaryReader(decompressingStream); var readBlock = decompressingReader.ReadBytes(TestBlockSize); Assert.AreEqual(data, readBlock); }
public void TestSelectionStrategy() { var data = new byte[TestSize]; for (int i = 0; i < TestSize; i++) { data[i] = (byte)i; } var compressors = new ICompressionStrategy[TestSize]; for (int i = 0; i < TestSize; i++) { compressors[i] = new MockStrategy((byte)i); } var strategy = new BruteCompressionStrategy(compressors); var memStream = new MemoryStream(); var compressingStream = new BruteCompressingStream(new BinaryWriter(memStream), 1, strategy); compressingStream.Write(data, 0, TestSize); compressingStream.Flush(); Assert.AreEqual(memStream.Position, TestSize * 4); Console.WriteLine("Compressed {0} to {1} ({2}%)", TestSize, memStream.Position, memStream.Position * 100 / TestSize); }