From 59cbea5eb6914ceefef6ab19e545ad29e30048ad Mon Sep 17 00:00:00 2001 From: Brendan Stennett Date: Thu, 20 Sep 2018 14:02:36 -0400 Subject: [PATCH] Added some missing tests to increase coverage --- drivers/gpio/easy_driver_test.go | 66 +++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/drivers/gpio/easy_driver_test.go b/drivers/gpio/easy_driver_test.go index 825c398e..f96358d5 100644 --- a/drivers/gpio/easy_driver_test.go +++ b/drivers/gpio/easy_driver_test.go @@ -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) { @@ -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) @@ -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 @@ -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() @@ -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() @@ -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) -} \ No newline at end of file