forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
170 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
Oops, something went wrong.