Skip to content

Commit

Permalink
Added some missing tests to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanstennett authored and deadprogram committed May 22, 2019
1 parent d072e75 commit 59cbea5
Showing 1 changed file with 57 additions and 9 deletions.
66 changes: 57 additions & 9 deletions drivers/gpio/easy_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ const (
stepsPerRev = 720
)

var adapter *gpioTestAdaptor

func initEasyDriver() *EasyDriver {
return NewEasyDriver(newGpioTestAdaptor(), stepAngle, "1", "2", "3", "4")
adapter = newGpioTestAdaptor()
return NewEasyDriver(adapter, stepAngle, "1", "2", "3", "4")
}

func TestEasyDriver_Connection(t *testing.T) {
d := initEasyDriver()
gobottest.Assert(t, d.Connection(), adapter)
}

func TestEasyDriverDefaultName(t *testing.T) {
Expand All @@ -27,6 +35,20 @@ func TestEasyDriverSetName(t *testing.T) {
gobottest.Assert(t, strings.HasPrefix(d.Name(), "OtherDriver"), true)
}

func TestEasyDriverStart(t *testing.T) {
d := initEasyDriver()
d.Start()
// noop - no error occurred
}

func TestEasyDriverHalt(t *testing.T) {
d := initEasyDriver()
d.Run()
gobottest.Assert(t, d.IsMoving(), true)
d.Halt()
gobottest.Assert(t, d.IsMoving(), false)
}

func TestEasyDriverMove(t *testing.T) {
d := initEasyDriver()
d.Move(2)
Expand Down Expand Up @@ -75,6 +97,13 @@ func TestEasyDriverSetDirection(t *testing.T) {
gobottest.Assert(t, d.dir, int8(1))
}

func TestEasyDriverSetDirectionNoPin(t *testing.T) {
d := initEasyDriver()
d.dirPin = ""
err := d.SetDirection("cw")
gobottest.Refute(t, err, nil)
}

func TestEasyDriverSetSpeed(t *testing.T) {
d := initEasyDriver()
gobottest.Assert(t, d.rpm, uint(stepsPerRev/4)) // default speed of 720/4
Expand Down Expand Up @@ -105,6 +134,15 @@ func TestEasyDriverSleep(t *testing.T) {
gobottest.Assert(t, d.IsMoving(), false)
}

func TestEasyDriverSleepNoPin(t *testing.T) {
d := initEasyDriver()
d.sleepPin = ""
err := d.Sleep()
gobottest.Refute(t, err, nil)
err = d.Wake()
gobottest.Refute(t, err, nil)
}

func TestEasyDriverWake(t *testing.T) {
// let's test basic functionality
d := initEasyDriver()
Expand All @@ -114,6 +152,24 @@ func TestEasyDriverWake(t *testing.T) {
gobottest.Assert(t, d.IsSleeping(), false)
}

func TestEasyDriverEnable(t *testing.T) {
// let's test basic functionality
d := initEasyDriver()
d.Disable()
gobottest.Assert(t, d.IsEnabled(), false)
d.Enable()
gobottest.Assert(t, d.IsEnabled(), true)
}

func TestEasyDriverEnableNoPin(t *testing.T) {
d := initEasyDriver()
d.enPin = ""
err := d.Disable()
gobottest.Refute(t, err, nil)
err = d.Enable()
gobottest.Refute(t, err, nil)
}

func TestEasyDriverDisable(t *testing.T) {
// let's test basic functionality
d := initEasyDriver()
Expand All @@ -128,11 +184,3 @@ func TestEasyDriverDisable(t *testing.T) {
gobottest.Assert(t, d.IsMoving(), false)
}

func TestEasyDriverEnable(t *testing.T) {
// let's test basic functionality
d := initEasyDriver()
d.Disable()
gobottest.Assert(t, d.IsEnabled(), false)
d.Enable()
gobottest.Assert(t, d.IsEnabled(), true)
}

0 comments on commit 59cbea5

Please sign in to comment.