Skip to content

Commit

Permalink
add missing feature test; remove extra class field
Browse files Browse the repository at this point in the history
  • Loading branch information
ReDetection committed Nov 25, 2017
1 parent 35bcb93 commit 7fd90b7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 1 addition & 5 deletions bathroom_light/LightLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ LightLogic::LightLogic() {

void LightLogic::changeBrightness() {
isBright = !isBright;
lastBrightness = isBright;
}

void LightLogic::addMinutes(int minutes) {
Expand Down Expand Up @@ -39,13 +38,10 @@ void LightLogic::movementDetected() {
unsigned long now = millis();

if (minutesLeft == 0) {
if (wasEverTurnedOff && (now - lastTurnOff) < 5000) {
isBright = lastBrightness;
} else {
if (!wasEverTurnedOff || (now - lastTurnOff) >= 5000) {
isBright = hallBrightness() > 20;
}
}
minutesLeft = minutesLeft < triggerMinutes ? triggerMinutes : minutesLeft;
lastBrightness = isBright;
lastMinuteTick = now;
}
1 change: 0 additions & 1 deletion bathroom_light/LightLogic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class LightLogic {
unsigned long lastTurnOff;
unsigned long lastMinuteTick;
bool wasEverTurnedOff;
bool lastBrightness;
};

#endif /* defined(__bathroom_light__light_logic__) */
12 changes: 12 additions & 0 deletions tests/LigthLogic_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ TEST movementProlongsFor3Minutes() {
PASS();
}

TEST movementTurnsBackOnQuicklyAfterTurnOff() {
LightLogic logic = cleanWithState(true, 1);
millis = (60 + 1) * 1000;
logic.loop();
millis = (60 + 2) * 1000;
hallBrightness = 0;
logic.movementDetected();
ASSERT_EQ(logic.currentBrightness(), 255);
PASS();
}

TEST turnsOffAfter3Minutes() {
LightLogic logic = cleanLogic();
logic.movementDetected();
Expand Down Expand Up @@ -120,6 +131,7 @@ int main(int argc, char **argv) {
RUN_TEST(whenBrightInHallShouldTurnOnBright);
RUN_TEST(movementShouldNotAffectRunningBulb);
RUN_TEST(movementTurnsOnFor3Minutes);
RUN_TEST(movementTurnsBackOnQuicklyAfterTurnOff);
RUN_TEST(movementProlongsFor3Minutes);
RUN_TEST(movementDoesFairTimerReset);
RUN_TEST(turnsOffAfter3Minutes);
Expand Down

0 comments on commit 7fd90b7

Please sign in to comment.