Skip to content

Commit 20cc111

Browse files
fix upper threshold
1 parent 1627463 commit 20cc111

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

controller/tea_poor/lib/CommandProcessor/CommandProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ std::string CommandProcessor::status() {
4545
}
4646

4747
std::string CommandProcessor::pour_tea(const char *milliseconds) {
48-
if (!isValidIntNumber(milliseconds, _waterPumpSafeThreshold)) {
48+
if (!isValidIntNumber(milliseconds, _waterPumpSafeThreshold + 1)) {
4949
// send error message as JSON
5050
return std::string("{ \"error\": \"invalid milliseconds value\" }");
5151
}

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,28 @@
33
#include "mocks/FakeWaterPumpSchedulerAPI.h"
44
#include "mocks/FakeEnvironment.h"
55

6+
const auto INVALID_TIME_ERROR_MESSAGE = "{ \"error\": \"invalid milliseconds value\" }";
67
// test that pour_tea() method returns error message if milliseconds:
78
// - greater than threshold
89
// - less than 0
910
// - empty string
1011
// - not a number
1112
TEST(CommandProcessor, pour_tea_invalid_milliseconds) {
12-
const auto EXPECTED_ERROR_MESSAGE = "{ \"error\": \"invalid milliseconds value\" }";
1313
CommandProcessor commandProcessor(123, nullptr, nullptr);
14+
ASSERT_EQ(commandProcessor.pour_tea("1234"), INVALID_TIME_ERROR_MESSAGE);
15+
ASSERT_EQ(commandProcessor.pour_tea("-1"), INVALID_TIME_ERROR_MESSAGE);
16+
ASSERT_EQ(commandProcessor.pour_tea(""), INVALID_TIME_ERROR_MESSAGE);
17+
ASSERT_EQ(commandProcessor.pour_tea("abc"), INVALID_TIME_ERROR_MESSAGE);
18+
}
19+
20+
// for simplicity of the UI, we should accept as valid 0 and exactly threshold value
21+
TEST(CommandProcessor, pour_tea_valid_boundary_values) {
22+
auto env = std::make_shared<FakeEnvironment>();
23+
auto waterPump = std::make_shared<FakeWaterPumpSchedulerAPI>();
24+
CommandProcessor commandProcessor(123, env, waterPump);
1425

15-
// array of invalid parameters
16-
const char *PARAMS[] = { "1234", "-1", "", "abc" };
17-
for (auto param : PARAMS) {
18-
const auto response = commandProcessor.pour_tea(param);
19-
ASSERT_EQ(response, EXPECTED_ERROR_MESSAGE);
20-
}
26+
ASSERT_NE(commandProcessor.pour_tea("0"), INVALID_TIME_ERROR_MESSAGE);
27+
ASSERT_NE(commandProcessor.pour_tea("123"), INVALID_TIME_ERROR_MESSAGE);
2128
}
2229

2330
// test that start pouring tea by calling pour_tea() method and its stops after T milliseconds

0 commit comments

Comments
 (0)