Skip to content

Commit

Permalink
✅ (rc): Fix startChargingBehavior tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli committed Mar 16, 2022
1 parent d2cc608 commit 303ede8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 16 deletions.
33 changes: 18 additions & 15 deletions libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,26 @@ class RobotController : public interface::RobotController

auto isCharging() -> bool final { return _battery.isCharging(); };

void onStartChargingBehavior(uint8_t level)
{
_service_battery.setBatteryLevel(level);

if (level < 25) {
_video_kit.displayImage("/fs/images/battery_0.jpg");
} else if (level < 50) {
_video_kit.displayImage("/fs/images/battery_red.jpg");
} else if (level < 75) {
_video_kit.displayImage("/fs/images/battery_yellow_2.jpg");
} else if (level < 100) {
_video_kit.displayImage("/fs/images/battery_green_3.jpg");
} else {
_video_kit.displayImage("/fs/images/battery_green_4.jpg");
}
}

void startChargingBehavior() final
{
_battery_kit.onDataUpdated([this](uint8_t level) {
_service_battery.setBatteryLevel(level);

if (level < 25) {
_video_kit.displayImage("/fs/images/battery_0.jpg");
} else if (level < 50) {
_video_kit.displayImage("/fs/images/battery_red.jpg");
} else if (level < 75) {
_video_kit.displayImage("/fs/images/battery_yellow_2.jpg");
} else if (level < 100) {
_video_kit.displayImage("/fs/images/battery_green_3.jpg");
} else {
_video_kit.displayImage("/fs/images/battery_green_4.jpg");
}
});
_battery_kit.onDataUpdated([this](uint8_t level) { onStartChargingBehavior(level); });
}
void stopChargingBehavior() final
{
Expand Down
47 changes: 46 additions & 1 deletion libs/RobotKit/tests/RobotController_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class RobotControllerTest : public testing::Test
rc.initializeComponents();

EXPECT_CALL(battery, level).Times(1);
EXPECT_CALL(mbed_mock_gatt, write(_, _, _, _)).Times(1);
EXPECT_CALL(mbed_mock_gatt, write(_, _, _, _)).Times(AnyNumber());
EXPECT_CALL(sleep_timeout, onTimeout).WillOnce(GetCallback<interface::Timeout::callback_t>(&on_sleep_timeout));
EXPECT_CALL(battery, onChargeDidStart).WillOnce(GetCallback<mbed::Callback<void()>>(&on_charge_did_start));
EXPECT_CALL(battery, onChargeDidStop).WillOnce(GetCallback<mbed::Callback<void()>>(&on_charge_did_stop));
Expand Down Expand Up @@ -94,6 +94,51 @@ TEST_F(RobotControllerTest, initializeComponents)
rc.initializeComponents();
}

TEST_F(RobotControllerTest, onStartChargingBehaviorLevelBelow25)
{
auto battery_level = 0;

rc.onStartChargingBehavior(battery_level);

// nohting expected
}

TEST_F(RobotControllerTest, onStartChargingBehaviorLevelAbove25Below50)
{
auto battery_level = 42;

rc.onStartChargingBehavior(battery_level);

// nohting expected
}

TEST_F(RobotControllerTest, onStartChargingBehaviorLevelAbove50Below75)
{
auto battery_level = 66;

rc.onStartChargingBehavior(battery_level);

// nohting expected
}

TEST_F(RobotControllerTest, onStartChargingBehaviorLevelAbove75Below100)
{
auto battery_level = 90;

rc.onStartChargingBehavior(battery_level);

// nohting expected
}

TEST_F(RobotControllerTest, onStartChargingBehaviorLevelAt100)
{
auto battery_level = 100;

rc.onStartChargingBehavior(battery_level);

// nohting expected
}

TEST_F(RobotControllerTest, stateSetupEventSetupComplete)
{
ble::GapMock &mbed_mock_gap = ble::gap_mock();
Expand Down

0 comments on commit 303ede8

Please sign in to comment.