diff --git a/README.md b/README.md index 47499c3..262ed59 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# Dining Philosophers Problem [![license](https://img.shields.io/github/license/herrera-diego/dining-philosophers)](./LICENSE) +# Dining Philosophers Problem [![license](https://img.shields.io/github/license/herrera-diego/dining-philosophers)](./LICENSE) [![Makefile CI](https://github.com/herrera-diego/dining-philosophers/actions/workflows/makefile.yml/badge.svg?branch=main)](https://github.com/herrera-diego/dining-philosophers/actions/workflows/makefile.yml) + Implementation on Dining Philosophers problem on C++ diff --git a/code/src/waiting-state/fork.cpp b/code/src/waiting-state/fork.cpp new file mode 100644 index 0000000..f725c60 --- /dev/null +++ b/code/src/waiting-state/fork.cpp @@ -0,0 +1,14 @@ +#include "fork.h" + +using namespace WaitingPhilosopher; + +Fork::Fork() +{ + +} + +bool Fork::isBeingUsed() +{ + return IsUsed; +} + diff --git a/code/src/waiting-state/fork.h b/code/src/waiting-state/fork.h new file mode 100644 index 0000000..d49f296 --- /dev/null +++ b/code/src/waiting-state/fork.h @@ -0,0 +1,26 @@ +#ifndef FORK_H_ +#define FORK_H_ + +// #ifdef __cplusplus +// extern "C" { +// #endif +#include + +namespace WaitingPhilosopher +{ + class Fork + { + public: + Fork(); + bool isBeingUsed(); + protected: + bool IsUsed = true; + + + + }; +} + +#endif /* FORK_H_ */ + +// EOF \ No newline at end of file diff --git a/code/src/waiting-state/philosopher.cpp b/code/src/waiting-state/philosopher.cpp index da2d0e0..3ac89c8 100644 --- a/code/src/waiting-state/philosopher.cpp +++ b/code/src/waiting-state/philosopher.cpp @@ -7,11 +7,8 @@ Philosopher::Philosopher() } -bool Philosopher::checkNeighbor() -{ - bool neighborBusy = true; - - return neighborBusy; +void Philosopher::think() +{ } void Philosopher::wait() diff --git a/code/src/waiting-state/philosopher.h b/code/src/waiting-state/philosopher.h index 0001545..a5b06b0 100644 --- a/code/src/waiting-state/philosopher.h +++ b/code/src/waiting-state/philosopher.h @@ -12,7 +12,7 @@ namespace WaitingPhilosopher { public: Philosopher(); - bool checkNeighbor(); + void think(); void wait(); void eat(); protected: diff --git a/code/unittest/test-waiting-state.cpp b/code/unittest/test-waiting-state.cpp index b65cfac..6aec5e6 100644 --- a/code/unittest/test-waiting-state.cpp +++ b/code/unittest/test-waiting-state.cpp @@ -1,6 +1,7 @@ #include "gtest/gtest.h" #include #include "waiting-state/philosopher.h" +#include "waiting-state/fork.h" using namespace WaitingPhilosopher; using namespace std; @@ -32,8 +33,10 @@ class WaitingPhilosopherTest : public testing::Test TEST_F(WaitingPhilosopherTest, evenPhilosophers) { - Philosopher nietzche; - ASSERT_TRUE(nietzche.checkNeighbor()); + int numPh = 6; + Philosopher phs[numPh]; + Fork forks[numPh*2 -1]; + ASSERT_TRUE(forks[0].isBeingUsed()); }