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

148 lines
4.1 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 MAX31855_RT Thermocouple library
// https://github.com/RobTillaart/MAX31855_RT
// 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 "Arduino.h"
#include "MAX31855.h"
unittest_setup()
{
2022-11-16 09:46:22 -05:00
fprintf(stderr, "MAX31855_VERSION: %s\n", (char *) MAX31855_VERSION);
2021-01-29 06:31:58 -05:00
}
2022-11-16 09:46:22 -05:00
2021-01-29 06:31:58 -05:00
unittest_teardown()
{
}
2021-12-10 05:12:41 -05:00
unittest(test_constants)
{
assertEqual(0x00, STATUS_OK);
assertEqual(0x01, STATUS_OPEN_CIRCUIT);
assertEqual(0x02, STATUS_SHORT_TO_GND);
assertEqual(0x04, STATUS_SHORT_TO_VCC);
assertEqual(0x07, STATUS_ERROR);
assertEqual(0x80, STATUS_NOREAD);
assertEqual(0x81, STATUS_NO_COMMUNICATION);
2022-11-16 09:46:22 -05:00
2021-12-10 05:12:41 -05:00
assertEqual(-999, MAX31855_NO_TEMPERATURE);
}
unittest(test_status)
2021-01-29 06:31:58 -05:00
{
2023-11-29 09:53:40 -05:00
const int selectPin = 7;
const int dataPin = 6;
const int clockPin = 5;
2021-01-29 06:31:58 -05:00
2023-11-29 09:53:40 -05:00
MAX31855 thermoCouple(selectPin, dataPin, clockPin);
thermoCouple.begin();
2021-01-29 06:31:58 -05:00
fprintf(stderr, "Status...\n");
2023-11-29 09:53:40 -05:00
assertEqual(STATUS_NOREAD, (int)thermoCouple.getStatus());
assertEqual(0, thermoCouple.lastRead());
assertEqual(0, thermoCouple.getRawData());
assertFalse(thermoCouple.openCircuit());
assertFalse(thermoCouple.shortToGND());
assertFalse(thermoCouple.shortToVCC());
assertFalse(thermoCouple.genericError());
assertFalse(thermoCouple.noCommunication());
assertTrue(thermoCouple.noRead());
2021-12-10 05:12:41 -05:00
}
unittest(test_temperature)
{
2023-11-29 09:53:40 -05:00
const int selectPin = 7;
const int dataPin = 6;
const int clockPin = 5;
2021-12-10 05:12:41 -05:00
2023-11-29 09:53:40 -05:00
MAX31855 thermoCouple(selectPin, dataPin, clockPin);
thermoCouple.begin();
2021-01-29 06:31:58 -05:00
fprintf(stderr, "Temperature...\n");
2023-11-29 09:53:40 -05:00
assertEqualFloat(MAX31855_NO_TEMPERATURE, thermoCouple.getInternal(), 0.001);
assertEqualFloat(MAX31855_NO_TEMPERATURE, thermoCouple.getTemperature(), 0.001);
2021-01-29 06:31:58 -05:00
2021-12-10 05:12:41 -05:00
fprintf(stderr, "\nOffset...\n");
2021-01-29 06:31:58 -05:00
for (int of = 0; of < 10; of++)
{
2023-11-29 09:53:40 -05:00
thermoCouple.setOffset(of * 0.1);
2021-01-29 06:31:58 -05:00
fprintf(stderr, "%f\t", of * 0.1);
2023-11-29 09:53:40 -05:00
assertEqualFloat(of * 0.1, thermoCouple.getOffset(), 0.001);
2021-01-29 06:31:58 -05:00
}
2021-12-10 05:12:41 -05:00
fprintf(stderr, "\nSeebeckCoefficient...\n");
2022-11-16 09:46:22 -05:00
for (float sbc = 9; sbc < 100; sbc += 12.345) // non existent still good for test.
2021-01-29 06:31:58 -05:00
{
2023-11-29 09:53:40 -05:00
thermoCouple.setSeebeckCoefficient(sbc);
2021-01-29 06:31:58 -05:00
fprintf(stderr, "%f\t", sbc);
2023-11-29 09:53:40 -05:00
assertEqualFloat(sbc, thermoCouple.getSeebeckCoefficient(), 0.001);
2021-01-29 06:31:58 -05:00
}
2021-12-10 05:12:41 -05:00
}
unittest(test_SPIspeed_SWSPIdelay)
{
2023-11-29 09:53:40 -05:00
const int selectPin = 7;
const int dataPin = 6;
const int clockPin = 5;
2021-01-29 06:31:58 -05:00
2023-11-29 09:53:40 -05:00
MAX31855 thermoCouple(selectPin, dataPin, clockPin);
thermoCouple.begin();
2021-12-10 05:12:41 -05:00
fprintf(stderr, "SPIspeed...\n");
for (uint32_t sp = 100000; sp <= 1000000; sp += 100000)
{
2023-11-29 09:53:40 -05:00
thermoCouple.setSPIspeed(sp);
2021-12-10 05:12:41 -05:00
fprintf(stderr, "%ld\t", sp);
2023-11-29 09:53:40 -05:00
assertEqual(sp, thermoCouple.getSPIspeed());
2021-12-10 05:12:41 -05:00
}
fprintf(stderr, "\nsetSWSPIdelay...\n");
for (uint16_t del = 0; del < 11; del++)
{
2023-11-29 09:53:40 -05:00
thermoCouple.setSWSPIdelay(del);
2021-12-10 05:12:41 -05:00
fprintf(stderr, "%d\t", del);
2023-11-29 09:53:40 -05:00
assertEqual(del, thermoCouple.getSWSPIdelay());
2021-12-10 05:12:41 -05:00
}
2021-01-29 06:31:58 -05:00
}
2021-12-10 05:12:41 -05:00
2021-01-29 06:31:58 -05:00
unittest_main()
2022-11-16 09:46:22 -05:00
// -- END OF FILE --