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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
unittest_teardown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest(test_constructor)
|
|
|
|
{
|
2021-11-01 10:56:22 -04:00
|
|
|
fprintf(stderr, "VERSION:\t%s\n", (char*) FRACTION_LIB_VERSION);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
// TODO
|
|
|
|
assertEqual(1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unittest_main()
|
|
|
|
|
|
|
|
// --------
|