Skip to content

Commit

Permalink
Fixed bug of empty intersections.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsch420 committed Mar 15, 2024
1 parent 4d6a9ef commit ffec3a4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/random_events/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.0.1'
__version__ = '2.0.2'
3 changes: 0 additions & 3 deletions src/random_events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,10 @@ def intersection(self, other: EventType) -> EventType:
result = self.__class__()

variables = set(self.keys()) | set(other.keys())

for variable in variables:
assignment1 = self.get(variable, variable.domain)
assignment2 = other.get(variable, variable.domain)
intersection = variable.intersection_of_assignments(assignment1, assignment2)
if len(intersection) == 0:
return self.__class__()
result[variable] = intersection

return result
Expand Down
7 changes: 7 additions & 0 deletions test/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ def test_set_operations_return_type(self):
self.assertEqual(type(event | event), ComplexEvent)
self.assertEqual(type(event - event), ComplexEvent)

def test_intersection_with_empty(self):
event = Event({self.integer: ()})
complete_event = Event({self.integer: self.integer.domain})
intersection = event.intersection(complete_event)
self.assertIn(self.integer, intersection.keys())
self.assertTrue(intersection.is_empty())


class ComplexEventTestCase(unittest.TestCase):

Expand Down
1 change: 1 addition & 0 deletions test/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,6 @@ def test_complement_of_assignment(self):
self.assertEqual(self.symbol.complement_of_assignment(("a",)), ("b", "c", ))



if __name__ == '__main__':
unittest.main()

0 comments on commit ffec3a4

Please sign in to comment.