From 7fd90b76b7cb5e0948bf09e767c437f336eff931 Mon Sep 17 00:00:00 2001 From: ReDetection Date: Sat, 25 Nov 2017 16:00:18 +0700 Subject: [PATCH] add missing feature test; remove extra class field --- bathroom_light/LightLogic.cpp | 6 +----- bathroom_light/LightLogic.hpp | 1 - tests/LigthLogic_tests.cpp | 12 ++++++++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bathroom_light/LightLogic.cpp b/bathroom_light/LightLogic.cpp index 7f4cb6f..76a3d03 100644 --- a/bathroom_light/LightLogic.cpp +++ b/bathroom_light/LightLogic.cpp @@ -7,7 +7,6 @@ LightLogic::LightLogic() { void LightLogic::changeBrightness() { isBright = !isBright; - lastBrightness = isBright; } void LightLogic::addMinutes(int minutes) { @@ -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; } diff --git a/bathroom_light/LightLogic.hpp b/bathroom_light/LightLogic.hpp index f681eb5..1f6814f 100644 --- a/bathroom_light/LightLogic.hpp +++ b/bathroom_light/LightLogic.hpp @@ -23,7 +23,6 @@ class LightLogic { unsigned long lastTurnOff; unsigned long lastMinuteTick; bool wasEverTurnedOff; - bool lastBrightness; }; #endif /* defined(__bathroom_light__light_logic__) */ diff --git a/tests/LigthLogic_tests.cpp b/tests/LigthLogic_tests.cpp index 74840f2..febd83f 100644 --- a/tests/LigthLogic_tests.cpp +++ b/tests/LigthLogic_tests.cpp @@ -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(); @@ -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);