2021-01-29 06:31:58 -05:00
|
|
|
//
|
|
|
|
// FILE: unit_test_001.cpp
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// DATE: 2020-12-24
|
|
|
|
// PURPOSE: unit tests for the FunctionGenerator library
|
|
|
|
// https://github.com/RobTillaart/FunctionGenerator
|
|
|
|
// 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
|
|
|
|
// ----------------------------
|
|
|
|
// assertEqual(expected, actual)
|
|
|
|
// assertNotEqual(expected, actual)
|
|
|
|
// assertLess(expected, actual)
|
|
|
|
// assertMore(expected, actual)
|
|
|
|
// assertLessOrEqual(expected, actual)
|
|
|
|
// assertMoreOrEqual(expected, actual)
|
|
|
|
// assertTrue(actual)
|
|
|
|
// assertFalse(actual)
|
|
|
|
// assertNull(actual)
|
|
|
|
// assertNotNull(actual)
|
|
|
|
|
|
|
|
#include <ArduinoUnitTests.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "functionGenerator.h"
|
|
|
|
|
|
|
|
|
|
|
|
unittest_setup()
|
|
|
|
{
|
2021-12-18 10:52:23 -05:00
|
|
|
fprintf(stderr, "FUNCTIONGENERATOR_LIB_VERSION: %s\n", (char*) FUNCTIONGENERATOR_LIB_VERSION);
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
unittest_teardown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_constructor)
|
|
|
|
{
|
|
|
|
funcgen gen;
|
|
|
|
|
|
|
|
fprintf(stderr, "Default values\n");
|
|
|
|
assertEqualFloat(1, gen.getPeriod(), 0.0001);
|
|
|
|
assertEqualFloat(1, gen.getFrequency(), 0.0001);
|
|
|
|
assertEqualFloat(1, gen.getAmplitude(), 0.0001);
|
|
|
|
assertEqualFloat(0, gen.getPhase(), 0.0001);
|
|
|
|
assertEqualFloat(0, gen.getYShift(), 0.0001);
|
|
|
|
}
|
|
|
|
|
2021-11-02 06:27:01 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest(test_constructor_param)
|
|
|
|
{
|
|
|
|
funcgen gen(4, 2.5, 0.33, -0.5);
|
|
|
|
|
|
|
|
fprintf(stderr, "funcgen gen(4, 2.5, 0.33, -0.5)\n");
|
|
|
|
|
|
|
|
assertEqualFloat(4.00, gen.getPeriod(), 0.0001);
|
|
|
|
assertEqualFloat(0.25, gen.getFrequency(), 0.0001);
|
|
|
|
assertEqualFloat(2.50, gen.getAmplitude(), 0.0001);
|
|
|
|
assertEqualFloat(0.33, gen.getPhase(), 0.0001);
|
|
|
|
assertEqualFloat(-0.5, gen.getYShift(), 0.0001);
|
|
|
|
}
|
|
|
|
|
2021-11-02 06:27:01 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest(test_set_get_param)
|
|
|
|
{
|
|
|
|
funcgen gen;
|
|
|
|
|
|
|
|
fprintf(stderr, "set get parameters\n");
|
|
|
|
|
|
|
|
gen.setPeriod(3.1415);
|
|
|
|
assertEqualFloat(3.1415, gen.getPeriod(), 0.0001);
|
|
|
|
|
|
|
|
gen.setFrequency(142.5);
|
|
|
|
assertEqualFloat(142.5, gen.getFrequency(), 0.0001);
|
|
|
|
|
|
|
|
gen.setAmplitude(2.345);
|
|
|
|
assertEqualFloat(2.345, gen.getAmplitude(), 0.0001);
|
|
|
|
|
|
|
|
gen.setPhase(1.5);
|
|
|
|
assertEqualFloat(1.5, gen.getPhase(), 0.0001);
|
|
|
|
|
|
|
|
gen.setYShift(6.89);
|
|
|
|
assertEqualFloat(6.89, gen.getYShift(), 0.0001);
|
|
|
|
}
|
|
|
|
|
2021-11-02 06:27:01 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest(test_line_zero)
|
|
|
|
{
|
|
|
|
funcgen gen;
|
2021-12-18 10:52:23 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
fprintf(stderr, "default line = 1.0 \n");
|
|
|
|
|
|
|
|
assertEqualFloat(1.00, gen.line(), 0.0001);
|
|
|
|
|
|
|
|
fprintf(stderr, "line = amplitude + yshift\n");
|
|
|
|
|
|
|
|
gen.setAmplitude(2.34);
|
|
|
|
gen.setYShift(6.89);
|
|
|
|
assertEqualFloat(9.23, gen.line(), 0.0001);
|
|
|
|
|
|
|
|
fprintf(stderr, "zero == 0 \n");
|
|
|
|
|
|
|
|
assertEqual(0, gen.zero());
|
|
|
|
}
|
|
|
|
|
2021-11-02 06:27:01 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
/*
|
|
|
|
TODO wave forms 6x ?
|
|
|
|
*/
|
|
|
|
|
|
|
|
unittest_main()
|
|
|
|
|
|
|
|
// --------
|