2021-01-29 06:31:58 -05:00
|
|
|
//
|
|
|
|
// FILE: unit_test_001.cpp
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// DATE: 2020-12-30
|
|
|
|
// PURPOSE: unit tests for the M62429 volume IC
|
|
|
|
// https://github.com/RobTillaart/M62429
|
|
|
|
// 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 "M62429.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unittest_setup()
|
|
|
|
{
|
2021-12-21 06:50:11 -05:00
|
|
|
fprintf(stderr, "M62429_VERSION: %s\n", (char *) M62429_VERSION);
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
2021-12-21 06:50:11 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest_teardown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-12-21 06:50:11 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
/*
|
|
|
|
unittest(test_new_operator)
|
|
|
|
{
|
|
|
|
assertEqualINF(exp(800));
|
|
|
|
assertEqualINF(0.0/0.0);
|
|
|
|
assertEqualINF(42);
|
2021-12-21 06:50:11 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqualNAN(INFINITY - INFINITY);
|
|
|
|
assertEqualNAN(0.0/0.0);
|
|
|
|
assertEqualNAN(42);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2021-12-21 06:50:11 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest(test_all)
|
|
|
|
{
|
|
|
|
uint8_t dataPin = 6;
|
|
|
|
uint8_t clockPin = 7;
|
2021-12-21 06:50:11 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
M62429 AMP;
|
|
|
|
AMP.begin(dataPin, clockPin);
|
|
|
|
|
|
|
|
fprintf(stderr, "mute on off\n");
|
|
|
|
assertFalse(AMP.isMuted());
|
|
|
|
AMP.muteOn();
|
|
|
|
assertTrue(AMP.isMuted());
|
|
|
|
AMP.muteOff();
|
|
|
|
assertFalse(AMP.isMuted());
|
|
|
|
|
2021-12-21 06:50:11 -05:00
|
|
|
fprintf(stderr, "\nset get volume(0)\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
for (int vol = 0; vol < 10; vol++)
|
|
|
|
{
|
|
|
|
AMP.setVolume(0, vol);
|
|
|
|
assertEqual(vol, AMP.getVolume(0));
|
|
|
|
}
|
2021-12-21 06:50:11 -05:00
|
|
|
|
|
|
|
fprintf(stderr, "\nset get volume(1)\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
for (int vol = 10; vol < 20; vol++)
|
|
|
|
{
|
|
|
|
AMP.setVolume(1, vol);
|
|
|
|
assertEqual(vol, AMP.getVolume(1));
|
|
|
|
}
|
|
|
|
|
2021-12-21 06:50:11 -05:00
|
|
|
fprintf(stderr, "\nset get volume(2)\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
for (int vol = 30; vol < 40; vol++)
|
|
|
|
{
|
|
|
|
AMP.setVolume(2, vol);
|
|
|
|
assertEqual(vol, AMP.getVolume(0));
|
|
|
|
assertEqual(vol, AMP.getVolume(1));
|
|
|
|
}
|
|
|
|
|
2021-12-21 06:50:11 -05:00
|
|
|
fprintf(stderr, "\nincr, decr\n");
|
2021-01-29 06:31:58 -05:00
|
|
|
AMP.setVolume(0, 0);
|
|
|
|
for (int i = 0; i < 10; i++) AMP.incr();
|
|
|
|
assertEqual(10, AMP.getVolume(0));
|
|
|
|
for (int i = 0; i < 5; i++) AMP.decr();
|
|
|
|
assertEqual(5, AMP.getVolume(0));
|
|
|
|
}
|
|
|
|
|
2021-12-21 06:50:11 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest_main()
|
|
|
|
|
|
|
|
// --------
|