Skip to content

Commit

Permalink
Quick fix of maps with different number of variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsch420 committed Sep 12, 2024
1 parent 03b2a5b commit 8484773
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/random_events/product_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion test/test_product_algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 8484773

Please sign in to comment.