forked from makiuchi-d/gozxing
-
Notifications
You must be signed in to change notification settings - Fork 1
/
go_image_bit_matrix_test.go
48 lines (43 loc) · 974 Bytes
/
go_image_bit_matrix_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
package gozxing
import (
"image"
"image/color"
"reflect"
"testing"
)
func TestBitMatrix_ColorModel(t *testing.T) {
img, _ := NewBitMatrix(10, 10)
c := img.ColorModel()
if c != color.GrayModel {
t.Fatalf("ColorModel = %v, wants %v", c, color.GrayModel)
}
}
func TestBitMatrix_Bounds(t *testing.T) {
img, _ := NewBitMatrix(10, 20)
rect := img.Bounds()
expect := image.Rect(0, 0, 10, 20)
if !reflect.DeepEqual(rect, expect) {
t.Fatalf("Bounds = %v, wants %v", rect, expect)
}
}
func TestBitMatrix_At(t *testing.T) {
str := "" +
"# # #\n" +
" # # \n" +
"# # #\n"
img, _ := ParseStringToBitMatrix(str, "#", " ")
for j := 0; j < 3; j++ {
for i := 0; i < 5; i++ {
c := uint32(0)
if !img.Get(i, j) {
c = 0xffff // white
}
r, g, b, a := img.At(i, j).RGBA()
if r != c || g != c || b != c || a != 0xffff {
t.Fatalf(
"At(%v,%v) = RGBA(%v,%v,%v,%v), wants (%v,%v,%v,%v)",
i, j, r, g, b, a, c, c, c, 0xffff)
}
}
}
}