2016-10-06 17:56:55 -04:00
|
|
|
/** Unit tests for histogram
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2017-03-03 20:20:13 -04:00
|
|
|
* @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-05-05 19:24:16 +00:00
|
|
|
*
|
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-05-05 19:24:16 +00:00
|
|
|
*
|
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;
|
2016-11-08 00:36:04 -05:00
|
|
|
int ret;
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2017-05-07 15:49:40 +02:00
|
|
|
ret = hist_init(&h, 0, 0);
|
2016-11-08 00:36:04 -05:00
|
|
|
cr_assert_eq(ret, 0);
|
2017-05-05 19:24:16 +00:00
|
|
|
|
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]);
|
2017-05-05 19:24:16 +00:00
|
|
|
|
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);
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2016-10-13 19:48:18 -04:00
|
|
|
// for (int i = 0; i < ARRAY_LEN(hist_result); i++)
|
|
|
|
// cr_assert_eq()
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2016-10-06 17:56:55 -04:00
|
|
|
hist_destroy(&h);
|
2018-03-26 12:50:15 +02:00
|
|
|
}
|