//[TestMethod]
        // Disabled for now.  Decreases are not guaranteed symmetric with increases.
        public void VerifyBulkUpdateDecrease()
        {
            string originalInput      = "astrachan_";
            var    originalCompressor = new DynamicHuffman <char>(OriginalNYT);

            var originalTreeState = new TreeStateStore();

            for (int i = 0; i < originalInput.Length; ++i)
            {
                originalCompressor.WriteCode(originalInput[i], (bit) => { }, (symbol) => { });
            }

            originalCompressor.WriteTable(originalTreeState.WriteSymbol, originalTreeState.WriteUInt32,
                                          originalTreeState.WriteNotYetTransmitted);

            string partialInput   = "astrachan";
            var    bulkCompressor = new DynamicHuffman <char>(OriginalNYT);

            for (int i = 0; i < partialInput.Length; ++i)
            {
                bulkCompressor.WriteCode(partialInput[i], (bit) => { }, (symbol) => { });
            }

            bulkCompressor.UpdateSymbol('_', 8);
            bulkCompressor.UpdateSymbol('_', -7);

            var bulkTreeState = new TreeStateStore();

            bulkCompressor.WriteTable(bulkTreeState.WriteSymbol, bulkTreeState.WriteUInt32,
                                      bulkTreeState.WriteNotYetTransmitted);

            CollectionAssert.AreEqual(originalTreeState, bulkTreeState);
        }
Ejemplo n.º 2
0
        public void VerifyCompression_LargeCorpus()
        {
            var    stream     = new MemoryStream();
            var    writer     = new BitStreamWriter(stream, true);
            var    reader     = new BitStreamReader(stream, true);
            string input      = TestResources.RFC5_Text;
            var    state      = new TreeStateStore();
            var    compressor = new StaticHuffman <char>(CharacterFrequencies(input));

            compressor.WriteTable(state.WriteSymbol, state.WriteUInt32);

            foreach (char ch in input)
            {
                compressor.WriteCode(ch, writer.Write);
            }
            writer.Flush();

            state.Reset();

            var decompressor = new StaticHuffman <char>(state.ReadSymbol, state.ReadUInt32);

            stream.Position = 0;

            foreach (char ch in input)
            {
                Assert.AreEqual(ch, decompressor.GetSymbol(reader.ReadBoolean));
            }
        }