File: lz4_test.go

package info (click to toggle)
golang-github-bkaradzic-go-lz4 1.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 688 kB
  • sloc: makefile: 7
file content (63 lines) | stat: -rw-r--r-- 981 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package lz4

import (
	"bytes"
	"io/ioutil"
	"testing"
)

var testfile, _ = ioutil.ReadFile("testdata/pg1661.txt")

func roundtrip(t *testing.T, input []byte) {

	dst, err := Encode(nil, input)
	if err != nil {
		t.Errorf("got error during compression: %s", err)
	}

	output, err := Decode(nil, dst)

	if err != nil {
		t.Errorf("got error during decompress: %s", err)
	}

	if !bytes.Equal(output, input) {
		t.Errorf("roundtrip failed")
	}
}

func TestEmpty(t *testing.T) {
	roundtrip(t, nil)
}

func TestLengths(t *testing.T) {

	for i := 0; i < 1024; i++ {
		roundtrip(t, testfile[:i])
	}

	for i := 1024; i < 4096; i += 23 {
		roundtrip(t, testfile[:i])
	}
}

func TestWords(t *testing.T) {
	roundtrip(t, testfile)
}

func BenchmarkLZ4Encode(b *testing.B) {
	for i := 0; i < b.N; i++ {
		Encode(nil, testfile)
	}
}

func BenchmarkLZ4Decode(b *testing.B) {

	var compressed, _ = Encode(nil, testfile)

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		Decode(nil, compressed)
	}
}