lis2mdl: starting point for adding unit tests

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2020-08-26 16:45:41 +02:00
committed by Ron Evans
parent ce81b66fe2
commit dd34b83e9f
2 changed files with 19 additions and 3 deletions
+4 -3
View File
@@ -6,14 +6,15 @@
package lis2mdl // import "tinygo.org/x/drivers/lis2mdl"
import (
"machine"
"math"
"time"
"tinygo.org/x/drivers"
)
// Device wraps an I2C connection to a LIS2MDL device.
type Device struct {
bus machine.I2C
bus drivers.I2C
Address uint8
PowerMode uint8
SystemMode uint8
@@ -31,7 +32,7 @@ type Configuration struct {
// configured.
//
// This function only creates the Device object, it does not touch the device.
func New(bus machine.I2C) Device {
func New(bus drivers.I2C) Device {
return Device{bus: bus, Address: MAG_ADDRESS}
}
+15
View File
@@ -0,0 +1,15 @@
package lis2mdl
import (
"testing"
qt "github.com/frankban/quicktest"
"tinygo.org/x/drivers/tester"
)
func TestI2CAddress(t *testing.T) {
c := qt.New(t)
bus := tester.NewI2CBus(c)
dev := New(bus)
c.Assert(dev.Address, qt.Equals, uint8(MAG_ADDRESS))
}