• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   std::vector<double> Inputs;
11   {
12     Inputs = {42, 42, 42, 42};
13     double Res = benchmark::StatisticsMean(Inputs);
14     EXPECT_DOUBLE_EQ(Res, 42.0);
15   }
16   {
17     Inputs = {1, 2, 3, 4};
18     double Res = benchmark::StatisticsMean(Inputs);
19     EXPECT_DOUBLE_EQ(Res, 2.5);
20   }
21   {
22     Inputs = {1, 2, 5, 10, 10, 14};
23     double Res = benchmark::StatisticsMean(Inputs);
24     EXPECT_DOUBLE_EQ(Res, 7.0);
25   }
26 }
27 
TEST(StatisticsTest,Median)28 TEST(StatisticsTest, Median) {
29   std::vector<double> Inputs;
30   {
31     Inputs = {42, 42, 42, 42};
32     double Res = benchmark::StatisticsMedian(Inputs);
33     EXPECT_DOUBLE_EQ(Res, 42.0);
34   }
35   {
36     Inputs = {1, 2, 3, 4};
37     double Res = benchmark::StatisticsMedian(Inputs);
38     EXPECT_DOUBLE_EQ(Res, 2.5);
39   }
40   {
41     Inputs = {1, 2, 5, 10, 10};
42     double Res = benchmark::StatisticsMedian(Inputs);
43     EXPECT_DOUBLE_EQ(Res, 5.0);
44   }
45 }
46 
TEST(StatisticsTest,StdDev)47 TEST(StatisticsTest, StdDev) {
48   std::vector<double> Inputs;
49   {
50     Inputs = {101, 101, 101, 101};
51     double Res = benchmark::StatisticsStdDev(Inputs);
52     EXPECT_DOUBLE_EQ(Res, 0.0);
53   }
54   {
55     Inputs = {1, 2, 3};
56     double Res = benchmark::StatisticsStdDev(Inputs);
57     EXPECT_DOUBLE_EQ(Res, 1.0);
58   }
59 }
60 
61 }  // end namespace
62