forked from lijiext/lammps
add function to query whether ErrorStats class has data
This commit is contained in:
parent
2edad432ce
commit
e94d1c5537
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue