From 145d725b79a4e4df609b1fe2ef091b524bb549bd Mon Sep 17 00:00:00 2001
From: Mikael Henriksson <mike.zx@hotmail.com>
Date: Thu, 7 Sep 2023 17:21:31 +0200
Subject: [PATCH] resources.py: add contains method for ProcessCollection

---
 b_asic/resources.py    | 11 +++++++++++
 test/test_resources.py |  9 +++++++++
 2 files changed, 20 insertions(+)

diff --git a/b_asic/resources.py b/b_asic/resources.py
index fae30e87..b3f97bdb 100644
--- a/b_asic/resources.py
+++ b/b_asic/resources.py
@@ -502,6 +502,17 @@ class ProcessCollection:
         else:
             self.collection.remove(process)
 
+    def __contains__(self, process: Process) -> bool:
+        """
+        Test if a process is part of this ProcessCollection
+
+        Parameters
+        ----------
+        process : :class:`~b_asic.process.Process`
+            The process to test.
+        """
+        return process in self.collection
+
     def plot(
         self,
         ax: Optional[Axes] = None,
diff --git a/test/test_resources.py b/test/test_resources.py
index a0234878..59ba4959 100644
--- a/test/test_resources.py
+++ b/test/test_resources.py
@@ -38,6 +38,15 @@ class TestProcessCollectionPlainMemoryVariable:
         )
         assert len(collection_split) == 3
 
+    def test_contains(self):
+        collection = ProcessCollection([], schedule_time=10, cyclic=True)
+        m1 = PlainMemoryVariable(0, 0, {0: 3})
+        assert m1 not in collection
+        collection.add_process(m1)
+        assert m1 in collection
+        collection.remove_process(m1)
+        assert m1 not in collection
+
     def test_split_sequence_raises(self, simple_collection: ProcessCollection):
         with pytest.raises(KeyError, match="processes in `sequence` must be"):
             simple_collection.split_ports_sequentially(
-- 
GitLab