diff mbox

[i-g-t,5/5] tests/stats: Make sure we properly invalidate the cached mean

Message ID 1435274819-2777-5-git-send-email-damien.lespiau@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lespiau, Damien June 25, 2015, 11:26 p.m. UTC
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>
---
 lib/tests/igt_stats.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
diff mbox

Patch

diff --git a/lib/tests/igt_stats.c b/lib/tests/igt_stats.c
index 172e4b3..f9081c7 100644
--- a/lib/tests/igt_stats.c
+++ b/lib/tests/igt_stats.c
@@ -45,6 +45,30 @@  static void test_mean(void)
 	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:
  * https://en.wikipedia.org/wiki/Standard_deviation
@@ -80,5 +104,6 @@  static void test_std_deviation(void)
 igt_simple_main
 {
 	test_mean();
+	test_invalidate_mean();
 	test_std_deviation();
 }