Skip to content

Commit

Permalink
fix upper threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
GreenWizard2015 committed Jan 13, 2024
1 parent 1627463 commit 20cc111
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ std::string CommandProcessor::status() {
}

std::string CommandProcessor::pour_tea(const char *milliseconds) {
if (!isValidIntNumber(milliseconds, _waterPumpSafeThreshold)) {
if (!isValidIntNumber(milliseconds, _waterPumpSafeThreshold + 1)) {
// send error message as JSON
return std::string("{ \"error\": \"invalid milliseconds value\" }");
}
Expand Down
21 changes: 14 additions & 7 deletions controller/tea_poor/test/test_native/tests/CommandProcessor_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
#include "mocks/FakeWaterPumpSchedulerAPI.h"
#include "mocks/FakeEnvironment.h"

const auto INVALID_TIME_ERROR_MESSAGE = "{ \"error\": \"invalid milliseconds value\" }";
// test that pour_tea() method returns error message if milliseconds:
// - greater than threshold
// - less than 0
// - empty string
// - not a number
TEST(CommandProcessor, pour_tea_invalid_milliseconds) {
const auto EXPECTED_ERROR_MESSAGE = "{ \"error\": \"invalid milliseconds value\" }";
CommandProcessor commandProcessor(123, nullptr, nullptr);
ASSERT_EQ(commandProcessor.pour_tea("1234"), INVALID_TIME_ERROR_MESSAGE);
ASSERT_EQ(commandProcessor.pour_tea("-1"), INVALID_TIME_ERROR_MESSAGE);
ASSERT_EQ(commandProcessor.pour_tea(""), INVALID_TIME_ERROR_MESSAGE);
ASSERT_EQ(commandProcessor.pour_tea("abc"), INVALID_TIME_ERROR_MESSAGE);
}

// for simplicity of the UI, we should accept as valid 0 and exactly threshold value
TEST(CommandProcessor, pour_tea_valid_boundary_values) {
auto env = std::make_shared<FakeEnvironment>();
auto waterPump = std::make_shared<FakeWaterPumpSchedulerAPI>();
CommandProcessor commandProcessor(123, env, waterPump);

// array of invalid parameters
const char *PARAMS[] = { "1234", "-1", "", "abc" };
for (auto param : PARAMS) {
const auto response = commandProcessor.pour_tea(param);
ASSERT_EQ(response, EXPECTED_ERROR_MESSAGE);
}
ASSERT_NE(commandProcessor.pour_tea("0"), INVALID_TIME_ERROR_MESSAGE);
ASSERT_NE(commandProcessor.pour_tea("123"), INVALID_TIME_ERROR_MESSAGE);
}

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

0 comments on commit 20cc111

Please sign in to comment.