Skip to content

Commit 34634eb

Browse files
some extra tests
1 parent 7c0ccc3 commit 34634eb

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

controller/tea_poor/test/test_native/tests/CommandProcessor_test.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
const auto VALID_POWER = "100";
77
const auto INVALID_TIME_ERROR_MESSAGE = "{ \"error\": \"invalid milliseconds value\" }";
8+
const auto INVALID_POWER_ERROR_MESSAGE = "{ \"error\": \"invalid power value\" }";
89
// test that pour_tea() method returns error message if milliseconds:
910
// - greater than threshold
1011
// - less than 0
@@ -18,6 +19,19 @@ TEST(CommandProcessor, pour_tea_invalid_milliseconds) {
1819
ASSERT_EQ(commandProcessor.pour_tea("abc", VALID_POWER), INVALID_TIME_ERROR_MESSAGE);
1920
}
2021

22+
// test that pour_tea() method returns error message if power:
23+
// - greater than 100
24+
// - less than 0
25+
// - empty string
26+
// - not a number
27+
TEST(CommandProcessor, pour_tea_invalid_power) {
28+
CommandProcessor commandProcessor(123, nullptr, nullptr);
29+
ASSERT_EQ(commandProcessor.pour_tea("123", "101"), INVALID_POWER_ERROR_MESSAGE);
30+
ASSERT_EQ(commandProcessor.pour_tea("123", "-1"), INVALID_POWER_ERROR_MESSAGE);
31+
ASSERT_EQ(commandProcessor.pour_tea("123", ""), INVALID_POWER_ERROR_MESSAGE);
32+
ASSERT_EQ(commandProcessor.pour_tea("123", "abc"), INVALID_POWER_ERROR_MESSAGE);
33+
}
34+
2135
// for simplicity of the UI, we should accept as valid 0 and exactly threshold value
2236
TEST(CommandProcessor, pour_tea_valid_boundary_values) {
2337
auto env = std::make_shared<FakeEnvironment>();
@@ -28,7 +42,7 @@ TEST(CommandProcessor, pour_tea_valid_boundary_values) {
2842
ASSERT_NE(commandProcessor.pour_tea("123", VALID_POWER), INVALID_TIME_ERROR_MESSAGE);
2943
}
3044

31-
// test that start pouring tea by calling pour_tea() method and its stops after T milliseconds
45+
// test that start pouring tea by calling pour_tea() method with specified parameters
3246
TEST(CommandProcessor, pour_tea) {
3347
auto env = std::make_shared<FakeEnvironment>();
3448
env->time(2343);

controller/tea_poor/test/test_native/tests/WaterPumpScheduler_test.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
TEST(WaterPumpScheduler, test_pump_stops_after_given_time) {
77
// random time between 1 and 10 seconds
88
const unsigned long runTimeMs = 1000 + (rand() % 10) * 1000;
9-
IWaterPumpPtr fakeWaterPump = std::make_shared<FakeWaterPump>();
9+
const auto fakeWaterPump = std::make_shared<FakeWaterPump>();
1010
WaterPumpScheduler waterPumpScheduler(fakeWaterPump);
1111
waterPumpScheduler.setup();
1212
// start water pump
1313
unsigned long currentTimeMs = 0;
1414
waterPumpScheduler.start(runTimeMs, 1, currentTimeMs);
15+
ASSERT_EQ(fakeWaterPump->powerInPercents(), 1);
1516
// check status
1617
auto status = waterPumpScheduler.status();
1718
ASSERT_TRUE(status.isRunning);
@@ -29,7 +30,7 @@ TEST(WaterPumpScheduler, test_pump_stops_after_given_time) {
2930

3031
// test that pump is periodically forced to stop after given time
3132
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>();
3334
WaterPumpScheduler waterPumpScheduler(fakeWaterPump, 1000); // force stop each 1 second
3435
waterPumpScheduler.setup();
3536
// start water pump
@@ -42,8 +43,19 @@ TEST(WaterPumpScheduler, test_pump_is_periodically_forced_to_stop_after_given_ti
4243
for(int i = 0; i < 10; i++) {
4344
// emulate that pump was started again
4445
fakeWaterPump->start(1);
46+
ASSERT_EQ(fakeWaterPump->powerInPercents(), 1);
4547
currentTimeMs += 1000;
4648
waterPumpScheduler.tick(currentTimeMs);
4749
ASSERT_FALSE(fakeWaterPump->isRunning()); // pump should be stopped
4850
}
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);
4961
}

0 commit comments

Comments
 (0)