forked from smart--petea/pixl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpixl_test.go
83 lines (67 loc) · 1.7 KB
/
pixl_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
package pixl
import (
"image"
"image/color"
"testing"
)
func Test_paintAll(t *testing.T) {
size := 10
out := image.NewGray(image.Rect(0, 0, size, size))
traverseImage(out, out, paintAll{color: color.Gray{Y: 0x0F}})
result := true
for x := 0; x < size; x++ {
for y := 0; y < size; y++ {
if (out.At(x, y) != color.Gray{Y: 0x0F}) {
result = false
}
}
}
if result == false {
t.Errorf("Not a whole picture has been painted.")
}
}
func Test_histogramGray(t *testing.T) {
grayInput := image.NewGray(image.Rect(0, 0, 10, 10))
for i := 0; i < 10; i++ {
for j := 0; j < 10; j++ {
if i >= 3 && i <= 6 && j >= 2 && j <= 3 {
grayInput.Set(i, j, color.Black)
} else {
grayInput.Set(i, j, color.White)
}
}
}
h := histogramGray(grayInput)
if h[0] != 8 {
t.Errorf("Amount of black pixels is incorect, got: %d, want: %d.", h[0], 8)
}
if h[0xFF] != 92 {
t.Errorf("Amount of white pixels is incorect, got: %d, want: %d.", h[0xFF], 92)
}
}
func Test_parseHexColor(t *testing.T) {
_, err := parseHexColor("err")
if err == nil {
t.Errorf("Err is nil. Should be: parseHexColor: invalid format")
}
err = nil
_, err = parseHexColor("#ff00Fx")
if err == nil {
t.Errorf("Err is nil. Should be: parseHexColor: invalid format")
}
err = nil
_, err = parseHexColor("#ff00F")
if err == nil {
t.Errorf("Err is nil. Should be: parseHexColor: invalid format")
}
c, _ := parseHexColor("#Ff00f0")
if c.R != 0xFF {
t.Errorf("R value of pixel is incorect, got: %d, want: %d.", c.R, 0xFF)
}
if c.G != 0x00 {
t.Errorf("G value of pixel is incorect, got: %d, want: %d.", c.G, 0x00)
}
if c.B != 0xF0 {
t.Errorf("B value of pixel is incorect, got: %d, want: %d.", c.B, 0xF0)
}
}