Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Frenetz committed May 29, 2024
1 parent f06d423 commit 3931c1f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
26 changes: 13 additions & 13 deletions src/TimedDoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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();
}
14 changes: 7 additions & 7 deletions test/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

0 comments on commit 3931c1f

Please sign in to comment.