2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
2019-09-21 11:33:38 -07:00
|
|
|
|
2021-08-03 19:05:01 -07:00
|
|
|
#include "functional_sensor.h"
|
2019-09-21 11:33:38 -07:00
|
|
|
|
2019-09-24 18:11:41 -07:00
|
|
|
struct DoublerFunc final : public SensorConverter {
|
|
|
|
SensorResult convert(float input) const {
|
2020-04-19 05:37:43 -07:00
|
|
|
if (input <= 0) {
|
|
|
|
return unexpected;
|
|
|
|
}
|
2019-09-24 18:11:41 -07:00
|
|
|
|
2020-04-19 05:37:43 -07:00
|
|
|
return input * 2;
|
2019-09-24 18:11:41 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-21 11:33:38 -07:00
|
|
|
class SensorConverted : public ::testing::Test {
|
|
|
|
protected:
|
2019-09-24 18:11:41 -07:00
|
|
|
SensorConverted()
|
2020-01-12 00:25:23 -08:00
|
|
|
: dut(SensorType::Clt, MS2NT(50)) {}
|
2019-09-24 18:11:41 -07:00
|
|
|
|
2019-09-21 11:33:38 -07:00
|
|
|
void SetUp() override {
|
2019-09-25 04:26:56 -07:00
|
|
|
dut.setFunction(func);
|
2019-09-21 11:33:38 -07:00
|
|
|
Sensor::resetRegistry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
Sensor::resetRegistry();
|
|
|
|
}
|
|
|
|
|
2019-09-25 04:26:56 -07:00
|
|
|
FunctionalSensor dut;
|
|
|
|
DoublerFunc func;
|
2019-09-21 11:33:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(SensorConverted, TestValid) {
|
|
|
|
ASSERT_TRUE(dut.Register());
|
|
|
|
|
|
|
|
// Should be invalid - not set yet
|
|
|
|
{
|
|
|
|
auto s = Sensor::get(SensorType::Clt);
|
|
|
|
EXPECT_FALSE(s.Valid);
|
|
|
|
}
|
|
|
|
|
2020-07-19 15:05:31 -07:00
|
|
|
dut.postRawValue(25, getTimeNowNt());
|
2019-09-21 11:33:38 -07:00
|
|
|
|
|
|
|
// Should be valid, with a value of 25*2 = 50
|
|
|
|
{
|
|
|
|
auto s = Sensor::get(SensorType::Clt);
|
|
|
|
EXPECT_TRUE(s.Valid);
|
|
|
|
EXPECT_FLOAT_EQ(s.Value, 50);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(SensorConverted, TestInvalid) {
|
|
|
|
ASSERT_TRUE(dut.Register());
|
|
|
|
|
|
|
|
// Should be invalid - not set yet
|
|
|
|
{
|
|
|
|
auto s = Sensor::get(SensorType::Clt);
|
|
|
|
EXPECT_FALSE(s.Valid);
|
|
|
|
}
|
|
|
|
|
2020-01-12 00:25:23 -08:00
|
|
|
dut.postRawValue(-25, 0);
|
2019-09-21 11:33:38 -07:00
|
|
|
|
|
|
|
// Should be invalid, with a value of -25*2 = 0
|
|
|
|
{
|
|
|
|
auto s = Sensor::get(SensorType::Clt);
|
|
|
|
EXPECT_FALSE(s.Valid);
|
|
|
|
}
|
|
|
|
}
|