1 //===---------------------------------------------------------------------===//
2 // statistics_test - Unit tests for src/statistics.cc
3 //===---------------------------------------------------------------------===//
4 
5 #include "../src/statistics.h"
6 #include "gtest/gtest.h"
7 
8 namespace {
TEST(StatisticsTest,Mean)9 TEST(StatisticsTest, Mean) {
10   EXPECT_DOUBLE_EQ(benchmark::StatisticsMean({42, 42, 42, 42}), 42.0);
11   EXPECT_DOUBLE_EQ(benchmark::StatisticsMean({1, 2, 3, 4}), 2.5);
12   EXPECT_DOUBLE_EQ(benchmark::StatisticsMean({1, 2, 5, 10, 10, 14}), 7.0);
13 }
14 
TEST(StatisticsTest,Median)15 TEST(StatisticsTest, Median) {
16   EXPECT_DOUBLE_EQ(benchmark::StatisticsMedian({42, 42, 42, 42}), 42.0);
17   EXPECT_DOUBLE_EQ(benchmark::StatisticsMedian({1, 2, 3, 4}), 2.5);
18   EXPECT_DOUBLE_EQ(benchmark::StatisticsMedian({1, 2, 5, 10, 10}), 5.0);
19 }
20 
TEST(StatisticsTest,StdDev)21 TEST(StatisticsTest, StdDev) {
22   EXPECT_DOUBLE_EQ(benchmark::StatisticsStdDev({101, 101, 101, 101}), 0.0);
23   EXPECT_DOUBLE_EQ(benchmark::StatisticsStdDev({1, 2, 3}), 1.0);
24   EXPECT_DOUBLE_EQ(benchmark::StatisticsStdDev({2.5, 2.4, 3.3, 4.2, 5.1}),
25                    1.151086443322134);
26 }
27 
28 }  // end namespace
29