2017-03-01 02:40:16 +08:00
|
|
|
package microbit
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/gobottest"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ gobot.Driver = (*LEDDriver)(nil)
|
|
|
|
|
|
|
|
func initTestLEDDriver() *LEDDriver {
|
2017-04-05 18:40:17 +08:00
|
|
|
d := NewLEDDriver(NewBleTestAdaptor())
|
2017-03-01 02:40:16 +08:00
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLEDDriver(t *testing.T) {
|
|
|
|
d := initTestLEDDriver()
|
|
|
|
gobottest.Assert(t, strings.HasPrefix(d.Name(), "Microbit LED"), true)
|
2017-04-05 18:40:17 +08:00
|
|
|
d.SetName("NewName")
|
|
|
|
gobottest.Assert(t, d.Name(), "NewName")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLEDDriverStartAndHalt(t *testing.T) {
|
|
|
|
d := initTestLEDDriver()
|
|
|
|
gobottest.Assert(t, d.Start(), nil)
|
|
|
|
gobottest.Assert(t, d.Halt(), nil)
|
2017-03-01 02:40:16 +08:00
|
|
|
}
|
2017-04-06 04:33:19 +08:00
|
|
|
|
|
|
|
func TestLEDDriverWriteMatrix(t *testing.T) {
|
|
|
|
d := initTestLEDDriver()
|
|
|
|
d.Start()
|
|
|
|
gobottest.Assert(t, d.WriteMatrix([]byte{0x01, 0x02}), nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLEDDriverWriteText(t *testing.T) {
|
|
|
|
d := initTestLEDDriver()
|
|
|
|
d.Start()
|
|
|
|
gobottest.Assert(t, d.WriteText("Hello"), nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLEDDriverCommands(t *testing.T) {
|
|
|
|
d := initTestLEDDriver()
|
|
|
|
d.Start()
|
|
|
|
gobottest.Assert(t, d.Blank(), nil)
|
|
|
|
gobottest.Assert(t, d.Solid(), nil)
|
|
|
|
gobottest.Assert(t, d.UpRightArrow(), nil)
|
|
|
|
gobottest.Assert(t, d.UpLeftArrow(), nil)
|
|
|
|
gobottest.Assert(t, d.DownRightArrow(), nil)
|
|
|
|
gobottest.Assert(t, d.DownLeftArrow(), nil)
|
|
|
|
gobottest.Assert(t, d.Dimond(), nil)
|
|
|
|
gobottest.Assert(t, d.Smile(), nil)
|
|
|
|
gobottest.Assert(t, d.Wink(), nil)
|
|
|
|
}
|