15static void check(
bool ok,
const std::string& what) {
16 std::cout << (
ok ?
" ok " :
" FAIL ") << what << std::endl;
20static bool near(
double a,
double b) {
21 return std::fabs(
a -
b) < 1e-9;
28 "first reading passes through unsmoothed (not ramped from 0)");
29 check(
near(s.
step(1, 300.0), 300.0),
"a steady reading stays put");
30 check(
near(s.
step(1, 340.0), 310.0),
"then it smooths: 0.25*340 + 0.75*300 = 310");
32 check(
near(s.
step(2, 50.0), 50.0),
"each uid seeds independently");
33 check(
near(s.
step(1, 310.0), 310.0),
"another uid does not disturb this one");
35 const double nan = std::numeric_limits<double>::quiet_NaN();
36 check(std::isnan(s.
step(3, nan)),
"a non-finite reading is passed through");
38 "and the next finite one re-seeds instead of averaging NaN");
41 check(
near(s.
step(1, 0.0), 0.0),
"reset re-seeds from the next reading");
45 double min_seen = 1e9;
46 for (
int i = 0; i < 10; ++i)
47 min_seen = std::fmin(min_seen, cold.
step(42, 300.0));
48 check(
near(min_seen, 300.0),
"a 300 psi tank never reads below 300 psi from a cold start");
50 std::cout << (
g_failures ?
"FAILED" :
"PASSED") << std::endl;
double step(uint16_t uid, double value)
Feed one reading; returns the smoothed value.
*brief create JSON pointer *sa reference_tokens const string_t const string_t & b
*brief create JSON pointer *sa reference_tokens const string_t & a
static void check(bool ok, const std::string &what)
static bool near(double a, double b)