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

134 lines
3.6 KiB
C++
Raw Normal View History

2021-01-29 06:31:58 -05:00
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2020-12-03
// PURPOSE: unit tests for the DAC8551
// https://github.com/RobTillaart/
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// https://github.com/Arduino-CI/arduino_ci/blob/master/cpp/unittest/Assertion.h#L33-L42
// ----------------------------
2021-08-29 14:58:12 -04:00
// 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)
2021-01-29 06:31:58 -05:00
#include <ArduinoUnitTests.h>
#include "Arduino.h"
#include "DAC8551.h"
unittest_setup()
{
2021-12-15 06:34:24 -05:00
fprintf(stderr, "DAC8551_LIB_VERSION: %s\n", (char *) DAC8551_LIB_VERSION);
2021-01-29 06:31:58 -05:00
}
unittest_teardown()
{
}
2021-12-15 06:34:24 -05:00
unittest(test_constants)
{
assertEqual(0, DAC8551_POWERDOWN_NORMAL );
assertEqual(1, DAC8551_POWERDOWN_1K );
assertEqual(2, DAC8551_POWERDOWN_100K );
assertEqual(3, DAC8551_POWERDOWN_HIGH_IMP);
assertEqual(0, DAC8501_POWERDOWN_NORMAL );
assertEqual(1, DAC8501_POWERDOWN_1K );
assertEqual(2, DAC8501_POWERDOWN_100K );
assertEqual(3, DAC8501_POWERDOWN_HIGH_IMP);
assertEqual(0, DAC8531_POWERDOWN_NORMAL );
assertEqual(1, DAC8531_POWERDOWN_1K );
assertEqual(2, DAC8531_POWERDOWN_100K );
assertEqual(3, DAC8531_POWERDOWN_HIGH_IMP);
assertEqual(0, DAC8550_POWERDOWN_NORMAL );
assertEqual(1, DAC8550_POWERDOWN_1K );
assertEqual(2, DAC8550_POWERDOWN_100K );
assertEqual(3, DAC8550_POWERDOWN_HIGH_IMP);
}
2021-01-29 06:31:58 -05:00
unittest(test_HW_constructor)
{
2021-08-29 14:58:12 -04:00
DAC8551 myDAC(10);
myDAC.begin();
2021-01-29 06:31:58 -05:00
for (uint16_t val = 0; val < 65500; val += 30)
{
2021-08-29 14:58:12 -04:00
myDAC.setValue(val);
if (myDAC.getValue() != val)
2021-01-29 06:31:58 -05:00
{
2021-08-29 14:58:12 -04:00
fprintf(stderr, "%d -> %d\n", val, myDAC.getValue());
2021-01-29 06:31:58 -05:00
}
}
2021-08-29 14:58:12 -04:00
myDAC.setValue(100);
assertEqual(100, myDAC.getValue());
2021-01-29 06:31:58 -05:00
}
unittest(test_SW_constructor)
{
2021-08-29 14:58:12 -04:00
DAC8551 myDAC(4, 5, 6);
myDAC.begin();
2021-01-29 06:31:58 -05:00
for (uint16_t val = 0; val < 65500; val += 30)
{
2021-08-29 14:58:12 -04:00
myDAC.setValue(val);
if (myDAC.getValue() != val)
2021-01-29 06:31:58 -05:00
{
2021-08-29 14:58:12 -04:00
fprintf(stderr, "%d -> %d\n", val, myDAC.getValue());
2021-01-29 06:31:58 -05:00
}
}
2021-08-29 14:58:12 -04:00
myDAC.setValue(100);
assertEqual(100, myDAC.getValue());
2021-01-29 06:31:58 -05:00
}
unittest(test_powerDown)
{
2021-08-29 14:58:12 -04:00
DAC8551 myDAC(4, 5, 6);
myDAC.begin();
2021-01-29 06:31:58 -05:00
2021-08-29 14:58:12 -04:00
myDAC.setPowerDown(DAC8551_POWERDOWN_NORMAL);
assertEqual(DAC8551_POWERDOWN_NORMAL, myDAC.getPowerDownMode());
2021-01-29 06:31:58 -05:00
2021-08-29 14:58:12 -04:00
myDAC.setPowerDown(DAC8551_POWERDOWN_1K);
assertEqual(DAC8551_POWERDOWN_1K, myDAC.getPowerDownMode());
2021-01-29 06:31:58 -05:00
2021-08-29 14:58:12 -04:00
myDAC.setPowerDown(DAC8551_POWERDOWN_100K);
assertEqual(DAC8551_POWERDOWN_100K, myDAC.getPowerDownMode());
2021-01-29 06:31:58 -05:00
2021-08-29 14:58:12 -04:00
myDAC.setPowerDown(DAC8551_POWERDOWN_HIGH_IMP);
assertEqual(DAC8551_POWERDOWN_HIGH_IMP, myDAC.getPowerDownMode());
2021-01-29 06:31:58 -05:00
}
unittest_main()
// --------