-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtransform_test.go
64 lines (57 loc) · 1.26 KB
/
transform_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
package imagecoding
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestTransform(t *testing.T) {
sample, err := os.ReadFile("testdata/gamer.png")
if !assert.NoError(t, err) {
t.FailNow()
}
img, _, _, _, err := Transform(sample, true, DefaultScale)
if assert.NoError(t, err) {
assert.Equal(t, 1240, img.Bounds().Dx())
assert.Equal(t, 1317, img.Bounds().Dy())
}
}
func TestTransformNoError(t *testing.T) {
tests := []struct {
name string
filename string
}{
{
"world",
"testdata/world-political.jpg",
},
}
for _, tt := range tests {
sample, err := os.ReadFile(tt.filename)
if !assert.NoError(t, err) {
t.FailNow()
}
t.Run(tt.name, func(t *testing.T) {
_, _, _, _, err := Transform(sample, true, DefaultScale)
assert.NoError(t, err)
})
}
}
func TestTransformEmpty(t *testing.T) {
empty := []byte{}
_, _, _, _, err := Transform(empty, true, DefaultScale)
if assert.Error(t, err) {
assert.Equal(t, ErrEmptyInput, err)
}
}
func BenchmarkPNGTransform(b *testing.B) {
sample, err := os.ReadFile("testdata/gamer.png")
if !assert.NoError(b, err) {
b.FailNow()
}
for n := 0; n < b.N; n++ {
_, _, _, _, err := Transform(sample, true, DefaultScale)
if !assert.NoError(b, err) {
b.FailNow()
}
}
}