Exercise: MockSensor_nopoly
(Non-Polymorphic)¶
Requirement¶
Implement a sensor class MockSensor_nopoly
which does not access
any real hardware to measure temperature. Rather, it has a method
set_temperature()
which can be used (by unit tests, ideally) to
control the value that is returned by subsequent calls to
get_temperature()
.
Use the following test to guide you through the implementation:
#include <gtest/gtest.h>
#include <sensor-mock-nopoly.h>
TEST(sensor_mock_nopoly_suite, basic)
{
MockSensor_nopoly ms(/*initial temperature:*/36.4);
ASSERT_FLOAT_EQ(ms.get_temperature(), 36.4);
ms.set_temperature(42.8);
ASSERT_FLOAT_EQ(ms.get_temperature(), 42.8);
}