summaryrefslogtreecommitdiff
path: root/lib/tests
diff options
context:
space:
mode:
authorDamien Lespiau <damien.lespiau@intel.com>2015-06-25 23:59:21 +0100
committerDamien Lespiau <damien.lespiau@intel.com>2015-06-27 16:03:27 +0100
commit515cec1210764241153f5d46d70ba5e943201b14 (patch)
tree4b7866c6de7bfbf32423bbbe30dde0af78bcefb8 /lib/tests
parent05c10f940f9df3a5b24e2a0b476052fbe5a22282 (diff)
stats: Add a way to retrieve the standard deviation
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Diffstat (limited to 'lib/tests')
-rw-r--r--lib/tests/Makefile.am2
-rw-r--r--lib/tests/igt_stats.c33
2 files changed, 34 insertions, 1 deletions
diff --git a/lib/tests/Makefile.am b/lib/tests/Makefile.am
index e59065bb..938d2ab0 100644
--- a/lib/tests/Makefile.am
+++ b/lib/tests/Makefile.am
@@ -15,5 +15,5 @@ AM_CFLAGS = $(DRM_CFLAGS) $(CWARNFLAGS) \
LDADD = ../libintel_tools.la $(PCIACCESS_LIBS) $(DRM_LIBS) $(LIBUNWIND_LIBS)
-LDADD += $(CAIRO_LIBS) $(LIBUDEV_LIBS) $(GLIB_LIBS)
+LDADD += $(CAIRO_LIBS) $(LIBUDEV_LIBS) $(GLIB_LIBS) -lm
AM_CFLAGS += $(CAIRO_CFLAGS) $(LIBUDEV_CFLAGS) $(GLIB_CFLAGS)
diff --git a/lib/tests/igt_stats.c b/lib/tests/igt_stats.c
index c20b4537..172e4b32 100644
--- a/lib/tests/igt_stats.c
+++ b/lib/tests/igt_stats.c
@@ -45,7 +45,40 @@ static void test_mean(void)
igt_stats_fini(&stats);
}
+/*
+ * Taken from the "Basic examples" section of:
+ * https://en.wikipedia.org/wiki/Standard_deviation
+ */
+static void test_std_deviation(void)
+{
+ igt_stats_t stats;
+ double mean, variance, std_deviation;
+
+ igt_stats_init(&stats, 8);
+
+ igt_stats_push(&stats, 2);
+ igt_stats_push(&stats, 4);
+ igt_stats_push(&stats, 4);
+ igt_stats_push(&stats, 4);
+ igt_stats_push(&stats, 5);
+ igt_stats_push(&stats, 5);
+ igt_stats_push(&stats, 7);
+ igt_stats_push(&stats, 9);
+
+ mean = igt_stats_get_mean(&stats);
+ igt_assert(mean == (2 + 3 * 4 + 2 * 5 + 7 + 9) / 8.);
+
+ variance = igt_stats_get_variance(&stats);
+ igt_assert(variance == 4);
+
+ std_deviation = igt_stats_get_std_deviation(&stats);
+ igt_assert(std_deviation == 2);
+
+ igt_stats_fini(&stats);
+}
+
igt_simple_main
{
test_mean();
+ test_std_deviation();
}