forked from smart--petea/pixl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalize_test.go
52 lines (44 loc) · 1.18 KB
/
normalize_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
package pixl
import (
"image"
"image/color"
_ "image/jpeg"
"testing"
)
func TestNormalize(t *testing.T) {
size := 2
image := image.NewNRGBA(image.Rectangle{Max: image.Point{X: size, Y: size}})
image.Set(0, 0, color.Gray{Y: 0})
image.Set(0, 1, color.Gray{Y: 25})
image.Set(1, 0, color.Gray{Y: 50})
image.Set(1, 1, color.Gray{Y: 127})
out := Normalize{}.Convert(image)
c := out.At(0, 0)
r, _, _, _ := c.RGBA()
if expected := uint32(0); r>>8 != expected {
t.Errorf("Invalid value of pixel, got: %d, want: %d.", r>>8, expected)
}
c = out.At(0, 1)
r, _, _, _ = c.RGBA()
if expected := uint32(50); r>>8 != expected {
t.Errorf("Invalid value of pixel, got: %d, want: %d.", r>>8, expected)
}
c = out.At(1, 0)
r, _, _, _ = c.RGBA()
if expected := uint32(100); r>>8 != expected {
t.Errorf("Invalid value of pixel, got: %d, want: %d.", r>>8, expected)
}
c = out.At(1, 1)
r, _, _, _ = c.RGBA()
if expected := uint32(255); r>>8 != expected {
t.Errorf("Invalid value of pixel, got: %d, want: %d.", r>>8, expected)
}
}
func BenchmarkNormalize(b *testing.B) {
b.StopTimer()
input := generateImage()
b.StartTimer()
for n := 0; n < b.N; n++ {
Normalize{}.Convert(input)
}
}