GY-63_MS5611/libraries/SRF05/test/unit_test_001.cpp
2021-05-26 11:31:36 +02:00

103 lines
2.6 KiB
C++

//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2021-01-07
// PURPOSE: unit tests for the SRF05 library
// https://github.com/RobTillaart/SRF05
// 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)
#include <ArduinoUnitTests.h>
#include "SRF05.h"
unittest_setup()
{
}
unittest_teardown()
{
}
unittest(test_constructor)
{
fprintf(stderr, "\nVERSION: %s\n", SRF05_LIB_VERSION);
SRF05 SRF(7, 6);
}
unittest(test_SOS)
{
fprintf(stderr, "\nVERSION: %s\n", SRF05_LIB_VERSION);
SRF05 SRF(7, 6);
assertEqualFloat(340, SRF.getSpeedOfSound(), 0.001);
for (float sos = 330; sos < 350; sos += 1.3)
{
SRF.setSpeedOfSound(sos);
assertEqualFloat(sos, SRF.getSpeedOfSound(), 0.001);
}
}
unittest(test_correctionFactor)
{
fprintf(stderr, "\nVERSION: %s\n", SRF05_LIB_VERSION);
SRF05 SRF(7, 6);
assertEqualFloat(1, SRF.getCorrectionFactor(), 0.001);
for (float cf = 0.95; cf < 1.06; cf += 0.01)
{
SRF.setCorrectionFactor(cf);
assertEqualFloat(cf, SRF.getCorrectionFactor(), 0.001);
}
}
unittest(test_operationalMode)
{
fprintf(stderr, "\nVERSION: %s\n", SRF05_LIB_VERSION);
SRF05 SRF(7, 6);
assertEqual(0, SRF.getOperationalMode());
SRF.setModeRunningAverage(0.2);
assertEqual(3, SRF.getOperationalMode());
SRF.setModeMedian(7);
assertEqual(2, SRF.getOperationalMode());
SRF.setModeAverage(7);
assertEqual(1, SRF.getOperationalMode());
SRF.setModeSingle();
assertEqual(0, SRF.getOperationalMode());
}
unittest_main()
// --------