[llvm-exegesis][NFC] Improve parsing of the YAML files
[llvm-core.git] / utils / benchmark / test / statistics_gtest.cc
blobb4d6abbb5780ea15ba8dec2ce4f8e32ea9917bc9
1 //===---------------------------------------------------------------------===//
2 // statistics_test - Unit tests for src/statistics.cc
3 //===---------------------------------------------------------------------===//
5 #include "../src/statistics.h"
6 #include "gtest/gtest.h"
8 namespace {
9 TEST(StatisticsTest, Mean) {
10 std::vector<double> Inputs;
12 Inputs = {42, 42, 42, 42};
13 double Res = benchmark::StatisticsMean(Inputs);
14 EXPECT_DOUBLE_EQ(Res, 42.0);
17 Inputs = {1, 2, 3, 4};
18 double Res = benchmark::StatisticsMean(Inputs);
19 EXPECT_DOUBLE_EQ(Res, 2.5);
22 Inputs = {1, 2, 5, 10, 10, 14};
23 double Res = benchmark::StatisticsMean(Inputs);
24 EXPECT_DOUBLE_EQ(Res, 7.0);
28 TEST(StatisticsTest, Median) {
29 std::vector<double> Inputs;
31 Inputs = {42, 42, 42, 42};
32 double Res = benchmark::StatisticsMedian(Inputs);
33 EXPECT_DOUBLE_EQ(Res, 42.0);
36 Inputs = {1, 2, 3, 4};
37 double Res = benchmark::StatisticsMedian(Inputs);
38 EXPECT_DOUBLE_EQ(Res, 2.5);
41 Inputs = {1, 2, 5, 10, 10};
42 double Res = benchmark::StatisticsMedian(Inputs);
43 EXPECT_DOUBLE_EQ(Res, 5.0);
47 TEST(StatisticsTest, StdDev) {
48 std::vector<double> Inputs;
50 Inputs = {101, 101, 101, 101};
51 double Res = benchmark::StatisticsStdDev(Inputs);
52 EXPECT_DOUBLE_EQ(Res, 0.0);
55 Inputs = {1, 2, 3};
56 double Res = benchmark::StatisticsStdDev(Inputs);
57 EXPECT_DOUBLE_EQ(Res, 1.0);
61 } // end namespace