forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrovepi_driver_test.go
61 lines (47 loc) · 1.53 KB
/
grovepi_driver_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
package i2c
import (
"strings"
"testing"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/aio"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/gobottest"
)
var _ gobot.Driver = (*GrovePiDriver)(nil)
// must implement the DigitalReader interface
var _ gpio.DigitalReader = (*GrovePiDriver)(nil)
// must implement the DigitalWriter interface
var _ gpio.DigitalWriter = (*GrovePiDriver)(nil)
// must implement the AnalogReader interface
var _ aio.AnalogReader = (*GrovePiDriver)(nil)
// must implement the Adaptor interface
var _ gobot.Adaptor = (*GrovePiDriver)(nil)
func initTestGrovePiDriver() (driver *GrovePiDriver) {
driver, _ = initGrovePiDriverWithStubbedAdaptor()
return
}
func initGrovePiDriverWithStubbedAdaptor() (*GrovePiDriver, *i2cTestAdaptor) {
adaptor := newI2cTestAdaptor()
return NewGrovePiDriver(adaptor), adaptor
}
func TestGrovePiDriverName(t *testing.T) {
g := initTestGrovePiDriver()
gobottest.Refute(t, g.Connection(), nil)
gobottest.Assert(t, strings.HasPrefix(g.Name(), "GrovePi"), true)
}
func TestGrovePiDriverOptions(t *testing.T) {
g := NewGrovePiDriver(newI2cTestAdaptor(), WithBus(2))
gobottest.Assert(t, g.GetBusOrDefault(1), 2)
}
// Methods
func TestGrovePiDriverStart(t *testing.T) {
g := initTestGrovePiDriver()
gobottest.Assert(t, g.Start(), nil)
}
func TestGrovePiDrivergetPin(t *testing.T) {
gobottest.Assert(t, getPin("a1"), "1")
gobottest.Assert(t, getPin("A16"), "16")
gobottest.Assert(t, getPin("D3"), "3")
gobottest.Assert(t, getPin("d22"), "22")
gobottest.Assert(t, getPin("22"), "22")
}