2014-11-10 07:37:12 +08:00
|
|
|
package i2c
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2014-12-23 05:36:52 +08:00
|
|
|
"time"
|
2014-11-10 07:37:12 +08:00
|
|
|
|
2016-02-22 13:21:24 +08:00
|
|
|
"github.com/hybridgroup/gobot/gobottest"
|
2014-11-10 07:37:12 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// --------- HELPERS
|
|
|
|
func initTestMPU6050Driver() (driver *MPU6050Driver) {
|
|
|
|
driver, _ = initTestMPU6050DriverWithStubbedAdaptor()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func initTestMPU6050DriverWithStubbedAdaptor() (*MPU6050Driver, *i2cTestAdaptor) {
|
|
|
|
adaptor := newI2cTestAdaptor("adaptor")
|
|
|
|
return NewMPU6050Driver(adaptor, "bot"), adaptor
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------- TESTS
|
|
|
|
|
|
|
|
func TestNewMPU6050Driver(t *testing.T) {
|
|
|
|
// Does it return a pointer to an instance of MPU6050Driver?
|
|
|
|
var bm interface{} = NewMPU6050Driver(newI2cTestAdaptor("adaptor"), "bot")
|
|
|
|
_, ok := bm.(*MPU6050Driver)
|
|
|
|
if !ok {
|
|
|
|
t.Errorf("NewMPU6050Driver() should have returned a *MPU6050Driver")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-23 05:36:52 +08:00
|
|
|
func TestMPU6050Driver(t *testing.T) {
|
|
|
|
mpu := initTestMPU6050Driver()
|
2016-02-22 13:21:24 +08:00
|
|
|
gobottest.Assert(t, mpu.Name(), "bot")
|
|
|
|
gobottest.Assert(t, mpu.Connection().Name(), "adaptor")
|
|
|
|
gobottest.Assert(t, mpu.interval, 10*time.Millisecond)
|
2014-12-23 05:36:52 +08:00
|
|
|
|
|
|
|
mpu = NewMPU6050Driver(newI2cTestAdaptor("adaptor"), "bot", 100*time.Millisecond)
|
2016-02-22 13:21:24 +08:00
|
|
|
gobottest.Assert(t, mpu.interval, 100*time.Millisecond)
|
2014-12-23 05:36:52 +08:00
|
|
|
}
|
|
|
|
|
2014-11-10 07:37:12 +08:00
|
|
|
// Methods
|
|
|
|
func TestMPU6050DriverStart(t *testing.T) {
|
|
|
|
mpu := initTestMPU6050Driver()
|
|
|
|
|
2016-02-22 13:21:24 +08:00
|
|
|
gobottest.Assert(t, len(mpu.Start()), 0)
|
2014-11-10 07:37:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMPU6050DriverHalt(t *testing.T) {
|
|
|
|
mpu := initTestMPU6050Driver()
|
|
|
|
|
2016-02-22 13:21:24 +08:00
|
|
|
gobottest.Assert(t, len(mpu.Halt()), 0)
|
2014-11-10 07:37:12 +08:00
|
|
|
}
|