cleaner and slightly larger statistics tests (#604)

This commit is contained in:
Dominic Hamon 2018-05-29 13:13:06 +01:00 committed by GitHub
parent c8adf4531f
commit 16703ff83c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 43 deletions

View File

@ -7,55 +7,22 @@
namespace {
TEST(StatisticsTest, Mean) {
std::vector<double> Inputs;
{
Inputs = {42, 42, 42, 42};
double Res = benchmark::StatisticsMean(Inputs);
EXPECT_DOUBLE_EQ(Res, 42.0);
}
{
Inputs = {1, 2, 3, 4};
double Res = benchmark::StatisticsMean(Inputs);
EXPECT_DOUBLE_EQ(Res, 2.5);
}
{
Inputs = {1, 2, 5, 10, 10, 14};
double Res = benchmark::StatisticsMean(Inputs);
EXPECT_DOUBLE_EQ(Res, 7.0);
}
EXPECT_DOUBLE_EQ(benchmark::StatisticsMean({42,42,42,42}), 42.0);
EXPECT_DOUBLE_EQ(benchmark::StatisticsMean({1,2,3,4}), 2.5);
EXPECT_DOUBLE_EQ(benchmark::StatisticsMean({1, 2, 5, 10, 10, 14}), 7.0);
}
TEST(StatisticsTest, Median) {
std::vector<double> Inputs;
{
Inputs = {42, 42, 42, 42};
double Res = benchmark::StatisticsMedian(Inputs);
EXPECT_DOUBLE_EQ(Res, 42.0);
}
{
Inputs = {1, 2, 3, 4};
double Res = benchmark::StatisticsMedian(Inputs);
EXPECT_DOUBLE_EQ(Res, 2.5);
}
{
Inputs = {1, 2, 5, 10, 10};
double Res = benchmark::StatisticsMedian(Inputs);
EXPECT_DOUBLE_EQ(Res, 5.0);
}
EXPECT_DOUBLE_EQ(benchmark::StatisticsMedian({42,42,42,42}), 42.0);
EXPECT_DOUBLE_EQ(benchmark::StatisticsMedian({1,2,3,4}), 2.5);
EXPECT_DOUBLE_EQ(benchmark::StatisticsMedian({1, 2, 5, 10, 10}), 5.0);
}
TEST(StatisticsTest, StdDev) {
std::vector<double> Inputs;
{
Inputs = {101, 101, 101, 101};
double Res = benchmark::StatisticsStdDev(Inputs);
EXPECT_DOUBLE_EQ(Res, 0.0);
}
{
Inputs = {1, 2, 3};
double Res = benchmark::StatisticsStdDev(Inputs);
EXPECT_DOUBLE_EQ(Res, 1.0);
}
EXPECT_DOUBLE_EQ(benchmark::StatisticsStdDev({101, 101, 101, 101}), 0.0);
EXPECT_DOUBLE_EQ(benchmark::StatisticsStdDev({1,2,3}), 1.0);
EXPECT_FLOAT_EQ(benchmark::StatisticsStdDev({1.5, 2.4, 3.3, 4.2, 5.1}),
1.42302495);
}
} // end namespace