public void AddFileTest1() { TestIPlatformService platform = new TestIPlatformService { ReadFileFunc = x => new MemoryStream() }; TestIEncodingOutputStream stream = new TestIEncodingOutputStream(); builder.Initialize(platform, EmptyEncodingToken.Instance, stream); builder.AddFile(new FileSegment(@"file.bin", @"C:\file.bin"), CancellationToken.None, null); IReadOnlyList <Bit> bitList = BitListHelper.CreateBuilder() .AddByte(0x00) .AddInt(0x10) .AddChar('f') .AddChar('i') .AddChar('l') .AddChar('e') .AddChar('.') .AddChar('b') .AddChar('i') .AddChar('n') .AddLong(0x0).BitList; Assert.AreEqual(bitList, stream.BitList); }
public void AddWeightsTableTest3() { TestIEncodingOutputStream stream = new TestIEncodingOutputStream(); builder.Initialize(new TestIPlatformService(), EmptyEncodingToken.Instance, stream); WeightsTable weightsTable = new WeightsTable(); weightsTable.TrackSymbol(0x1); weightsTable.TrackSymbol(symbol: 0xF, frequency: 0x5); weightsTable.TrackSymbol(symbol: 0x2, frequency: 0xFFF); weightsTable.TrackSymbol(symbol: 0xAF, frequency: 0xFFA); weightsTable.TrackSymbol(0xFF); builder.AddWeightsTable(new BootstrapSegment(weightsTable)); IReadOnlyList <Bit> bitList = BitListHelper.CreateBuilder() .AddByte(0x2) .AddInt(0x2D) .AddByte(0x1) .AddLong(0x1) .AddByte(0x2) .AddLong(0xFFF) .AddByte(0xF) .AddLong(0x5) .AddByte(0xAF) .AddLong(0xFFA) .AddByte(0xFF) .AddLong(0x1).BitList; Assert.AreEqual(bitList, stream.BitList); }
public void AddFileTest2() { byte[] data = { 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 }; TestIPlatformService platform = new TestIPlatformService { ReadFileFunc = x => new MemoryStream(data) }; TestIEncodingOutputStream stream = new TestIEncodingOutputStream(); HuffmanEncoder encoder = new HuffmanEncoder(); builder.Initialize(platform, CreateEncodingToken(encoder, data), stream); builder.AddFile(new FileSegment(@"data.bin", @"C:\data.bin"), CancellationToken.None, null); IReadOnlyList <Bit> bitList = BitListHelper.CreateBuilder() .AddByte(0x00) .AddInt(0x10) .AddChar('d') .AddChar('a') .AddChar('t') .AddChar('a') .AddChar('.') .AddChar('b') .AddChar('i') .AddChar('n') .AddLong(0x19)//bits .AddByte(0x20) .AddByte(0x55) .AddByte(0xFF) .AddByte(0x01).BitList; Assert.AreEqual(bitList, stream.BitList); }
public void ParseWeightsTableTest3() { IReadOnlyList <Bit> data = BitListHelper.CreateBuilder() .AddInt(0x2D) .AddByte(0x1) .AddLong(0x1) .AddByte(0x2) .AddLong(0xFFF) .AddByte(0xF) .AddLong(0x5) .AddByte(0xAF) .AddLong(0xFFA) .AddByte(0xFF) .AddLong(0x1).BitList; BootstrapSegment segment = streamParser.ParseWeightsTable(new TestIDecodingInputStream(data)); Assert.IsNotNull(segment); WeightsTable weightsTable = segment.WeightsTable; Assert.IsNotNull(weightsTable); WeightedSymbol[] expectedSymbols = { new WeightedSymbol(0x1, 0x1), new WeightedSymbol(0x2, 0xFFF), new WeightedSymbol(0xF, 0x5), new WeightedSymbol(0xAF, 0xFFA), new WeightedSymbol(0xFF, 1), }; Assert.AreEqual(expectedSymbols, weightsTable); }
public void ParseFileTest1() { IReadOnlyList <Bit> data = BitListHelper.CreateBuilder() .AddInt(0x10) .AddChar('f') .AddChar('i') .AddChar('l') .AddChar('e') .AddChar('.') .AddChar('b') .AddChar('i') .AddChar('n') .AddLong(0x0).BitList; FileSegment segment = streamParser.ParseFile(new TestIDecodingInputStream(data), new WeightsTable()); Assert.IsNotNull(segment); Assert.AreEqual("file.bin", segment.Name); Assert.IsNull(segment.Path); IFileDecoder decoder = segment.FileDecoder; Assert.IsNotNull(decoder); TestIDecodingOutputStream outputStream = new TestIDecodingOutputStream(); decoder.Decode(outputStream, CancellationToken.None, null); CollectionAssert.IsEmpty(outputStream.ByteList); }
public void AddWeightsTableTest1() { TestIEncodingOutputStream stream = new TestIEncodingOutputStream(); builder.Initialize(new TestIPlatformService(), EmptyEncodingToken.Instance, stream); builder.AddWeightsTable(new BootstrapSegment(new WeightsTable())); IReadOnlyList <Bit> bitList = BitListHelper.CreateBuilder() .AddByte(0x2) .AddInt(0x0).BitList; Assert.AreEqual(bitList, stream.BitList); }
public void ParseWeightsTableTest1() { IReadOnlyList <Bit> data = BitListHelper.CreateBuilder() .AddInt(0x0).BitList; BootstrapSegment segment = streamParser.ParseWeightsTable(new TestIDecodingInputStream(data)); Assert.IsNotNull(segment); WeightsTable weightsTable = segment.WeightsTable; Assert.IsNotNull(weightsTable); Assert.AreEqual(0, weightsTable.Size); }
public void ParseDirectoryTest2() { IReadOnlyList <Bit> data = BitListHelper.CreateBuilder() .AddInt(0x12) .AddString("Directory") .AddInt(0x5).BitList; DirectorySegment segment = streamParser.ParseDirectory(new TestIDecodingInputStream(data)); Assert.IsNotNull(segment); Assert.AreEqual("Directory", segment.Name); Assert.AreEqual(5, segment.Cardinality); }
public void AddDirectoryTest2() { TestIEncodingOutputStream stream = new TestIEncodingOutputStream(); builder.Initialize(new TestIPlatformService(), EmptyEncodingToken.Instance, stream); builder.AddDirectory(new DirectorySegment("Directory", 3)); IReadOnlyList <Bit> bitList = BitListHelper.CreateBuilder() .AddByte(0x1) .AddInt(0x12) .AddString("Directory") .AddInt(0x3).BitList; Assert.AreEqual(bitList, stream.BitList); }
public void ParseWeightsTableTest2() { IReadOnlyList <Bit> data = BitListHelper.CreateBuilder() .AddInt(0x9) .AddByte(0x45) .AddLong(0x33).BitList; BootstrapSegment segment = streamParser.ParseWeightsTable(new TestIDecodingInputStream(data)); Assert.IsNotNull(segment); WeightsTable weightsTable = segment.WeightsTable; Assert.IsNotNull(weightsTable); WeightedSymbol[] expectedSymbols = { new WeightedSymbol(0x45, 0x33) }; Assert.AreEqual(expectedSymbols, weightsTable); }
public void ParseFileTest2() { IReadOnlyList <Bit> data = BitListHelper.CreateBuilder() .AddInt(0x10) .AddChar('d') .AddChar('a') .AddChar('t') .AddChar('a') .AddChar('.') .AddChar('b') .AddChar('i') .AddChar('n') .AddLong(0x19) .AddByte(0x20) .AddByte(0x55) .AddByte(0xFF) .AddByte(0x01).BitList; WeightsTable weightsTable = new WeightsTable(); weightsTable.TrackSymbol(1, 1); weightsTable.TrackSymbol(2, 2); weightsTable.TrackSymbol(3, 4); weightsTable.TrackSymbol(4, 8); FileSegment segment = streamParser.ParseFile(new TestIDecodingInputStream(data), weightsTable); Assert.IsNotNull(segment); Assert.AreEqual("data.bin", segment.Name); Assert.IsNull(segment.Path); IFileDecoder decoder = segment.FileDecoder; Assert.IsNotNull(decoder); TestIDecodingOutputStream outputStream = new TestIDecodingOutputStream(); decoder.Decode(outputStream, CancellationToken.None, null); byte[] expectedData = { 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 }; Assert.AreEqual(expectedData, outputStream.ByteList); }