2023-08-31 17:35:12 +02:00
|
|
|
/* Unit tests for histogram.
|
2018-08-22 11:29:39 +02:00
|
|
|
*
|
2023-08-31 11:17:07 +02:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2023-08-28 12:31:18 +02:00
|
|
|
*/
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2019-06-26 20:15:26 +02:00
|
|
|
#include <array>
|
|
|
|
|
2018-08-22 11:29:39 +02:00
|
|
|
#include <criterion/criterion.h>
|
|
|
|
|
2019-04-07 15:12:32 +02:00
|
|
|
#include <villas/hist.hpp>
|
2019-04-23 12:57:51 +02:00
|
|
|
#include <villas/utils.hpp>
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2019-06-26 20:15:26 +02:00
|
|
|
const std::array<double, 10> test_data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2019-06-03 17:31:12 +02:00
|
|
|
using namespace villas;
|
|
|
|
|
2020-09-11 15:16:53 +02:00
|
|
|
// cppcheck-suppress unknownMacro
|
2018-10-19 14:33:10 +02:00
|
|
|
TestSuite(hist, .description = "Histogram");
|
2018-08-23 13:14:39 +02:00
|
|
|
|
2018-08-22 11:29:39 +02:00
|
|
|
Test(hist, simple) {
|
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
Hist h(10, 2);
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
for (auto td : test_data)
|
|
|
|
h.put(td);
|
2018-08-22 11:29:39 +02:00
|
|
|
|
2023-09-07 13:19:19 +02:00
|
|
|
cr_assert_float_eq(h.getMean(), 5.5, 1e-6, "Mean is %lf", h.getMean());
|
|
|
|
cr_assert_float_eq(h.getVar(), 9.1666, 1e-3);
|
|
|
|
cr_assert_float_eq(h.getStddev(), 3.027650, 1e-6);
|
2018-08-22 11:29:39 +02:00
|
|
|
}
|