diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-09-27 17:53:53 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-09-27 17:53:53 +0200 |
| commit | 51857521f770caae7b36e3a36a30d5b6986e66d1 (patch) | |
| tree | 8b56e84794c6a3be67db33bc3d9cea435e2a2b2c /src/philo/philo.py | |
| parent | 20e0b28ec3c8e9e0a63759116a32438c18941a59 (diff) | |
| download | philosophers_test-51857521f770caae7b36e3a36a30d5b6986e66d1.tar.gz philosophers_test-51857521f770caae7b36e3a36a30d5b6986e66d1.tar.bz2 philosophers_test-51857521f770caae7b36e3a36a30d5b6986e66d1.zip | |
Added should be dead check, Moved philo classes in src/test/philo.py
Diffstat (limited to 'src/philo/philo.py')
| -rw-r--r-- | src/philo/philo.py | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/src/philo/philo.py b/src/philo/philo.py deleted file mode 100644 index e7e2e1d..0000000 --- a/src/philo/philo.py +++ /dev/null @@ -1,50 +0,0 @@ -# ############################################################################ # -# # -# ::: :::::::: # -# philo.py :+: :+: :+: # -# +:+ +:+ +:+ # -# By: charles <me@cacharle.xyz> +#+ +:+ +#+ # -# +#+#+#+#+#+ +#+ # -# Created: 2020/09/27 12:54:12 by charles #+# #+# # -# Updated: 2020/09/27 16:50:22 by charles ### ########.fr # -# # -# ############################################################################ # - -import itertools -from philo.event import Event - -class Philo: - def __init__(self, id_: int, meal_num: int = 1): - self._logs = [] - self.id = id_ - self.meal_num = meal_num - - def add_log(self, log): - self._logs.append(log) - - def check(self): - grouped = [(e, list(g)) for e, g in itertools.groupby(self._logs, (lambda x: x.event))] - for e, g in grouped: - if e is Event.EATING: - if len(g) != self.meal_num: - raise RuntimeError("lala") - else: - if len(g) != 1: - raise RuntimeError("1lala") - - events = [e for e, _ in grouped] - for e1, e2 in zip(events, events[1:]): - if e2 is Event.DIED: - break - if e1 is Event.THINKING and e2 is not Event.EATING: - raise RuntimeError("2lala") - elif e1 is Event.EATING and e2 is not Event.SLEEPING: - raise RuntimeError("2lala") - elif e1 is Event.SLEEPING and e2 is not Event.EATING: - raise RuntimeError("2lala") - - @property - def last_event(self): - if len(self._logs) == 0: - return Event.NONE - return self._logs[-1].event |
