diff --git a/platforms/gpio/analog_sensor_driver_test.go b/platforms/gpio/analog_sensor_driver_test.go index dcf64740..a1881b47 100644 --- a/platforms/gpio/analog_sensor_driver_test.go +++ b/platforms/gpio/analog_sensor_driver_test.go @@ -11,15 +11,18 @@ func init() { a = NewAnalogSensorDriver(TestAdaptor{}, "bot", "1") } -func TestStart(t *testing.T) { +func TestAnalogSensorStart(t *testing.T) { gobot.Expect(t, a.Start(), true) } -func TestHalt(t *testing.T) { + +func TestAnalogSensorHalt(t *testing.T) { gobot.Expect(t, a.Halt(), true) } -func TestInit(t *testing.T) { + +func TestAnalogSensorInit(t *testing.T) { gobot.Expect(t, a.Init(), true) } -func TestRead(t *testing.T) { + +func TestAnalogSensorRead(t *testing.T) { gobot.Expect(t, a.Read(), 99) } diff --git a/platforms/gpio/button_driver_test.go b/platforms/gpio/button_driver_test.go index 1f438d57..cb631464 100644 --- a/platforms/gpio/button_driver_test.go +++ b/platforms/gpio/button_driver_test.go @@ -5,32 +5,32 @@ import ( "testing" ) -var a *AnalogSensorDriver +var b *ButtonDriver func init() { b = NewButtonDriver(TestAdaptor{}, "bot", "1") } -func TestStart(t *testing.T) { +func TestButtonStart(t *testing.T) { gobot.Expect(t, a.Start(), true) } -func TestHalt(t *testing.T) { +func TestButtonHalt(t *testing.T) { gobot.Expect(t, a.Halt(), true) } -func TestInit(t *testing.T) { +func TestButtonInit(t *testing.T) { gobot.Expect(t, a.Init(), true) } -func TestReadState(t *testing.T) { +func TestButtonReadState(t *testing.T) { gobot.Expect(t, b.readState(), 1) } -func TestActive(t *testing.T) { +func TestButtonActive(t *testing.T) { b.update(1) gobot.Expect(t, b.Active, true) b.update(0) - gobot.Expect(b.Active, false) + gobot.Expect(t, b.Active, false) } diff --git a/platforms/gpio/direct_pin_driver_test.go b/platforms/gpio/direct_pin_driver_test.go index 34031e70..6938321d 100644 --- a/platforms/gpio/direct_pin_driver_test.go +++ b/platforms/gpio/direct_pin_driver_test.go @@ -11,38 +11,38 @@ func init() { d = NewDirectPinDriver(TestAdaptor{}, "bot", "1") } -func TestStart(t *testing.T) { +func TestDirectPinStart(t *testing.T) { gobot.Expect(t, a.Start(), true) } -func TestHalt(t *testing.T) { +func TestDirectPinHalt(t *testing.T) { gobot.Expect(t, a.Halt(), true) } -func TestInit(t *testing.T) { +func TestDirectPinInit(t *testing.T) { gobot.Expect(t, a.Init(), true) } -func TestDigitalRead(t *testing.T) { +func TestDirectPinDigitalRead(t *testing.T) { gobot.Expect(t, d.DigitalRead(), 1) } -func TestDigitalWrite(t *testing.T) { +func TestDirectPinDigitalWrite(t *testing.T) { d.DigitalWrite(1) } -func TestAnalogRead(t *testing.T) { +func TestDirectPinAnalogRead(t *testing.T) { gobot.Expect(t, d.AnalogRead(), 99) } -func TestAnalogWrite(t *testing.T) { +func TestDirectPinAnalogWrite(t *testing.T) { d.AnalogWrite(100) } -func TestPwmWrite(t *testing.T) { +func TestDirectPinPwmWrite(t *testing.T) { d.PwmWrite(100) } -func TestServoWrite(t *testing.T) { +func TestDirectPinServoWrite(t *testing.T) { d.ServoWrite(100) } diff --git a/platforms/gpio/led_driver_test.go b/platforms/gpio/led_driver_test.go index 96fcb11e..a7dc11fc 100644 --- a/platforms/gpio/led_driver_test.go +++ b/platforms/gpio/led_driver_test.go @@ -11,36 +11,36 @@ func init() { l = NewLedDriver(TestAdaptor{}, "myLed", "1") } -func TestStart(t *testing.T) { +func TestLedStart(t *testing.T) { gobot.Expect(t, l.Start(), true) } -func TestHalt(t *testing.T) { +func TestLedHalt(t *testing.T) { gobot.Expect(t, l.Halt(), true) } -func TestInit(t *testing.T) { +func TestLedInit(t *testing.T) { gobot.Expect(t, l.Init(), true) } -func TestOn(t *testing.T) { +func TestLedOn(t *testing.T) { gobot.Expect(t, l.On(), true) gobot.Expect(t, l.IsOn(), true) } -func TestOff(t *testing.T) { +func TestLedOff(t *testing.T) { gobot.Expect(t, l.Off(), true) gobot.Expect(t, l.IsOff(), true) } -func TestToggle(t *testing.T) { +func TestLedToggle(t *testing.T) { l.Off() l.Toggle() gobot.Expect(t, l.IsOn(), true) l.Toggle() - gobot.Expect(l.IsOff(), true) + gobot.Expect(t, l.IsOff(), true) } -func TestBrightness(t *testing.T) { +func TestLedBrightness(t *testing.T) { l.Brightness(150) } diff --git a/platforms/gpio/motor_driver_test.go b/platforms/gpio/motor_driver_test.go index 8d6d303a..b9079305 100644 --- a/platforms/gpio/motor_driver_test.go +++ b/platforms/gpio/motor_driver_test.go @@ -1,86 +1,96 @@ package gpio import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/hybridgroup/gobot" + "testing" ) -var _ = Describe("Motor", func() { - var ( - t TestAdaptor - m *MotorDriver - ) +var m *MotorDriver - BeforeEach(func() { - m = NewMotorDriver(t, "bot", "1") - }) +func init() { + m = NewMotorDriver(TestAdaptor{}, "bot", "1") +} - It("Must be able to Start", func() { - Expect(m.Start()).To(Equal(true)) - }) - It("Must be able to Init", func() { - Expect(m.Init()).To(Equal(true)) - }) - It("Must be able to Halt", func() { - Expect(m.Halt()).To(Equal(true)) - }) - It("Must be able to tell if IsOn", func() { - m.CurrentState = 1 - Expect(m.IsOn()).To(BeTrue()) - m.CurrentMode = "analog" - m.CurrentSpeed = 100 - Expect(m.IsOn()).To(BeTrue()) - }) - It("Must be able to tell if IsOff", func() { - Expect(m.IsOff()).To(Equal(true)) - }) - It("Should be able to turn On", func() { - m.On() - Expect(m.CurrentState).To(Equal(uint8(1))) - m.CurrentMode = "analog" - m.CurrentSpeed = 0 - m.On() - Expect(m.CurrentSpeed).To(Equal(uint8(255))) - }) - It("Should be able to turn Off", func() { - m.Off() - Expect(m.CurrentState).To(Equal(uint8(0))) - m.CurrentMode = "analog" - m.CurrentSpeed = 100 - m.Off() - Expect(m.CurrentSpeed).To(Equal(uint8(0))) - }) - It("Should be able to Toggle", func() { - m.Off() - m.Toggle() - Expect(m.IsOn()).To(BeTrue()) - m.Toggle() - Expect(m.IsOn()).NotTo(BeTrue()) - }) - It("Should be able to set to Min speed", func() { - m.Min() - }) - It("Should be able to set to Max speed", func() { - m.Max() - }) - It("Should be able to set Speed", func() { - Expect(true) - }) - It("Should be able to set Forward", func() { - m.Forward(100) - Expect(m.CurrentSpeed).To(Equal(uint8(100))) - Expect(m.CurrentDirection).To(Equal("forward")) - }) - It("Should be able to set Backward", func() { - m.Backward(100) - Expect(m.CurrentSpeed).To(Equal(uint8(100))) - Expect(m.CurrentDirection).To(Equal("backward")) - }) - It("Should be able to set Direction", func() { - m.Direction("none") - m.DirectionPin = "2" - m.Direction("forward") - m.Direction("backward") - }) +func TestMotorStart(t *testing.T) { + gobot.Expect(t, m.Start(), true) +} -}) +func TestMotorHalt(t *testing.T) { + gobot.Expect(t, m.Halt(), true) +} + +func TestMotorInit(t *testing.T) { + gobot.Expect(t, m.Init(), true) +} + +func TestMotorIsOn(t *testing.T) { + m.CurrentMode = "digital" + m.CurrentState = 1 + gobot.Expect(t, m.IsOn(), true) + m.CurrentMode = "analog" + m.CurrentSpeed = 100 + gobot.Expect(t, m.IsOn(), true) +} + +func TestMotorIsOff(t *testing.T) { + m.Off() + gobot.Expect(t, m.IsOff(), true) +} + +func TestMotorOn(t *testing.T) { + m.CurrentMode = "digital" + m.On() + gobot.Expect(t, m.CurrentState, uint8(1)) + m.CurrentMode = "analog" + m.CurrentSpeed = 0 + m.On() + gobot.Expect(t, m.CurrentSpeed, uint8(255)) +} + +func TestMotorOff(t *testing.T) { + m.CurrentMode = "digital" + m.Off() + gobot.Expect(t, m.CurrentState, uint8(0)) + m.CurrentMode = "analog" + m.CurrentSpeed = 100 + m.Off() + gobot.Expect(t, m.CurrentSpeed, uint8(0)) +} + +func TestMotorToggle(t *testing.T) { + m.Off() + m.Toggle() + gobot.Expect(t, m.IsOn(), true) + m.Toggle() + gobot.Expect(t, m.IsOn(), false) +} + +func TestMotorMin(t *testing.T) { + m.Min() +} + +func TestMotorMax(t *testing.T) { + m.Max() +} + +func TestMotorSpeed(t *testing.T) { + m.Speed(100) +} + +func TestMotorForward(t *testing.T) { + m.Forward(100) + gobot.Expect(t, m.CurrentSpeed, uint8(100)) + gobot.Expect(t, m.CurrentDirection, "forward") +} +func TestMotorBackward(t *testing.T) { + m.Backward(100) + gobot.Expect(t, m.CurrentSpeed, uint8(100)) + gobot.Expect(t, m.CurrentDirection, "backward") +} + +func TestMotorDirection(t *testing.T) { + m.Direction("none") + m.DirectionPin = "2" + m.Direction("forward") + m.Direction("backward") +} diff --git a/platforms/gpio/servo_driver_test.go b/platforms/gpio/servo_driver_test.go index 9818a1ac..4dae085f 100644 --- a/platforms/gpio/servo_driver_test.go +++ b/platforms/gpio/servo_driver_test.go @@ -1,51 +1,48 @@ package gpio import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/hybridgroup/gobot" + "testing" ) -var _ = Describe("Servo", func() { - var ( - t TestAdaptor - s *ServoDriver - ) +var s *ServoDriver - BeforeEach(func() { - s = NewServoDriver(t, "bot", "1") - }) +func init() { + s = NewServoDriver(TestAdaptor{}, "bot", "1") +} - It("Should be able to Move", func() { - s.Move(100) - Expect(s.CurrentAngle).To(Equal(uint8(100))) - }) +func TestServoStart(t *testing.T) { + gobot.Expect(t, l.Start(), true) +} - It("Should be able to move to Min", func() { - s.Min() - Expect(s.CurrentAngle).To(Equal(uint8(0))) - }) +func TestServoHalt(t *testing.T) { + gobot.Expect(t, l.Halt(), true) +} - It("Should be able to move to Max", func() { - s.Max() - Expect(s.CurrentAngle).To(Equal(uint8(180))) - }) +func TestServoInit(t *testing.T) { + gobot.Expect(t, l.Init(), true) +} - It("Should be able to move to Center", func() { - s.Center() - Expect(s.CurrentAngle).To(Equal(uint8(90))) - }) +func TestServoMove(t *testing.T) { + s.Move(100) + gobot.Expect(t, s.CurrentAngle, uint8(100)) +} - It("Should be able to move to init servo", func() { - s.InitServo() - }) +func TestServoMin(t *testing.T) { + s.Min() + gobot.Expect(t, s.CurrentAngle, uint8(0)) +} - It("Must be able to Start", func() { - Expect(s.Start()).To(Equal(true)) - }) - It("Must be able to Init", func() { - Expect(s.Init()).To(Equal(true)) - }) - It("Must be able to Halt", func() { - Expect(s.Halt()).To(Equal(true)) - }) -}) +func TestServoMax(t *testing.T) { + s.Max() + gobot.Expect(t, s.CurrentAngle, uint8(180)) +} + +func TestServoCenter(t *testing.T) { + s.Center() + gobot.Expect(t, s.CurrentAngle, uint8(90)) +} + +func TestServoInitServo(t *testing.T) { + s.InitServo() +} diff --git a/test_helper.go b/test_helper.go index 29035a79..f272e662 100644 --- a/test_helper.go +++ b/test_helper.go @@ -3,6 +3,8 @@ package gobot import ( "fmt" "reflect" + "runtime" + "strings" "testing" ) @@ -13,7 +15,9 @@ type testStruct struct { func Expect(t *testing.T, a interface{}, b interface{}) { if !reflect.DeepEqual(a, b) { - t.Errorf("Got %v - type %v, Expected %v - type %v", a, reflect.TypeOf(a), b, reflect.TypeOf(b)) + _, file, line, _ := runtime.Caller(1) + s := strings.Split(file, "/") + t.Errorf("%v:%v Got %v - type %v, Expected %v - type %v", s[len(s)-1], line, a, reflect.TypeOf(a), b, reflect.TypeOf(b)) } }