github.com/aquanetwork/aquachain@v1.7.8/opt/compression/rle/read_write_test.go (about)

     1  // Copyright 2014 The aquachain Authors
     2  // This file is part of the aquachain library.
     3  //
     4  // The aquachain library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The aquachain library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the aquachain library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package rle
    18  
    19  import (
    20  	"testing"
    21  
    22  	checker "gopkg.in/check.v1"
    23  )
    24  
    25  func Test(t *testing.T) { checker.TestingT(t) }
    26  
    27  type CompressionRleSuite struct{}
    28  
    29  var _ = checker.Suite(&CompressionRleSuite{})
    30  
    31  func (s *CompressionRleSuite) TestDecompressSimple(c *checker.C) {
    32  	exp := []byte{0xc5, 0xd2, 0x46, 0x1, 0x86, 0xf7, 0x23, 0x3c, 0x92, 0x7e, 0x7d, 0xb2, 0xdc, 0xc7, 0x3, 0xc0, 0xe5, 0x0, 0xb6, 0x53, 0xca, 0x82, 0x27, 0x3b, 0x7b, 0xfa, 0xd8, 0x4, 0x5d, 0x85, 0xa4, 0x70}
    33  	res, err := Decompress([]byte{token, 0xfd})
    34  	c.Assert(err, checker.IsNil)
    35  	c.Assert(res, checker.DeepEquals, exp)
    36  
    37  	exp = []byte{0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e, 0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x1, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21}
    38  	res, err = Decompress([]byte{token, 0xfe})
    39  	c.Assert(err, checker.IsNil)
    40  	c.Assert(res, checker.DeepEquals, exp)
    41  
    42  	res, err = Decompress([]byte{token, 0xff})
    43  	c.Assert(err, checker.IsNil)
    44  	c.Assert(res, checker.DeepEquals, []byte{token})
    45  
    46  	res, err = Decompress([]byte{token, 12})
    47  	c.Assert(err, checker.IsNil)
    48  	c.Assert(res, checker.DeepEquals, make([]byte, 10))
    49  
    50  }