diff options
author | obscuren <geffobscura@gmail.com> | 2014-11-03 06:33:06 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-11-03 06:33:06 +0800 |
commit | 9f8bcf3abca8c6c32efc384f6c6eda1677b769c5 (patch) | |
tree | 081d285f1ba5a38bf3708c53094f0966e11eee93 /compression/rle/read_write_test.go | |
parent | 1bb398f4e22feef8f83fedd8a525e4da5b627773 (diff) | |
download | dexon-9f8bcf3abca8c6c32efc384f6c6eda1677b769c5.tar.gz dexon-9f8bcf3abca8c6c32efc384f6c6eda1677b769c5.tar.zst dexon-9f8bcf3abca8c6c32efc384f6c6eda1677b769c5.zip |
Added RLE compression. Closes #171
Diffstat (limited to 'compression/rle/read_write_test.go')
-rw-r--r-- | compression/rle/read_write_test.go | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/compression/rle/read_write_test.go b/compression/rle/read_write_test.go new file mode 100644 index 000000000..944822a47 --- /dev/null +++ b/compression/rle/read_write_test.go @@ -0,0 +1,93 @@ +package rle + +import ( + "bytes" + "testing" + + "github.com/ethereum/go-ethereum/crypto" +) + +func TestDecompressSimple(t *testing.T) { + res, err := Decompress([]byte{token, 0xfd}) + if err != nil { + t.Error(err) + } + if bytes.Compare(res, crypto.Sha3([]byte(""))) != 0 { + t.Error("empty sha3", res) + } + + res, err = Decompress([]byte{token, 0xfe}) + if err != nil { + t.Error(err) + } + if bytes.Compare(res, crypto.Sha3([]byte{0x80})) != 0 { + t.Error("0x80 sha3", res) + } + + res, err = Decompress([]byte{token, 0xff}) + if err != nil { + t.Error(err) + } + if bytes.Compare(res, []byte{token}) != 0 { + t.Error("token", res) + } + + res, err = Decompress([]byte{token, 12}) + if err != nil { + t.Error(err) + } + if bytes.Compare(res, make([]byte, 10)) != 0 { + t.Error("10 * zero", res) + } +} + +func TestDecompressMulti(t *testing.T) { + res, err := Decompress([]byte{token, 0xfd, token, 0xfe, token, 12}) + if err != nil { + t.Error(err) + } + + var exp []byte + exp = append(exp, crypto.Sha3([]byte(""))...) + exp = append(exp, crypto.Sha3([]byte{0x80})...) + exp = append(exp, make([]byte, 10)...) + + if bytes.Compare(res, res) != 0 { + t.Error("Expected", exp, "result", res) + } +} + +func TestCompressSimple(t *testing.T) { + res := Compress([]byte{0, 0, 0, 0, 0}) + if bytes.Compare(res, []byte{token, 7}) != 0 { + t.Error("5 * zero", res) + } + + res = Compress(crypto.Sha3([]byte(""))) + if bytes.Compare(res, []byte{token, emptyShaToken}) != 0 { + t.Error("empty sha", res) + } + + res = Compress(crypto.Sha3([]byte{0x80})) + if bytes.Compare(res, []byte{token, emptyListShaToken}) != 0 { + t.Error("empty list sha", res) + } + + res = Compress([]byte{token}) + if bytes.Compare(res, []byte{token, tokenToken}) != 0 { + t.Error("token", res) + } +} + +func TestCompressMulti(t *testing.T) { + in := []byte{0, 0, 0, 0, 0} + in = append(in, crypto.Sha3([]byte(""))...) + in = append(in, crypto.Sha3([]byte{0x80})...) + in = append(in, token) + res := Compress(in) + + exp := []byte{token, 7, token, emptyShaToken, token, emptyListShaToken, token, tokenToken} + if bytes.Compare(res, exp) != 0 { + t.Error("expected", exp, "got", res) + } +} |