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

134 lines
3.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 AverageAngle class
// https://github.com/RobTillaart/AverageAngle
// 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)
2021-10-18 15:44:20 -04:00
2021-01-29 06:31:58 -05:00
#include <ArduinoUnitTests.h>
#include "AverageAngle.h"
unittest_setup()
{
2022-10-29 07:59:29 -04:00
fprintf(stderr, "AVERAGE_ANGLE_LIB_VERSION: %s\n", (char*) AVERAGE_ANGLE_LIB_VERSION);
2021-01-29 06:31:58 -05:00
}
2023-02-01 07:53:15 -05:00
2021-01-29 06:31:58 -05:00
unittest_teardown()
{
}
2021-10-18 15:44:20 -04:00
2021-12-13 14:51:57 -05:00
unittest(test_constants)
{
assertEqualFloat(PI / 180.0, DEG_TO_RAD, 0.00001);
assertEqualFloat(180.0 / PI, RAD_TO_DEG, 0.00001);
assertEqualFloat(PI / 200.0, GRAD_TO_RAD, 0.00001);
assertEqualFloat(200.0 / PI, RAD_TO_GRAD, 0.00001);
2023-02-01 07:53:15 -05:00
// ERROR CODES
assertEqual(0, AVERAGE_ANGLE_OK);
assertEqual(-10, AVERAGE_ANGLE_OVERFLOW);
assertEqual(-20, AVERAGE_ANGLE_SINGULARITY);
2021-12-13 14:51:57 -05:00
}
2021-01-29 06:31:58 -05:00
unittest(test_constructor)
{
AverageAngle dd(AverageAngle::DEGREES);
AverageAngle rr(AverageAngle::RADIANS);
2021-10-18 15:44:20 -04:00
AverageAngle gg(AverageAngle::GRADIANS);
2021-01-29 06:31:58 -05:00
assertEqual(AverageAngle::DEGREES, dd.type());
assertEqual(AverageAngle::RADIANS, rr.type());
2021-10-18 15:44:20 -04:00
assertEqual(AverageAngle::GRADIANS, gg.type());
2023-02-01 07:53:15 -05:00
assertEqual(AVERAGE_ANGLE_OK, dd.lastError());
assertEqual(AVERAGE_ANGLE_OK, rr.lastError());
assertEqual(AVERAGE_ANGLE_OK, gg.lastError());
2021-01-29 06:31:58 -05:00
}
2021-10-18 15:44:20 -04:00
2021-01-29 06:31:58 -05:00
unittest(test_degrees)
{
AverageAngle aa(AverageAngle::DEGREES);
for (int i = 0; i < 10; i++)
{
int n = aa.add(i);
assertEqual(i + 1, n);
}
2021-10-18 15:44:20 -04:00
fprintf(stderr, "%f\n", aa.getAverage());
fprintf(stderr, "%f\n", aa.getTotalLength());
fprintf(stderr, "%f\n", aa.getAverageLength());
2021-01-29 06:31:58 -05:00
assertEqual(10, aa.count());
2021-10-18 15:44:20 -04:00
assertEqualFloat(4.5, aa.getAverage(), 0.001);
assertEqualFloat(9.987438, aa.getTotalLength(), 0.001);
assertEqualFloat(0.9987438, aa.getAverageLength(), 0.001);
2021-01-29 06:31:58 -05:00
}
2021-10-18 15:44:20 -04:00
unittest(test_radians)
{
AverageAngle aa(AverageAngle::RADIANS);
for (int i = 0; i < 10; i++)
{
int n = aa.add(i);
assertEqual(i + 1, n);
}
fprintf(stderr, "%f\n", aa.getAverage());
fprintf(stderr, "%f\n", aa.getTotalLength());
fprintf(stderr, "%f\n", aa.getAverageLength());
assertEqual(10, aa.count());
assertEqualFloat(1.35841, aa.getAverage(), 0.001);
assertEqualFloat(2.000152, aa.getTotalLength(), 0.001);
assertEqualFloat(0.2000152, aa.getAverageLength(), 0.001);
}
unittest(test_gradians)
{
AverageAngle aa(AverageAngle::GRADIANS);
for (int i = 0; i < 10; i++)
{
int n = aa.add(i);
assertEqual(i + 1, n);
}
fprintf(stderr, "%f\n", aa.getAverage());
fprintf(stderr, "%f\n", aa.getTotalLength());
fprintf(stderr, "%f\n", aa.getAverageLength());
assertEqual(10, aa.count());
assertEqualFloat(4.5, aa.getAverage(), 0.001);
assertEqualFloat(9.98982, aa.getTotalLength(), 0.001);
assertEqualFloat(0.998982, aa.getAverageLength(), 0.001);
}
2021-01-29 06:31:58 -05:00
unittest_main()
2023-02-01 07:53:15 -05:00
// -- END OF FILE --