2021-06-27 07:04:39 -04:00
|
|
|
//
|
|
|
|
// FILE: unit_test_001.cpp
|
|
|
|
// AUTHOR: Rob Tillaart
|
2023-01-27 14:36:02 -05:00
|
|
|
// DATE: 2021-06-24
|
|
|
|
// PURPOSE: unit tests for Arduino library for SGP30 environment sensor.
|
|
|
|
// https://github.com/RobTillaart/SGP30
|
2021-06-27 07:04:39 -04:00
|
|
|
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
|
|
|
//
|
|
|
|
|
|
|
|
// supported assertions
|
|
|
|
// ----------------------------
|
|
|
|
// assertEqual(expected, actual); // a == b
|
|
|
|
// assertNotEqual(unwanted, actual); // a != b
|
|
|
|
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
|
|
|
|
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
|
|
|
|
// assertLess(upperBound, actual); // a < b
|
|
|
|
// assertMore(lowerBound, actual); // a > b
|
|
|
|
// assertLessOrEqual(upperBound, actual); // a <= b
|
|
|
|
// assertMoreOrEqual(lowerBound, actual); // a >= b
|
|
|
|
// assertTrue(actual);
|
|
|
|
// assertFalse(actual);
|
|
|
|
// assertNull(actual);
|
|
|
|
|
|
|
|
// // special cases for floats
|
|
|
|
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
|
|
|
|
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
|
|
|
|
// assertInfinity(actual); // isinf(a)
|
|
|
|
// assertNotInfinity(actual); // !isinf(a)
|
|
|
|
// assertNAN(arg); // isnan(a)
|
|
|
|
// assertNotNAN(arg); // !isnan(a)
|
|
|
|
|
2023-01-27 14:36:02 -05:00
|
|
|
|
2021-06-27 07:04:39 -04:00
|
|
|
#include <ArduinoUnitTests.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "SGP30.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unittest_setup()
|
|
|
|
{
|
2021-12-28 05:10:52 -05:00
|
|
|
fprintf(stderr, "SGP30_LIB_VERSION: %s\n", (char *) SGP30_LIB_VERSION);
|
2021-06-27 07:04:39 -04:00
|
|
|
}
|
|
|
|
|
2021-12-28 05:10:52 -05:00
|
|
|
|
2021-06-27 07:04:39 -04:00
|
|
|
unittest_teardown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_constructor)
|
|
|
|
{
|
|
|
|
SGP30 SGP;
|
2023-01-27 14:36:02 -05:00
|
|
|
|
2021-06-27 07:04:39 -04:00
|
|
|
assertTrue(SGP.begin());
|
|
|
|
assertTrue(SGP.isConnected());
|
|
|
|
|
|
|
|
assertEqual(0x00, SGP.lastMeasurement());
|
|
|
|
assertEqual(0x00, SGP.lastError());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_constants)
|
|
|
|
{
|
2021-12-28 05:10:52 -05:00
|
|
|
assertEqual(SGP30_OK, 0x00);
|
|
|
|
assertEqual(SGP30_ERROR_CRC, 0xFF);
|
|
|
|
assertEqual(SGP30_ERROR_I2C, 0xFE);
|
2021-06-27 07:04:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_defaults_core)
|
|
|
|
{
|
|
|
|
SGP30 SGP;
|
|
|
|
|
|
|
|
assertEqual(0x00, SGP.getCO2());
|
|
|
|
assertEqual(0x00, SGP.getTVOC());
|
|
|
|
assertEqual(0x00, SGP.getH2_raw());
|
|
|
|
assertEqual(0x00, SGP.getEthanol_raw());
|
|
|
|
assertEqualFloat(6.71302e+10, SGP.getH2(), 1e7);
|
|
|
|
assertEqualFloat(1.86462e+15, SGP.getEthanol(), 1e12);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_sref_H2)
|
|
|
|
{
|
|
|
|
SGP30 SGP;
|
|
|
|
|
|
|
|
assertEqual(13119, SGP.getSrefH2());
|
|
|
|
|
|
|
|
SGP.setSrefH2(0);
|
|
|
|
assertEqual(0, SGP.getSrefH2());
|
|
|
|
|
|
|
|
SGP.setSrefH2(10000);
|
|
|
|
assertEqual(10000, SGP.getSrefH2());
|
2023-01-27 14:36:02 -05:00
|
|
|
|
2021-06-27 07:04:39 -04:00
|
|
|
SGP.setSrefH2();
|
|
|
|
assertEqual(13119, SGP.getSrefH2());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_sref_Ethanol)
|
|
|
|
{
|
|
|
|
SGP30 SGP;
|
|
|
|
|
|
|
|
assertEqual(18472, SGP.getSrefEthanol());
|
|
|
|
|
|
|
|
SGP.setSrefEthanol(0);
|
|
|
|
assertEqual(0, SGP.getSrefEthanol());
|
|
|
|
|
|
|
|
SGP.setSrefEthanol(10000);
|
|
|
|
assertEqual(10000, SGP.getSrefEthanol());
|
2023-01-27 14:36:02 -05:00
|
|
|
|
2021-06-27 07:04:39 -04:00
|
|
|
SGP.setSrefEthanol();
|
|
|
|
assertEqual(18472, SGP.getSrefEthanol());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest_main()
|
|
|
|
|
|
|
|
|
2023-01-27 14:36:02 -05:00
|
|
|
// -- END OF FILE --
|