-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrgb_test.go
65 lines (57 loc) · 1.39 KB
/
rgb_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
package firmata
import (
"fmt"
. "launchpad.net/gocheck"
"log"
"testing"
)
// Hook up gocheck into the gotest runner.
func Test(t *testing.T) { TestingT(t) }
type BoardTests struct {
board Board
}
var _ = Suite(&BoardTests{})
func (b *BoardTests) SetUpTest(c *C) {
board, err := NewBoard("/dev/ttyUSB1", 57600)
b.board = *board
if err != nil {
log.Fatal("Could not setup board")
}
go func() {
for msg := range *board.Reader {
fmt.Println(msg)
}
}()
}
// Just create a new LED and setup the pins
func (b *BoardTests) TestCreateLED(t *C) {
println("Sending analog mapping request")
l := new(RGBLED, 9, 10, 11)
l.SetupPins(b.board)
}
// Check that when we use quick colors they come out as we would expect
func (b *BoardTest) TestQuickColors(t *C) {
l := new(RGBLED, 9, 10, 11)
var cs = map[string][3]byte{
"red": [3]byte{0xFF, 00, 00},
"green": [3]byte{00, 0xFF, 00},
"blue": [3]byte{00, 00, 0xFF},
"black": [3]byte{00, 00, 00},
"white": [3]byte{0xFF, 0xFF, 0xFF},
}
for c, v := range cs {
l.QuickColor(c)
t.Check(l.Red, Equals, v[0])
t.Check(l.Green, Equals, v[1])
t.Check(l.Blue, Equals, v[2])
}
}
// Check that the conversion to a hex string RRGGBB works
// as expected
func (b *BoardTest) TestHexColors(t *C) {
l := new(RGBLED, 9, 10, 11)
l.Red = 02 // Test padding
l.Green = 255 // largest
l.Blue = 0 // Zero
t.check(l.HexString(), Equals, "02FF00")
}