2021-10-14 08:54:11 -04:00
|
|
|
//
|
|
|
|
// FILE: unit_test_001.cpp
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// DATE: 2021-10-14
|
|
|
|
// PURPOSE: unit tests for the MINMAX library
|
|
|
|
// https://github.com/RobTillaart/MINMAX
|
|
|
|
//
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
|
|
|
|
#include <ArduinoUnitTests.h>
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "MINMAX.h"
|
|
|
|
|
|
|
|
|
|
|
|
unittest_setup()
|
|
|
|
{
|
2021-12-21 13:57:20 -05:00
|
|
|
fprintf(stderr, "MINMAX_LIB_VERSION: %s\n", (char *) MINMAX_LIB_VERSION);
|
2021-10-14 08:54:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
unittest_teardown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-21 13:57:20 -05:00
|
|
|
unittest(test_constants)
|
2021-10-14 08:54:11 -04:00
|
|
|
{
|
2021-12-21 13:57:20 -05:00
|
|
|
assertEqual(MINMAX_NO_CHANGE , 0X00);
|
|
|
|
assertEqual(MINMAX_MIN_CHANGED, 0X01);
|
|
|
|
assertEqual(MINMAX_MAX_CHANGED, 0X02);
|
|
|
|
assertEqual(MINMAX_RESET_DONE , 0X80);
|
|
|
|
}
|
2021-10-14 08:54:11 -04:00
|
|
|
|
2021-12-21 13:57:20 -05:00
|
|
|
|
|
|
|
unittest(test_add)
|
|
|
|
{
|
2021-10-14 08:54:11 -04:00
|
|
|
MINMAX mm;
|
2021-12-21 13:57:20 -05:00
|
|
|
|
2021-10-14 08:54:11 -04:00
|
|
|
for (int i = 0; i < 1000; i++)
|
|
|
|
{
|
|
|
|
mm.add(i);
|
|
|
|
}
|
|
|
|
assertEqual(0, mm.minimum());
|
|
|
|
assertEqual(999, mm.maximum());
|
|
|
|
assertEqual(1000, mm.count());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_reset)
|
|
|
|
{
|
|
|
|
MINMAX mm;
|
2021-12-21 13:57:20 -05:00
|
|
|
|
2021-10-14 08:54:11 -04:00
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
mm.add(i);
|
|
|
|
}
|
2022-11-17 11:36:35 -05:00
|
|
|
assertEqual(0, mm.minimum());
|
|
|
|
assertEqual(9, mm.maximum());
|
|
|
|
assertEqual(10, mm.count());
|
2021-10-14 08:54:11 -04:00
|
|
|
mm.reset();
|
|
|
|
assertEqual(0, mm.minimum());
|
|
|
|
assertEqual(0, mm.maximum());
|
|
|
|
assertEqual(0, mm.count());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_autoReset)
|
|
|
|
{
|
|
|
|
MINMAX mm;
|
|
|
|
|
|
|
|
mm.autoReset(10);
|
2021-12-21 13:57:20 -05:00
|
|
|
|
2021-10-14 08:54:11 -04:00
|
|
|
for (int i = 0; i < 15; i++)
|
|
|
|
{
|
|
|
|
mm.add(i);
|
|
|
|
}
|
|
|
|
assertEqual(10, mm.minimum());
|
|
|
|
assertEqual(14, mm.maximum());
|
|
|
|
assertEqual(5, mm.count());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-17 11:36:35 -05:00
|
|
|
unittest(test_lastValue)
|
|
|
|
{
|
|
|
|
MINMAX mm;
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
mm.add(i);
|
|
|
|
}
|
|
|
|
assertEqual(9, mm.lastValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-14 08:54:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
unittest_main()
|
|
|
|
|
|
|
|
|
|
|
|
// -- END OF FILE --
|