Ejemplo n.º 1
0
        public void Encode_NumberOfBitsIsEqualsToNumberOfSymbolsEncoded()
        {
            //given
            var coder = new OneSymbolCoder <char>('a');
            var input = new MockCoderInput <char>(new List <char>()
            {
                'a', 'a', 'a', 'a'
            });
            var output = new MockCoderOutput();

            //when
            coder.Encode(input, output);
            //then
            output.AssertEquals(new List <int>()
            {
                1, 1, 1, 1
            });
        }
Ejemplo n.º 2
0
        public void Encode_FourNodes_BalancedTree()
        {
            //given
            var tree  = MockHuffmanTreeBuilder.Build('#', '#', 'a', 'b', 'c', 'd');
            var coder = new HuffmanCoder <char>(tree);
            var input = new MockCoderInput <char>(new List <char>()
            {
                'a', 'b', 'c', 'd'
            });
            var output = new MockCoderOutput();

            //when
            coder.Encode(input, output);
            //then
            output.AssertEquals(new List <int>()
            {
                0, 0, 0, 1, 1, 0, 1, 1
            });
        }
Ejemplo n.º 3
0
        public void Encode_ThreeNodes_TwoAreRight()
        {
            //given
            var tree  = MockHuffmanTreeBuilder.Build('c', '#', 'b', 'a');
            var coder = new HuffmanCoder <char>(tree);
            var input = new MockCoderInput <char>(new List <char>()
            {
                'a', 'b', 'c'
            });
            var output = new MockCoderOutput();

            //when
            coder.Encode(input, output);
            //then
            output.AssertEquals(new List <int>()
            {
                1, 1, 1, 0, 0
            });
        }