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/common/tests/unit/hist.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
784 B
C++
Raw Permalink Normal View History

/* Unit tests for histogram.
*
* 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
*/
2019-06-26 20:15:26 +02:00
#include <array>
#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>
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};
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
Test(hist, simple) {
Hist h(10, 2);
for (auto td : test_data)
h.put(td);
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);
}