Skip to content

Commit

Permalink
lib: Add test for stats_dist_get_variance()
Browse files Browse the repository at this point in the history
  • Loading branch information
mrannanj committed Aug 22, 2018
1 parent e58933f commit 3f0c4ba
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/lib/test-stats-dist.c
Expand Up @@ -48,6 +48,37 @@ test_stats_dist_verify(const struct stats_dist *t, const int64_t *input,
i_free(copy);
}

static void test_stats_dist_get_variance(void)
{
static const struct {
int64_t in[10];
double out;
} tests[] = {
{ .in = { 2, 2, 2, -1 }, .out = 0.0 },
{ .in = { -1 }, .out = 0.0 },
{ .in = { 1, 2, 3, 4, 5, 6, 7, 8, -1 }, .out = 5.25 },
};

struct stats_dist *t;
unsigned int i, j;

test_begin("stats_dists_get_variance");

for (i = 0; i < N_ELEMENTS(tests); i++) {
t = stats_dist_init();
for (j = 0; tests[i].in[j] >= 0; j++) {
stats_dist_add(t, tests[i].in[j]);
test_stats_dist_verify(t, tests[i].in, j+1);
}
test_assert_idx(DBL_EQ(stats_dist_get_variance(t),
tests[i].out), i);

stats_dist_deinit(&t);
}

test_end();
}

void test_stats_dist(void)
{
static int64_t test_input1[] = {
Expand Down Expand Up @@ -96,4 +127,6 @@ void test_stats_dist(void)
test_assert(stats_dist_get_95th(t) > 0 && stats_dist_get_95th(t) < i-1);
stats_dist_deinit(&t);
test_end();

test_stats_dist_get_variance();
}

0 comments on commit 3f0c4ba

Please sign in to comment.