-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathimage_test.go
43 lines (41 loc) · 1.37 KB
/
image_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
package main
import (
"image"
"image/color"
"testing"
)
func TestAnalyzeAlpha(t *testing.T) {
// Define list of rectangles and if they should be contained within a
var testCases = []struct {
Image [][]color.RGBA
ShouldHaveAlphaPixel bool
ShouldSkip bool
}{
{[][]color.RGBA{
{{R: 0xff, G: 0xff, B: 0xff, A: 0xff}, {R: 0xff, G: 0xff, B: 0xff, A: 0xff}},
{{R: 0xff, G: 0xff, B: 0xff, A: 0xff}, {R: 0xff, G: 0xff, B: 0xff, A: 0xff}},
}, false, false},
{[][]color.RGBA{
{{R: 0xff, G: 0xff, B: 0xff, A: 0}, {R: 0xff, G: 0xff, B: 0xff, A: 0}},
{{R: 0xff, G: 0xff, B: 0xff, A: 0}, {R: 0xff, G: 0xff, B: 0xff, A: 0}},
}, true, true},
{[][]color.RGBA{
{{R: 0xff, G: 0xff, B: 0xff, A: 0xff}, {R: 0xff, G: 0xff, B: 0xff, A: 0}},
{{R: 0xff, G: 0xff, B: 0xff, A: 0}, {R: 0xff, G: 0xff, B: 0xff, A: 0}},
}, true, false},
}
for idx, tc := range testCases {
img := image.NewRGBA(image.Rect(0, 0, 2, 2))
for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ {
for x := img.Bounds().Min.X; x < img.Bounds().Max.X; x++ {
img.SetRGBA(x, y, tc.Image[x][y])
}
}
skip, hasAlpha := analyzeAlpha(img)
t.Logf("Test Case %d => hasAlphaPixel=%t (expecting %t) skip=%t (expecting %t)\n", idx+1,
hasAlpha, tc.ShouldHaveAlphaPixel, skip, tc.ShouldSkip)
if tc.ShouldHaveAlphaPixel != hasAlpha || tc.ShouldSkip != skip {
t.Fail()
}
}
}