From 13229a211b876573a35678f912874cfaed7f16e2 Mon Sep 17 00:00:00 2001 From: Tom Schierenbeck Date: Tue, 16 Jul 2024 09:20:07 +0200 Subject: [PATCH] Fixed bug in make_disjoint --- src/random_events/__init__.py | 2 +- src/random_events/sigma_algebra.py | 2 +- test/test_product_algebra.py | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/random_events/__init__.py b/src/random_events/__init__.py index 51dce9e..f93b2a2 100644 --- a/src/random_events/__init__.py +++ b/src/random_events/__init__.py @@ -1 +1 @@ -__version__ = '3.0.5' +__version__ = '3.0.6' diff --git a/src/random_events/sigma_algebra.py b/src/random_events/sigma_algebra.py index f11dc57..45759c9 100644 --- a/src/random_events/sigma_algebra.py +++ b/src/random_events/sigma_algebra.py @@ -370,7 +370,7 @@ def split_into_disjoint_and_non_disjoint(self) -> Tuple[Self, Self]: if len(difference_with_intersection.simple_sets) == 0: # skip the rest of the loop and mark the set for discarding difference_of_a_with_every_b = None - continue + break # add the disjoint remainder difference_of_a_with_every_b = difference_with_intersection diff --git a/test/test_product_algebra.py b/test/test_product_algebra.py index d2a12d4..2c07327 100644 --- a/test/test_product_algebra.py +++ b/test/test_product_algebra.py @@ -115,5 +115,25 @@ def test_to_json_multiple_events(self): event_ = AbstractSimpleSet.from_json(event.to_json()) self.assertEqual(event_, event) + +class NoneTypeObjectInDifferenceTestCase(unittest.TestCase): + x: Continuous = Continuous("x") + y: Continuous = Continuous("y") + event_1 = Event(SimpleEvent({x: SimpleInterval(0, 0.25, Bound.CLOSED, Bound.CLOSED), + y: SimpleInterval(0.25, 1, Bound.CLOSED, Bound.CLOSED)}), + SimpleEvent({x: SimpleInterval(0.75, 1, Bound.CLOSED, Bound.CLOSED), + y: SimpleInterval(0.75, 1, Bound.CLOSED, Bound.CLOSED)})) + event_2 = SimpleEvent({x: SimpleInterval(0., 0.25, Bound.CLOSED, Bound.CLOSED), + y: SimpleInterval(0., 1, Bound.CLOSED, Bound.CLOSED)}).as_composite_set() + + def test_union(self): + union = self.event_1 | self.event_2 + union_by_hand = Event(SimpleEvent({self.x: SimpleInterval(0, 0.25, Bound.CLOSED, Bound.CLOSED), + self.y: SimpleInterval(0., 1, Bound.CLOSED, Bound.CLOSED)}), + SimpleEvent({self.x: SimpleInterval(0.75, 1, Bound.CLOSED, Bound.CLOSED), + self.y: SimpleInterval(0.75, 1, Bound.CLOSED, Bound.CLOSED)})) + self.assertEqual(union, union_by_hand) + + if __name__ == '__main__': unittest.main()