aboutsummaryrefslogtreecommitdiff
path: root/src/philo/event.py
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-10-01 11:49:53 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-10-01 11:49:53 +0200
commit1f18e740539aed751865ecff9d0f3cba44230e54 (patch)
treee23254751cc5a3be551233efb979a00571f40dc6 /src/philo/event.py
parent763f02a8b1e69c0e26a088824981d23ba1e5386d (diff)
downloadphilosophers_test-1f18e740539aed751865ecff9d0f3cba44230e54.tar.gz
philosophers_test-1f18e740539aed751865ecff9d0f3cba44230e54.tar.bz2
philosophers_test-1f18e740539aed751865ecff9d0f3cba44230e54.zip
Refactoring file structure, Added summary
Diffstat (limited to 'src/philo/event.py')
-rw-r--r--src/philo/event.py41
1 files changed, 41 insertions, 0 deletions
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 <me@cacharle.xyz> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# 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]