-
Notifications
You must be signed in to change notification settings - Fork 7
/
decode_test.go
116 lines (95 loc) · 2.22 KB
/
decode_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package blurhash_test
import (
"image"
"image/png"
"io/ioutil"
"testing"
"github.com/matryer/is"
"github.com/bbrks/go-blurhash"
)
func TestDecodeRGBA(t *testing.T) {
for _, test := range testFixtures {
// skip tests without hashes
if test.hash == "" {
continue
}
t.Run(test.hash, func(t *testing.T) {
is := is.New(t)
img := image.NewRGBA(image.Rect(0, 0, 32, 32))
err := blurhash.DecodeDraw(img, test.hash, 1)
is.NoErr(err)
err = png.Encode(ioutil.Discard, img)
is.NoErr(err)
})
}
}
func TestDecode(t *testing.T) {
for _, test := range testFixtures {
// skip tests without hashes
if test.hash == "" {
continue
}
t.Run(test.hash, func(t *testing.T) {
is := is.New(t)
img, err := blurhash.Decode(test.hash, 32, 32, 1)
is.NoErr(err)
err = png.Encode(ioutil.Discard, img)
is.NoErr(err)
})
}
}
func TestComponents(t *testing.T) {
for _, test := range testFixtures {
// skip tests without expected component values
if test.hash == "" || test.xComp == 0 || test.yComp == 0 {
continue
}
t.Run(test.hash, func(t *testing.T) {
is := is.NewRelaxed(t)
x, y, err := blurhash.Components(test.hash)
is.NoErr(err) // unexpected error getting components
is.Equal(x, test.xComp) // blurhash component mismatch
is.Equal(y, test.yComp) // blurhash component mismatch
})
}
}
func BenchmarkComponents(b *testing.B) {
for _, test := range testFixtures {
// skip tests without hashes
if test.hash == "" {
continue
}
b.Run(test.hash, func(b *testing.B) {
for i := 0; i < b.N; i++ {
_, _, _ = blurhash.Components(test.hash)
}
})
}
}
func BenchmarkDecode(b *testing.B) {
for _, test := range testFixtures {
// skip tests without hashes
if test.hash == "" {
continue
}
b.Run(test.hash, func(b *testing.B) {
for i := 0; i < b.N; i++ {
_, _ = blurhash.Decode(test.hash, 32, 32, 1)
}
})
}
}
func BenchmarkDecodeDraw(b *testing.B) {
for _, test := range testFixtures {
// skip tests without hashes
if test.hash == "" {
continue
}
b.Run(test.hash, func(b *testing.B) {
for i := 0; i < b.N; i++ {
dst := image.NewRGBA(image.Rect(0, 0, 32, 32))
_ = blurhash.DecodeDraw(dst, test.hash, 1)
}
})
}
}