Example #1
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));
            }
        }
Example #2
0
        public void VerifyCompression_astrachan_()
        {
            var stream = new MemoryStream();
            string input = "astrachan_";
            var compressor = new StaticHuffman<char>(CharacterFrequencies(input));

            // Node ids:					     0    1    2    3    4    5    6    7  8     9    10    11    12     13      14
            // Weights:						     1    1    1    1    1    1    1    3  2     2     2     3     4      6      10
            var state = new TreeState(8, '_', 'c', 'h', 'n', 'r', 's', 't', 'a', 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 7, 11,
                                      12, 13);
            compressor.WriteTable(state.WriteSymbol, state.WriteUInt32);
            state.Final();

            var writer = new BitStreamWriter(stream, true);
            foreach (char ch in input)
            {
                compressor.WriteCode(ch, writer.Write);
            }
            writer.Flush();

            state.Reset();
            var decompressor = new StaticHuffman<char>(state.ReadSymbol, state.ReadUInt32);
            state.Final();
            state.Reset();
            decompressor.WriteTable(state.WriteSymbol, state.WriteUInt32);
            state.Final();

            stream.Position = 0;

            var reader = new BitStreamReader(stream, true);
            foreach (char ch in input)
            {
                Assert.AreEqual(ch, decompressor.GetSymbol(reader.ReadBoolean));
            }
        }
Example #3
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));
            }
        }
Example #4
0
        public void VerifyTable()
        {
            string input      = "astrachan_";
            var    compressor = new StaticHuffman <char>(CharacterFrequencies(input));

            // Node ids:					0    1    2    3    4    5    6    7    8     9    10    11    12     13      14
            // Weights:						1    1    1    1    1    1    1    3    2     2    2     3     4      6       10
            var state = new TreeState(8, '_', 'c', 'h', 'n', 'r', 's', 't', 'a', 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 7, 11,
                                      12, 13);

            compressor.WriteTable(state.WriteSymbol, state.WriteUInt32);
            state.Final();
        }
Example #5
0
        public void VerifyCompression_astrachan_()
        {
            var    stream     = new MemoryStream();
            string input      = "astrachan_";
            var    compressor = new StaticHuffman <char>(CharacterFrequencies(input));

            // Node ids:					     0    1    2    3    4    5    6    7  8     9    10    11    12     13      14
            // Weights:						     1    1    1    1    1    1    1    3  2     2     2     3     4      6      10
            var state = new TreeState(8, '_', 'c', 'h', 'n', 'r', 's', 't', 'a', 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 7, 11,
                                      12, 13);

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

            var writer = new BitStreamWriter(stream, true);

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

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

            state.Final();
            state.Reset();
            decompressor.WriteTable(state.WriteSymbol, state.WriteUInt32);
            state.Final();

            stream.Position = 0;

            var reader = new BitStreamReader(stream, true);

            foreach (char ch in input)
            {
                Assert.AreEqual(ch, decompressor.GetSymbol(reader.ReadBoolean));
            }
        }
Example #6
0
        public void VerifyTable()
        {
            string input = "astrachan_";
            var compressor = new StaticHuffman<char>(CharacterFrequencies(input));

            // Node ids:					0    1    2    3    4    5    6    7    8     9    10    11    12     13      14
            // Weights:						1    1    1    1    1    1    1    3    2     2    2     3     4      6       10
            var state = new TreeState(8, '_', 'c', 'h', 'n', 'r', 's', 't', 'a', 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 7, 11,
                                      12, 13);
            compressor.WriteTable(state.WriteSymbol, state.WriteUInt32);
            state.Final();
        }