From dd34b83e9fc688c9b50e5fedefe5f5c373bedaf7 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Wed, 26 Aug 2020 16:45:41 +0200 Subject: [PATCH] lis2mdl: starting point for adding unit tests Signed-off-by: deadprogram --- lis2mdl/lis2mdl.go | 7 ++++--- lis2mdl/lis2mdl_test.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 lis2mdl/lis2mdl_test.go diff --git a/lis2mdl/lis2mdl.go b/lis2mdl/lis2mdl.go index 04cb822..d1e8611 100644 --- a/lis2mdl/lis2mdl.go +++ b/lis2mdl/lis2mdl.go @@ -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} } diff --git a/lis2mdl/lis2mdl_test.go b/lis2mdl/lis2mdl_test.go new file mode 100644 index 0000000..6bf9c45 --- /dev/null +++ b/lis2mdl/lis2mdl_test.go @@ -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)) +}