From 84847730864cfc2b236f996fea87af1a59631b28 Mon Sep 17 00:00:00 2001 From: Tom Schierenbeck Date: Thu, 12 Sep 2024 13:07:45 +0200 Subject: [PATCH] Quick fix of maps with different number of variables --- src/random_events/product_algebra.py | 2 ++ test/test_product_algebra.py | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/random_events/product_algebra.py b/src/random_events/product_algebra.py index a1bf70f..497781e 100644 --- a/src/random_events/product_algebra.py +++ b/src/random_events/product_algebra.py @@ -160,6 +160,8 @@ def __lt__(self, other: Self): if len(self.variables) < len(other.variables): return True for variable in self.variables: + if variable not in other: + return True if self[variable] == other[variable]: continue else: diff --git a/test/test_product_algebra.py b/test/test_product_algebra.py index 6644b91..4a0e97a 100644 --- a/test/test_product_algebra.py +++ b/test/test_product_algebra.py @@ -141,12 +141,18 @@ class OperationsWithEmptySetsTestCase(unittest.TestCase): y: Continuous = Continuous("y") a: Symbolic = Symbolic("a", TestEnum) - def test_union(self): + def test_empty_union(self): empty_event = SimpleEvent({self.x: SimpleInterval(0, 0), self.y: SimpleInterval(0, 0)}).as_composite_set() event = SimpleEvent({self.x: SimpleInterval(0, 1), self.y: SimpleInterval(0, 1)}).as_composite_set() union = empty_event.union_with(event) self.assertEqual(union, event) + 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)) if __name__ == '__main__': unittest.main()