mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
fixed some unit tests
This commit is contained in:
parent
f038f00572
commit
da611d69b1
2 changed files with 31 additions and 30 deletions
17
tests/hist.c
17
tests/hist.c
|
@ -9,26 +9,27 @@
|
|||
#include <criterion/criterion.h>
|
||||
|
||||
#include "hist.h"
|
||||
#include "utils.h"
|
||||
|
||||
const double test_data[] = {};
|
||||
const double test_data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
|
||||
/* Histogram of test_data with 200 buckets between -100 and 100 */
|
||||
const int hist_result[] = {};
|
||||
|
||||
Test(hist) {
|
||||
Test(hist, simple) {
|
||||
struct hist h;
|
||||
|
||||
hist_create(&h, -100, 100, 1);
|
||||
|
||||
for (int i = 0; i < ARRAY_LEN(test_data); i++)
|
||||
hist_put(&h, test_data[i])
|
||||
hist_put(&h, test_data[i]);
|
||||
|
||||
cr_assert_float_eq(hist_mean(&h), 1, 1e-6);
|
||||
cr_assert_float_eq(hist_var(s&h), 1, 1e-6);
|
||||
cr_assert_float_eq(hist_stddev(&h), 1, 1e-6);
|
||||
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);
|
||||
|
||||
for (int i = 0; i < ARRAY_LEN(hist_result); i++)
|
||||
cr_assert_eq()
|
||||
// for (int i = 0; i < ARRAY_LEN(hist_result); i++)
|
||||
// cr_assert_eq()
|
||||
|
||||
hist_destroy(&h);
|
||||
}
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include "timing.h"
|
||||
|
||||
Test(time_now) {
|
||||
Test(timing, time_now) {
|
||||
struct timespec now1 = time_now();
|
||||
struct timespec now2 = time_now();
|
||||
|
||||
|
@ -20,9 +20,9 @@ Test(time_now) {
|
|||
cr_assert_gt(delta, 0, "time_now() was reordered!");
|
||||
}
|
||||
|
||||
Test(time_diff) {
|
||||
struct timespec ts1 = { .tv_sec 1, .tv_nsec = 0}; /* Value doesnt matter */
|
||||
struct timespec ts2 = { .tv_sec 0, .tv_nsec = 1}; /* Overflow in nano seconds! */
|
||||
Test(timing, time_diff) {
|
||||
struct timespec ts1 = { .tv_sec = 0, .tv_nsec = 1}; /* Value doesnt matter */
|
||||
struct timespec ts2 = { .tv_sec = 1, .tv_nsec = 0}; /* Overflow in nano seconds! */
|
||||
|
||||
struct timespec ts3 = time_diff(&ts1, &ts2);
|
||||
|
||||
|
@ -31,27 +31,27 @@ Test(time_diff) {
|
|||
cr_assert_eq(ts3.tv_nsec, 999999999);
|
||||
}
|
||||
|
||||
Test(time_add) {
|
||||
struct timespec ts1 = { .tv_sec 1, .tv_nsec = 999999999}; /* Value doesnt matter */
|
||||
struct timespec ts2 = { .tv_sec 1, .tv_nsec = 1}; /* Overflow in nano seconds! */
|
||||
Test(timing, time_add) {
|
||||
struct timespec ts1 = { .tv_sec = 1, .tv_nsec = 999999999}; /* Value doesnt matter */
|
||||
struct timespec ts2 = { .tv_sec = 1, .tv_nsec = 1}; /* Overflow in nano seconds! */
|
||||
|
||||
struct timespec ts3 = time_add(&ts1, &ts2);
|
||||
|
||||
/* ts4 == ts2? */
|
||||
cr_assert_eq(ts3.tv_sec, 2);
|
||||
cr_assert_eq(ts3.tv_sec, 3);
|
||||
cr_assert_eq(ts3.tv_nsec, 0);
|
||||
}
|
||||
|
||||
Test(time_delta) {
|
||||
struct timespec ts1 = { .tv_sec 1, .tv_nsec = 123}; /* Value doesnt matter */
|
||||
struct timespec ts2 = { .tv_sec 5, .tv_nsec = 246}; /* Overflow in nano seconds! */
|
||||
Test(timing, time_delta) {
|
||||
struct timespec ts1 = { .tv_sec = 1, .tv_nsec = 123}; /* Value doesnt matter */
|
||||
struct timespec ts2 = { .tv_sec = 5, .tv_nsec = 246}; /* Overflow in nano seconds! */
|
||||
|
||||
double = time_delta(&ts1, &ts2);
|
||||
double delta = time_delta(&ts1, &ts2);
|
||||
|
||||
cr_assert_float_eq(ts3.tv_sec, 4 + 123e-9, 1e-9);
|
||||
cr_assert_float_eq(delta, 4 + 123e-9, 1e-9);
|
||||
}
|
||||
|
||||
Test(time_from_double) {
|
||||
Test(timing, time_from_double) {
|
||||
double ref = 1234.56789;
|
||||
|
||||
struct timespec ts = time_from_double(ref);
|
||||
|
@ -60,7 +60,7 @@ Test(time_from_double) {
|
|||
cr_assert_eq(ts.tv_nsec, 567890000);
|
||||
}
|
||||
|
||||
Test(time_to_from_double) {
|
||||
Test(timing, time_to_from_double) {
|
||||
double ref = 1234.56789;
|
||||
|
||||
struct timespec ts = time_from_double(ref);
|
||||
|
@ -69,22 +69,22 @@ Test(time_to_from_double) {
|
|||
cr_assert_float_eq(dbl, ref, 1e-9);
|
||||
}
|
||||
|
||||
Test(timer_wait_until) {
|
||||
int tfd = timer_fd_create(CLOCK_MONOTONIC, 0);
|
||||
Test(timing, timerfd_wait_until) {
|
||||
int tfd = timerfd_create(CLOCK_REALTIME, 0);
|
||||
|
||||
cr_assert(tfd > 0);
|
||||
|
||||
double waitfor = 1.123456789;
|
||||
double waitfor = 0.423456789;
|
||||
|
||||
struct timespec start = time_now();
|
||||
struct timespec diff = time_from_double(waitfor);
|
||||
struct timespec future = time_add(&start, &diff)
|
||||
struct timespec future = time_add(&start, &diff);
|
||||
|
||||
timer_wait_until(tfd, &future);
|
||||
timerfd_wait_until(tfd, &future);
|
||||
|
||||
struct timespec end = time_now();
|
||||
|
||||
double waited = time_delta(&end, &start);
|
||||
double waited = time_delta(&start, &end);
|
||||
|
||||
cr_assert_float_eq(waited, waitfor, 1e-3, "We did not wait for %f secs");
|
||||
cr_assert_float_eq(waited, waitfor, 1e-3, "We slept for %f instead of %f secs", waited, waitfor);
|
||||
}
|
Loading…
Add table
Reference in a new issue