From 1f18e740539aed751865ecff9d0f3cba44230e54 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 1 Oct 2020 11:49:53 +0200 Subject: Refactoring file structure, Added summary --- src/philo/event.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/philo/event.py (limited to 'src/philo/event.py') diff --git a/src/philo/event.py b/src/philo/event.py new file mode 100644 index 0000000..ddcbe59 --- /dev/null +++ b/src/philo/event.py @@ -0,0 +1,41 @@ +# ############################################################################ # +# # +# ::: :::::::: # +# event.py :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2020/10/01 10:51:13 by cacharle #+# #+# # +# Updated: 2020/10/01 11:21:00 by cacharle ### ########.fr # +# # +# ############################################################################ # + +import enum + +class Event(enum.Enum): + FORK = 1 + EAT = 2 + SLEEP = 3 + THINK = 4 + DIE = 5 + NONE = 6 + + @staticmethod + def from_string(representation: str) -> "Event": + return { + "has taken fork": Event.FORK, + "is thinking": Event.THINK, + "is eating": Event.EAT, + "is sleeping": Event.SLEEP, + "died": Event.DIE, + }[representation] + + @staticmethod + def to_string(event: "Event") -> str: + return { + Event.FORK: "has taken fork", + Event.THINK: "is thinking", + Event.EAT: "is eating", + Event.SLEEP: "is sleeping", + Event.DIE: "died" + }[event] -- cgit