-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder_test.go
59 lines (48 loc) · 1.09 KB
/
decoder_test.go
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
package go_qoi
import (
"image"
"io/ioutil"
"path"
"testing"
"github.com/stretchr/testify/assert"
)
func TestDecoder(t *testing.T) {
dir := "qoi_test_images"
files, err := ioutil.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
for _, f := range files {
name := f.Name()
ext := name[len(name)-4:]
if ext != ".qoi" {
continue
}
t.Run(name, func(t *testing.T) {
t.Parallel()
qoiImg, err := ReadQoiFile(path.Join(dir, name))
assert.Nil(t, err)
pngImg, err := ReadPngFile(path.Join(dir, name[:len(name)-3]+"png"))
assert.Nil(t, err)
assertEqualImages(t, pngImg, qoiImg)
})
}
}
func assertEqualImages(t *testing.T, expected, actual image.Image) {
cond := func() bool {
b := actual.Bounds()
assert.Equal(t, expected.Bounds(), b)
for x := b.Min.X; x < b.Max.X; x++ {
for y := b.Min.Y; y < b.Max.Y; y++ {
exPx := colorToNRGBA(expected.At(x, y))
acPx := colorToNRGBA(actual.At(x, y))
ok := assert.Equalf(t, exPx, acPx, "pixel at (%d,%d) should match", x, y)
if !ok {
return false
}
}
}
return true
}
assert.Condition(t, cond)
}