From e94d1c5537bb868f49d6d9f33eb51d754788c737 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 9 Aug 2020 01:01:35 -0400 Subject: [PATCH] add function to query whether ErrorStats class has data --- unittest/force-styles/error_stats.h | 1 + unittest/force-styles/test_error_stats.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/unittest/force-styles/error_stats.h b/unittest/force-styles/error_stats.h index 664a987907..b9c44e4027 100644 --- a/unittest/force-styles/error_stats.h +++ b/unittest/force-styles/error_stats.h @@ -29,6 +29,7 @@ public: double dev() const; double max() const { return maxerr; } double idx() const { return maxidx; } + bool has_data() const { return num > 0; } private: double sum, sumsq, maxerr; diff --git a/unittest/force-styles/test_error_stats.cpp b/unittest/force-styles/test_error_stats.cpp index 42c185db83..0873757acd 100644 --- a/unittest/force-styles/test_error_stats.cpp +++ b/unittest/force-styles/test_error_stats.cpp @@ -29,12 +29,14 @@ TEST(ErrorStats, test) ASSERT_EQ(out.str(), "Average: 5.800e-01 StdDev: 7.305e-01 MaxErr: 2.000e+00 @ item: 3.0"); stats.reset(); + ASSERT_EQ(stats.has_data(), false); ASSERT_DOUBLE_EQ(stats.avg(), 0.0); ASSERT_DOUBLE_EQ(stats.dev(), 0.0); ASSERT_DOUBLE_EQ(stats.max(), 0.0); ASSERT_EQ(stats.idx(), -1); stats.add(1.0); + ASSERT_EQ(stats.has_data(), true); ASSERT_DOUBLE_EQ(stats.avg(), 1.0); ASSERT_DOUBLE_EQ(stats.dev(), 0.0); ASSERT_DOUBLE_EQ(stats.max(), 1.0);