statistics_gtest.cc 1.3 KB

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