-
Notifications
You must be signed in to change notification settings - Fork 0
/
text_test.go
69 lines (56 loc) · 1.41 KB
/
text_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
package as1130_test
import (
. "github.com/dcarley/as1130"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Text", func() {
Describe("TextFrames", func() {
const text = "hello world as1130 test"
var frames []*Frame24x5
BeforeEach(func() {
var err error
frames, err = TextFrames(text)
Expect(err).ToNot(HaveOccurred())
})
It("should have 1 frame per 5 characters on average", func() {
const (
framesPerChar = 5
spacerFrames = 1
)
Expect(frames).To(HaveLen(spacerFrames + len(text)/framesPerChar))
})
It("should start with an empty frame", func() {
frame := frames[0]
size := frame.Bounds()
var nonEmptyPixels int
for x := size.Min.X; x < size.Max.X; x++ {
for y := size.Min.Y; y < size.Max.Y; y++ {
if frame.GrayAt(x, y) != Off {
nonEmptyPixels++
}
}
}
Expect(nonEmptyPixels).To(Equal(0), "frame 1 to have no pixels set")
})
It("should have have text in all other frames", func() {
for i, frame := range frames {
if i == 0 {
continue
}
size := frame.Bounds()
var nonEmptyPixels int
for x := size.Min.X; x < size.Max.X; x++ {
for y := size.Min.Y; y < size.Max.Y; y++ {
if frame.GrayAt(x, y) == On {
nonEmptyPixels++
}
}
}
Expect(nonEmptyPixels).To(BeNumerically(">", 10),
"frame %d to contain enough non-empty pixels", i+1,
)
}
})
})
})