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 Fraction
|
|
|
|
// https://github.com/RobTillaart/Fraction
|
|
|
|
// 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)
|
|
|
|
|
2021-11-01 10:56:22 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
#include <ArduinoUnitTests.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "fraction.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unittest_setup()
|
|
|
|
{
|
2021-12-18 08:10:11 -05:00
|
|
|
fprintf(stderr, "FRACTION_LIB_VERSION: %s\n", (char*) FRACTION_LIB_VERSION);
|
2021-01-29 06:31:58 -05:00
|
|
|
}
|
|
|
|
|
2023-02-03 07:14:59 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
unittest_teardown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_constructor)
|
|
|
|
{
|
|
|
|
Fraction pi(PI);
|
|
|
|
assertEqual(355, pi.nominator());
|
|
|
|
assertEqual(113, pi.denominator());
|
|
|
|
assertFalse(pi.isProper());
|
|
|
|
fprintf(stderr, "PI -> %1.8f\n", pi.toFloat());
|
|
|
|
|
|
|
|
Fraction ee(EULER);
|
|
|
|
assertEqual(3985, ee.nominator());
|
|
|
|
assertEqual(1466, ee.denominator());
|
|
|
|
assertFalse(ee.isProper());
|
|
|
|
fprintf(stderr, "EULER -> %1.8f\n", ee.toFloat());
|
|
|
|
|
|
|
|
Fraction fr(49, 14);
|
|
|
|
assertEqual(7, fr.nominator());
|
|
|
|
assertEqual(2, fr.denominator());
|
|
|
|
assertFalse(fr.isProper());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_comparisons)
|
|
|
|
{
|
|
|
|
Fraction pi(PI);
|
|
|
|
Fraction ee(EULER);
|
|
|
|
assertTrue(pi > ee);
|
|
|
|
assertTrue(pi >= ee);
|
|
|
|
assertTrue(ee < pi);
|
|
|
|
assertTrue(ee <= pi);
|
|
|
|
assertTrue(ee != pi);
|
|
|
|
assertFalse(ee == pi);
|
|
|
|
|
|
|
|
Fraction mpi = -pi;
|
|
|
|
assertEqual(mpi.nominator(), -pi.nominator());
|
|
|
|
assertEqual(mpi.denominator(), pi.denominator());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_math)
|
|
|
|
{
|
|
|
|
Fraction pi(PI);
|
|
|
|
Fraction ee(EULER);
|
2023-02-03 07:14:59 -05:00
|
|
|
// TODO
|
2021-01-29 06:31:58 -05:00
|
|
|
assertEqual(1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest_main()
|
|
|
|
|
2023-02-03 07:14:59 -05:00
|
|
|
|
|
|
|
// -- END OF FILE --
|
|
|
|
|