From 478ec79e0039184fb8784b033a1dc04a74760412 Mon Sep 17 00:00:00 2001 From: Tom Schierenbeck Date: Fri, 20 Dec 2024 11:29:25 +0100 Subject: [PATCH] Fixed bug in difference --- src/random_events/__init__.py | 2 +- src/random_events/sigma_algebra.py | 3 +++ test/test_product_algebra.py | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/random_events/__init__.py b/src/random_events/__init__.py index f71b21a..dc0a25b 100644 --- a/src/random_events/__init__.py +++ b/src/random_events/__init__.py @@ -1 +1 @@ -__version__ = '3.1.2' +__version__ = '3.1.3' diff --git a/src/random_events/sigma_algebra.py b/src/random_events/sigma_algebra.py index 9461bc6..0ec3413 100644 --- a/src/random_events/sigma_algebra.py +++ b/src/random_events/sigma_algebra.py @@ -217,6 +217,9 @@ def difference_with_simple_set(self, other: AbstractSimpleSet) -> Self: def difference_with_simple_sets(self, other: SimpleSetContainer) -> Self: + if len(other) == 0: + return self + # initialize the result result = self.new_empty_set() diff --git a/test/test_product_algebra.py b/test/test_product_algebra.py index bec8995..ff7b681 100644 --- a/test/test_product_algebra.py +++ b/test/test_product_algebra.py @@ -172,8 +172,13 @@ def test_union_different_variables(self): event_1 = SimpleEvent({self.x: SimpleInterval(0, 1)}).as_composite_set() event_2 = SimpleEvent({self.y: SimpleInterval(0, 1)}).as_composite_set() union = event_1.union_with(event_2) - print(union) # self.assertEqual(union, Event(event_1, event_2)) + def test_difference_with_empty_set(self): + event = SimpleEvent({self.x: SimpleInterval(0, 1), self.y: SimpleInterval(0, 1)}).as_composite_set() + empty_event = Event() + diff = event.difference_with(empty_event) + self.assertEqual(diff, event) + if __name__ == '__main__': unittest.main()