6
6
TEST (WaterPumpScheduler, test_pump_stops_after_given_time) {
7
7
// random time between 1 and 10 seconds
8
8
const unsigned long runTimeMs = 1000 + (rand () % 10 ) * 1000 ;
9
- IWaterPumpPtr fakeWaterPump = std::make_shared<FakeWaterPump>();
9
+ const auto fakeWaterPump = std::make_shared<FakeWaterPump>();
10
10
WaterPumpScheduler waterPumpScheduler (fakeWaterPump);
11
11
waterPumpScheduler.setup ();
12
12
// start water pump
13
13
unsigned long currentTimeMs = 0 ;
14
14
waterPumpScheduler.start (runTimeMs, 1 , currentTimeMs);
15
+ ASSERT_EQ (fakeWaterPump->powerInPercents (), 1 );
15
16
// check status
16
17
auto status = waterPumpScheduler.status ();
17
18
ASSERT_TRUE (status.isRunning );
@@ -29,7 +30,7 @@ TEST(WaterPumpScheduler, test_pump_stops_after_given_time) {
29
30
30
31
// test that pump is periodically forced to stop after given time
31
32
TEST (WaterPumpScheduler, test_pump_is_periodically_forced_to_stop_after_given_time) {
32
- IWaterPumpPtr fakeWaterPump = std::make_shared<FakeWaterPump>();
33
+ const auto fakeWaterPump = std::make_shared<FakeWaterPump>();
33
34
WaterPumpScheduler waterPumpScheduler (fakeWaterPump, 1000 ); // force stop each 1 second
34
35
waterPumpScheduler.setup ();
35
36
// start water pump
@@ -42,8 +43,19 @@ TEST(WaterPumpScheduler, test_pump_is_periodically_forced_to_stop_after_given_ti
42
43
for (int i = 0 ; i < 10 ; i++) {
43
44
// emulate that pump was started again
44
45
fakeWaterPump->start (1 );
46
+ ASSERT_EQ (fakeWaterPump->powerInPercents (), 1 );
45
47
currentTimeMs += 1000 ;
46
48
waterPumpScheduler.tick (currentTimeMs);
47
49
ASSERT_FALSE (fakeWaterPump->isRunning ()); // pump should be stopped
48
50
}
51
+ }
52
+
53
+ // test that pumps power is set to specified value
54
+ TEST (WaterPumpScheduler, test_pumps_power_is_set_to_specified_value) {
55
+ const auto fakeWaterPump = std::make_shared<FakeWaterPump>();
56
+ WaterPumpScheduler waterPumpScheduler (fakeWaterPump);
57
+ waterPumpScheduler.setup ();
58
+ const int power = 23 ;
59
+ waterPumpScheduler.start (1 , power, 0 );
60
+ ASSERT_EQ (fakeWaterPump->powerInPercents (), power);
49
61
}
0 commit comments