Skip to content

Commit

Permalink
test: added test for intersecting eventpairs
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Aug 5, 2020
1 parent e83f3f8 commit 5f75f65
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion tests/test_transforms.py
@@ -1,4 +1,3 @@
import re
from pprint import pprint
from datetime import datetime, timedelta, timezone

Expand All @@ -20,6 +19,7 @@
tag,
Rule,
)
from aw_transform.filter_period_intersect import _intersecting_eventpairs


def test_simplify_string():
Expand Down Expand Up @@ -68,6 +68,46 @@ def test_filter_keyval_regex():
assert len(events_re) == 2


def test_intersecting_eventpairs():
td1h = timedelta(hours=1)
now = datetime.now()

# Test with two identical lists
e1 = [
Event(timestamp=now, duration=td1h),
Event(timestamp=now + td1h, duration=td1h),
]
e2 = [
Event(timestamp=now, duration=td1h),
Event(timestamp=now + td1h, duration=td1h),
]
intersecting = list(_intersecting_eventpairs(e1, e2))
assert len(intersecting) == 2

# Test with events in first list being in between events of second list
e1 = [
Event(timestamp=now + td1h, duration=td1h),
]
e2 = [
Event(timestamp=now, duration=td1h),
Event(timestamp=now + 2 * td1h, duration=td1h),
]
intersecting = list(_intersecting_eventpairs(e1, e2))
assert not intersecting

# Test with event in first list being identical to middle event in second list
e1 = [
Event(timestamp=now + td1h, duration=td1h),
]
e2 = [
Event(timestamp=now, duration=td1h),
Event(timestamp=now + 1 * td1h, duration=td1h),
Event(timestamp=now + 2 * td1h, duration=td1h),
]
intersecting = list(_intersecting_eventpairs(e1, e2))
assert len(intersecting) == 1


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

0 comments on commit 5f75f65

Please sign in to comment.