Skip to content

Commit

Permalink
Update gpio tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jun 13, 2014
1 parent 965ef0a commit 289e024
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 156 deletions.
11 changes: 7 additions & 4 deletions platforms/gpio/analog_sensor_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
14 changes: 7 additions & 7 deletions platforms/gpio/button_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
18 changes: 9 additions & 9 deletions platforms/gpio/direct_pin_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
16 changes: 8 additions & 8 deletions platforms/gpio/led_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
172 changes: 91 additions & 81 deletions platforms/gpio/motor_driver_test.go
Original file line number Diff line number Diff line change
@@ -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
)

BeforeEach(func() {
m = NewMotorDriver(t, "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")
})

})
var m *MotorDriver

func init() {
m = NewMotorDriver(TestAdaptor{}, "bot", "1")
}

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")
}
Loading

0 comments on commit 289e024

Please sign in to comment.