tests/stats: Make sure we properly invalidate the cached mean

Sure, that's an implementation details, but make sure we do recompute
the mean when we add a new value.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
This commit is contained in:
Damien Lespiau 2015-06-26 00:20:44 +01:00
parent 515cec1210
commit 76ea7b9133

View File

@ -45,6 +45,30 @@ static void test_mean(void)
igt_stats_fini(&stats); igt_stats_fini(&stats);
} }
static void test_invalidate_mean(void)
{
igt_stats_t stats;
double mean1, mean2;
igt_stats_init(&stats, 6);
igt_stats_push(&stats, 2);
igt_stats_push(&stats, 4);
igt_stats_push(&stats, 6);
igt_stats_push(&stats, 8);
igt_stats_push(&stats, 10);
mean1 = igt_stats_get_mean(&stats);
igt_assert(mean1 == (2 + 4 + 6 + 8 + 10) / 5.);
igt_stats_push(&stats, 100);
mean2 = igt_stats_get_mean(&stats);
igt_assert(mean1 != mean2);
igt_stats_fini(&stats);
}
/* /*
* Taken from the "Basic examples" section of: * Taken from the "Basic examples" section of:
* https://en.wikipedia.org/wiki/Standard_deviation * https://en.wikipedia.org/wiki/Standard_deviation
@ -80,5 +104,6 @@ static void test_std_deviation(void)
igt_simple_main igt_simple_main
{ {
test_mean(); test_mean();
test_invalidate_mean();
test_std_deviation(); test_std_deviation();
} }