diff --git a/src/TimedDoor.cpp b/src/TimedDoor.cpp index e556917..21cb5f3 100644 --- a/src/TimedDoor.cpp +++ b/src/TimedDoor.cpp @@ -6,31 +6,31 @@ #include "TimedDoor.h" -DoorTimerAdapter::DoorTimerAdapter(TimedDoor & door_) : door(door_) {} +DoorTimerAdapter::DoorTimerAdapter(TimedDoor& door_) : door(door_) {} void DoorTimerAdapter::Timeout() { - if (door.isDoorOpened()) + if (door.isDoorOpened()) { throw std::runtime_error("Time's up!"); - return; + } } -TimedDoor::TimedDoor(int timeout_) : iTimeout(timeout_), isOpened(false) { - adapter = new DoorTimerAdapter(*this); -} +TimedDoor::TimedDoor(int timeout_) : iTimeout(timeout_), isOpened(false), adapter(new DoorTimerAdapter(*this)) {} bool TimedDoor::isDoorOpened() { return isOpened; } void TimedDoor::unlock() { - if (isOpened) + if (isOpened) { throw std::logic_error("Door is already opened"); + } isOpened = true; } void TimedDoor::lock() { - if (!isOpened) + if (!isOpened) { throw std::logic_error("Door is already closed"); + } isOpened = false; } @@ -42,12 +42,12 @@ void TimedDoor::throwState() { adapter->Timeout(); } -void Timer::sleep(int time_) { - std::this_thread::sleep_for(std::chrono::seconds(time_)); +void Timer::sleep(int duration) { + std::this_thread::sleep_for(std::chrono::seconds(duration)); } -void Timer::tregister(int time_, TimerClient* client_) { - this->client = client_; - sleep(time_); +void Timer::tregister(int duration, TimerClient* client_) { + client = client_; + sleep(duration); client_->Timeout(); } diff --git a/test/tests.cpp b/test/tests.cpp index fa4900b..3f918ec 100644 --- a/test/tests.cpp +++ b/test/tests.cpp @@ -62,20 +62,20 @@ TEST_F(TimedDoorTest, first_door_closed_test) { EXPECT_FALSE(door.isDoorOpened()); } -TEST_F(TimedDoorTest, unlock_door_twice_test) { - door.unlock(); - EXPECT_THROW(door.unlock(), std::logic_error); -} - TEST_F(TimedDoorTest, opened_exeption_test) { door.unlock(); EXPECT_THROW(door.throwState(), std::runtime_error); } -TEST_F(TimedDoorTest, close_before_test) { - EXPECT_NO_THROW(door.throwState()); +TEST_F(TimedDoorTest, unlock_door_twice_test) { + door.unlock(); + EXPECT_THROW(door.unlock(), std::logic_error); } TEST_F(TimedDoorTest, lock_door_twice_test) { EXPECT_THROW(door.lock(), std::logic_error); } + +TEST_F(TimedDoorTest, close_before_test) { + EXPECT_NO_THROW(door.throwState()); +}