GY-63_MS5611/libraries/SHT2x/test/unit_test_001.cpp

154 lines
3.2 KiB
C++
Raw Normal View History

2021-09-27 14:51:23 -04:00
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2021-09-25
// PURPOSE: unit tests for the SHT2x temperature and humidity sensor
// https://github.com/RobTillaart/SHT2x
// https://www.adafruit.com/product/2857
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// ----------------------------
// assertEqual(expected, actual)
// assertNotEqual(expected, actual)
// assertLess(expected, actual)
// assertMore(expected, actual)
// assertLessOrEqual(expected, actual)
// assertMoreOrEqual(expected, actual)
// assertTrue(actual)
// assertFalse(actual)
// assertNull(actual)
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
/*
most unit tests will test for fail
as there is no sensor connected
and there is no mockup.
It appears that Wire.write does not fail without sensor...
*/
#include <ArduinoUnitTests.h>
#include "Arduino.h"
#include "SHT2x.h"
int expect; // TODO needed as there seems a problem with 8 bit comparisons (char?)
uint32_t start, stop;
unittest_setup()
{
}
unittest_teardown()
{
}
2021-11-17 12:59:50 -05:00
unittest(test_constructor)
{
fprintf(stderr, "SHT2x_LIB_VERSION: %s \n", (char *) SHT2x_LIB_VERSION);
SHT2x sht;
bool b = sht.begin();
assertEqual(b, true);
}
2021-09-27 14:51:23 -04:00
unittest(test_begin)
{
SHT2x sht;
bool b = sht.begin();
assertEqual(b, true);
assertTrue(sht.reset());
expect = SHT2x_OK;
assertEqual(expect, sht.getError());
Serial.println(sht.getTemperature());
Serial.println(sht.getHumidity());
Serial.println(sht.getRawTemperature());
Serial.println(sht.getRawHumidity());
// default value == 0
assertEqualFloat(-46.85, sht.getTemperature(), 0.01);
assertEqualFloat(-6, sht.getHumidity(), 0.01);
assertEqual(0, sht.getRawTemperature());
assertEqual(0, sht.getRawHumidity());
}
unittest(test_read)
{
SHT2x sht;
bool b = sht.begin();
assertEqual(b, true);
assertTrue(sht.isConnected());
expect = SHT2x_OK;
assertEqual(expect, sht.getError());
// assertion wire.available fails ...
// assertFalse(sht.read());
// expect = SHT2x_ERR_READBYTES;
// assertEqual(expect, sht.getError());
// start = millis();
// assertFalse(sht.read());
// stop = millis();
// Serial.println(stop - start);
// expect = SHT2x_ERR_READBYTES;
// assertEqual(expect, sht.getError());
// start = millis();
// assertFalse(sht.read());
// stop = millis();
// Serial.println(stop - start);
// expect = SHT2x_ERR_READBYTES;
// assertEqual(expect, sht.getError());
}
unittest(test_getStatus)
{
SHT2x sht;
bool b = sht.begin();
assertEqual(b, true);
assertEqual(0x00, sht.getStatus());
expect = SHT2x_OK;
assertEqual(expect, sht.getError());
}
unittest(test_heater)
{
SHT2x sht;
bool b = sht.begin();
assertEqual(b, true);
// assertion wire.available fails ...
// assertFalse(sht.heatOn());
// expect = SHT2x_ERR_READBYTES;
// assertEqual(expect, sht.getError());
// assertFalse(sht.heatOff());
// expect = SHT2x_ERR_READBYTES;
// assertEqual(expect, sht.getError());
// assertFalse(sht.isHeaterOn());
// expect = SHT2x_OK;
// assertEqual(expect, sht.getError());
}
unittest_main()
// --------