gobot.io/x/gobot@v1.16.0/platforms/microbit/led_driver_test.go (about)

     1  package microbit
     2  
     3  import (
     4  	"strings"
     5  	"testing"
     6  
     7  	"gobot.io/x/gobot"
     8  	"gobot.io/x/gobot/gobottest"
     9  )
    10  
    11  var _ gobot.Driver = (*LEDDriver)(nil)
    12  
    13  func initTestLEDDriver() *LEDDriver {
    14  	d := NewLEDDriver(NewBleTestAdaptor())
    15  	return d
    16  }
    17  
    18  func TestLEDDriver(t *testing.T) {
    19  	d := initTestLEDDriver()
    20  	gobottest.Assert(t, strings.HasPrefix(d.Name(), "Microbit LED"), true)
    21  	d.SetName("NewName")
    22  	gobottest.Assert(t, d.Name(), "NewName")
    23  }
    24  
    25  func TestLEDDriverStartAndHalt(t *testing.T) {
    26  	d := initTestLEDDriver()
    27  	gobottest.Assert(t, d.Start(), nil)
    28  	gobottest.Assert(t, d.Halt(), nil)
    29  }
    30  
    31  func TestLEDDriverWriteMatrix(t *testing.T) {
    32  	d := initTestLEDDriver()
    33  	d.Start()
    34  	gobottest.Assert(t, d.WriteMatrix([]byte{0x01, 0x02}), nil)
    35  }
    36  
    37  func TestLEDDriverWriteText(t *testing.T) {
    38  	d := initTestLEDDriver()
    39  	d.Start()
    40  	gobottest.Assert(t, d.WriteText("Hello"), nil)
    41  }
    42  
    43  func TestLEDDriverCommands(t *testing.T) {
    44  	d := initTestLEDDriver()
    45  	d.Start()
    46  	gobottest.Assert(t, d.Blank(), nil)
    47  	gobottest.Assert(t, d.Solid(), nil)
    48  	gobottest.Assert(t, d.UpRightArrow(), nil)
    49  	gobottest.Assert(t, d.UpLeftArrow(), nil)
    50  	gobottest.Assert(t, d.DownRightArrow(), nil)
    51  	gobottest.Assert(t, d.DownLeftArrow(), nil)
    52  	gobottest.Assert(t, d.Dimond(), nil)
    53  	gobottest.Assert(t, d.Smile(), nil)
    54  	gobottest.Assert(t, d.Wink(), nil)
    55  }