1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/tests/unit/hist.c

52 lines
1.6 KiB
C
Raw Permalink Normal View History

2016-10-06 17:56:55 -04:00
/** Unit tests for histogram
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
2017-04-27 12:56:43 +02:00
* @license GNU General Public License (version 3)
*
* VILLASnode
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
2017-04-27 12:56:43 +02:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
2017-04-27 12:56:43 +02:00
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2016-10-06 17:56:55 -04:00
*********************************************************************************/
#include <criterion/criterion.h>
2018-03-26 12:50:15 +02:00
#include <villas/hist.h>
#include <villas/utils.h>
2016-10-06 17:56:55 -04:00
2016-10-13 19:48:18 -04:00
const double test_data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
2016-10-06 17:56:55 -04:00
/* Histogram of test_data with 200 buckets between -100 and 100 */
const int hist_result[] = {};
2016-10-13 19:48:18 -04:00
Test(hist, simple) {
2016-10-06 17:56:55 -04:00
struct hist h;
int ret;
2017-05-07 15:49:40 +02:00
ret = hist_init(&h, 0, 0);
cr_assert_eq(ret, 0);
2016-10-06 17:56:55 -04:00
for (int i = 0; i < ARRAY_LEN(test_data); i++)
2016-10-13 19:48:18 -04:00
hist_put(&h, test_data[i]);
2016-10-13 19:48:18 -04:00
cr_assert_float_eq(hist_mean(&h), 5.5, 1e-6);
cr_assert_float_eq(hist_var(&h), 9.1666, 1e-3,);
cr_assert_float_eq(hist_stddev(&h), 3.027650, 1e-6);
2016-10-13 19:48:18 -04:00
// for (int i = 0; i < ARRAY_LEN(hist_result); i++)
// cr_assert_eq()
2016-10-06 17:56:55 -04:00
hist_destroy(&h);
2018-03-26 12:50:15 +02:00
}