statistics_gtest.cc
Go to the documentation of this file.
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 {
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 
15 TEST(StatisticsTest, Median) {
16  EXPECT_DOUBLE_EQ(benchmark::StatisticsMedian({42, 42, 42, 42}), 42.0);
18  EXPECT_DOUBLE_EQ(benchmark::StatisticsMedian({1, 2, 5, 10, 10}), 5.0);
19 }
20 
21 TEST(StatisticsTest, StdDev) {
22  EXPECT_DOUBLE_EQ(benchmark::StatisticsStdDev({101, 101, 101, 101}), 0.0);
24  EXPECT_DOUBLE_EQ(benchmark::StatisticsStdDev({2.5, 2.4, 3.3, 4.2, 5.1}),
25  1.151086443322134);
26 }
27 
28 TEST(StatisticsTest, CV) {
29  EXPECT_DOUBLE_EQ(benchmark::StatisticsCV({101, 101, 101, 101}), 0.0);
30  EXPECT_DOUBLE_EQ(benchmark::StatisticsCV({1, 2, 3}), 1. / 2.);
31  EXPECT_DOUBLE_EQ(benchmark::StatisticsCV({2.5, 2.4, 3.3, 4.2, 5.1}),
32  0.32888184094918121);
33 }
34 
35 } // end namespace
benchmark::StatisticsStdDev
double StatisticsStdDev(const std::vector< double > &v)
Definition: statistics.cc:66
TEST
#define TEST(name, init_size,...)
Definition: arena_test.cc:75
benchmark::StatisticsCV
double StatisticsCV(const std::vector< double > &v)
Definition: statistics.cc:77
EXPECT_DOUBLE_EQ
#define EXPECT_DOUBLE_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:28
benchmark::StatisticsMean
double StatisticsMean(const std::vector< double > &v)
Definition: statistics.cc:32
benchmark::StatisticsMedian
double StatisticsMedian(const std::vector< double > &v)
Definition: statistics.cc:37


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:17