mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
104 lines
2.0 KiB
C++
104 lines
2.0 KiB
C++
|
//
|
||
|
// FILE: unit_test_001.cpp
|
||
|
// AUTHOR: Rob Tillaart
|
||
|
// DATE: 2020-12-03
|
||
|
// PURPOSE: unit tests for the Histogram
|
||
|
// https://github.com/RobTillaart/Histogram
|
||
|
// 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 "histogram.h"
|
||
|
|
||
|
|
||
|
|
||
|
unittest_setup()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
unittest_teardown()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
unittest(test_new_operator)
|
||
|
{
|
||
|
assertEqualINF(exp(800));
|
||
|
assertEqualINF(0.0/0.0);
|
||
|
assertEqualINF(42);
|
||
|
|
||
|
assertEqualNAN(INFINITY - INFINITY);
|
||
|
assertEqualNAN(0.0/0.0);
|
||
|
assertEqualNAN(42);
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
unittest(test_constructor)
|
||
|
{
|
||
|
fprintf(stderr, "VERSION: %s\n", HISTOGRAM_LIB_VERSION);
|
||
|
|
||
|
float diceValues[] = {0.5, 1.5, 2.5, 3.5, 4.5, 5.5 };
|
||
|
Histogram hist(6, diceValues);
|
||
|
assertEqual(7, hist.size());
|
||
|
assertEqual(0, hist.count());
|
||
|
|
||
|
for (int i = 0; i < 7; i++)
|
||
|
{
|
||
|
fprintf(stderr, "%d\t", i);
|
||
|
assertEqual(0, hist.bucket(i));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
unittest(test_dice)
|
||
|
{
|
||
|
float diceValues[] = { 0.5, 1.5, 2.5, 3.5, 4.5, 5.5 };
|
||
|
Histogram hist(6, diceValues);
|
||
|
assertEqual(7, hist.size());
|
||
|
assertEqual(0, hist.count());
|
||
|
|
||
|
for (int d = 0; d < 70; d++)
|
||
|
{
|
||
|
hist.add( d % 7 ); // simulate dice
|
||
|
}
|
||
|
|
||
|
assertEqual(7, hist.size());
|
||
|
assertEqual(70, hist.count());
|
||
|
|
||
|
for (int i = 0; i < 7; i++)
|
||
|
{
|
||
|
fprintf(stderr, "%d\t", i);
|
||
|
assertEqual(10, hist.bucket(i));
|
||
|
}
|
||
|
|
||
|
hist.clear();
|
||
|
assertEqual(7, hist.size());
|
||
|
assertEqual(0, hist.count());
|
||
|
|
||
|
for (int i = 0; i < 7; i++)
|
||
|
{
|
||
|
fprintf(stderr, "%d\t", i);
|
||
|
assertEqual(0, hist.bucket(i));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
unittest_main()
|
||
|
|
||
|
// --------
|