add function to query whether ErrorStats class has data

This commit is contained in:
Axel Kohlmeyer 2020-08-09 01:01:35 -04:00
parent 2edad432ce
commit e94d1c5537
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
2 changed files with 3 additions and 0 deletions

View File

@ -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;

View File

@ -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);