コード例 #1
0
        public void Decode_FourSymbols_DeepTree()
        {
            //given
            var tree    = MockHuffmanTreeBuilder.Build('a', '#', 'b', '#', 'c', 'd');
            var decoder = new HuffmanDecoder <char>(tree);
            var input   = new MockDecoderInput(new List <int> {
                0, 1, 0, 1, 1, 0, 1, 1, 1
            });
            var output = new MockDecoderOutput(new List <char> {
                'a', 'b', 'c', 'd'
            });

            //when
            decoder.Decode(input, output);
            //then
            output.AssertCorrectOutput();
        }
コード例 #2
0
        public void Decode_ThreeSymbols_TwoAreRight()
        {
            //given
            var tree    = MockHuffmanTreeBuilder.Build('c', '#', 'x', 'a');
            var decoder = new HuffmanDecoder <char>(tree);
            var input   = new MockDecoderInput(new List <int> {
                0, 1, 1, 1, 0
            });
            var output = new MockDecoderOutput(new List <char> {
                'c', 'a', 'x'
            });

            //when
            decoder.Decode(input, output);
            //then
            output.AssertCorrectOutput();
        }
コード例 #3
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
            });
        }
コード例 #4
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
            });
        }