From 5dc53355c78dd768c5771639d31486d8f6cf2530 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Tue, 4 Apr 2017 14:06:58 +0200 Subject: [PATCH] i2c: increase test coverage for tsl2561 Signed-off-by: deadprogram --- drivers/i2c/tsl2561_driver_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/i2c/tsl2561_driver_test.go b/drivers/i2c/tsl2561_driver_test.go index fad01c0e..629981e2 100644 --- a/drivers/i2c/tsl2561_driver_test.go +++ b/drivers/i2c/tsl2561_driver_test.go @@ -134,3 +134,22 @@ func TestTSL2561DriverOptions(t *testing.T) { d := NewTSL2561Driver(newI2cTestAdaptor(), WithBus(2)) gobottest.Assert(t, d.GetBusOrDefault(1), 2) } + +func TestTSL2561DriverGetLuminocity(t *testing.T) { + d, adaptor := initTestTSL2561Driver() + + // TODO: obtain real sensor data here for testing + adaptor.i2cReadImpl = func(b []byte) (int, error) { + buf := new(bytes.Buffer) + buf.Write([]byte{77, 48}) + copy(b, buf.Bytes()) + return buf.Len(), nil + } + + d.Start() + bb, ir, err := d.GetLuminocity() + gobottest.Assert(t, err, nil) + gobottest.Assert(t, bb, uint16(12365)) + gobottest.Assert(t, ir, uint16(12365)) + gobottest.Assert(t, d.CalculateLux(bb, ir), uint32(72)) +}