Skip to content

Commit 0881b34

Browse files
committed
Add test
1 parent 24fc5de commit 0881b34

File tree

6 files changed

+44
-7
lines changed

6 files changed

+44
-7
lines changed

internal/lzss/README.md

Whitespace-only changes.

internal/lzss/lzss_test.go

+43-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,50 @@
11
package lzss
22

33
import (
4-
"fmt"
4+
"bytes"
5+
"io/ioutil"
56
"testing"
67
)
78

8-
func TestContains(t *testing.T) {
9-
buf := []byte("ciao a tutti")
10-
occ := []byte("tut")
11-
fmt.Println(contains(buf, occ))
12-
occ = []byte("ti")
13-
fmt.Println(contains(buf, occ))
9+
func TestEncode(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
infile string
13+
outfile string
14+
}{
15+
{
16+
name: "lorem",
17+
infile: "testdata/lorem.txt",
18+
outfile: "testdata/lorem.lzss",
19+
},
20+
{
21+
name: "short",
22+
infile: "testdata/short.txt",
23+
outfile: "testdata/short.lzss",
24+
},
25+
{
26+
name: "blink",
27+
infile: "testdata/blink.bin",
28+
outfile: "testdata/blink.lzss",
29+
},
30+
}
31+
32+
for _, tt := range tests {
33+
t.Run(tt.name, func(t *testing.T) {
34+
input, err := ioutil.ReadFile(tt.infile)
35+
if err != nil {
36+
t.Fatal("couldn't open test file")
37+
}
38+
39+
want, err := ioutil.ReadFile(tt.outfile)
40+
if err != nil {
41+
t.Fatal("couldn't open test file")
42+
}
43+
44+
got := Encode(input)
45+
if !bytes.Equal(want, got) {
46+
t.Error("encoding failed")
47+
}
48+
})
49+
}
1450
}

internal/lzss/testdata/blink.bin

11.2 KB
Binary file not shown.

internal/lzss/testdata/blink.lzss

9.36 KB
Binary file not shown.

internal/lzss/testdata/short.lzss

63 Bytes
Binary file not shown.

internal/lzss/testdata/short.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lorem ipsum dolor sit amet, consectetur adipiscing elit.

0 commit comments

Comments
 (0)