Skip to content

Commit

Permalink
fix: fixed bug when passing unsorted lists into _intersecting_eventpa…
Browse files Browse the repository at this point in the history
…irs and added test for it
  • Loading branch information
ErikBjare committed Aug 5, 2020
1 parent 5f75f65 commit 216e9fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions aw_transform/filter_period_intersect.py
Expand Up @@ -25,6 +25,8 @@ def _intersecting_eventpairs(
events1: List[Event], events2: List[Event]
) -> Iterable[Tuple[Event, Event, TimePeriod]]:
"""A generator that yields each overlapping pair of events from two eventlists along with a TimePeriod of the intersection"""
events1.sort(key=lambda e: e.timestamp)
events2.sort(key=lambda e: e.timestamp)
e1_i = 0
e2_i = 0
while e1_i < len(events1) and e2_i < len(events2):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_transforms.py
Expand Up @@ -107,6 +107,12 @@ def test_intersecting_eventpairs():
intersecting = list(_intersecting_eventpairs(e1, e2))
assert len(intersecting) == 1

# Test same as before, but reversed
e1 = list(reversed(e1))
e2 = list(reversed(e2))
intersecting = list(_intersecting_eventpairs(e1, e2))
assert len(intersecting) == 1


def test_filter_period_intersect():
td1h = timedelta(hours=1)
Expand Down

0 comments on commit 216e9fc

Please sign in to comment.