Skip to content

Commit 5f75f65

Browse files
committed
test: added test for intersecting eventpairs
1 parent e83f3f8 commit 5f75f65

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

tests/test_transforms.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import re
21
from pprint import pprint
32
from datetime import datetime, timedelta, timezone
43

@@ -20,6 +19,7 @@
2019
tag,
2120
Rule,
2221
)
22+
from aw_transform.filter_period_intersect import _intersecting_eventpairs
2323

2424

2525
def test_simplify_string():
@@ -68,6 +68,46 @@ def test_filter_keyval_regex():
6868
assert len(events_re) == 2
6969

7070

71+
def test_intersecting_eventpairs():
72+
td1h = timedelta(hours=1)
73+
now = datetime.now()
74+
75+
# Test with two identical lists
76+
e1 = [
77+
Event(timestamp=now, duration=td1h),
78+
Event(timestamp=now + td1h, duration=td1h),
79+
]
80+
e2 = [
81+
Event(timestamp=now, duration=td1h),
82+
Event(timestamp=now + td1h, duration=td1h),
83+
]
84+
intersecting = list(_intersecting_eventpairs(e1, e2))
85+
assert len(intersecting) == 2
86+
87+
# Test with events in first list being in between events of second list
88+
e1 = [
89+
Event(timestamp=now + td1h, duration=td1h),
90+
]
91+
e2 = [
92+
Event(timestamp=now, duration=td1h),
93+
Event(timestamp=now + 2 * td1h, duration=td1h),
94+
]
95+
intersecting = list(_intersecting_eventpairs(e1, e2))
96+
assert not intersecting
97+
98+
# Test with event in first list being identical to middle event in second list
99+
e1 = [
100+
Event(timestamp=now + td1h, duration=td1h),
101+
]
102+
e2 = [
103+
Event(timestamp=now, duration=td1h),
104+
Event(timestamp=now + 1 * td1h, duration=td1h),
105+
Event(timestamp=now + 2 * td1h, duration=td1h),
106+
]
107+
intersecting = list(_intersecting_eventpairs(e1, e2))
108+
assert len(intersecting) == 1
109+
110+
71111
def test_filter_period_intersect():
72112
td1h = timedelta(hours=1)
73113
td30min = timedelta(minutes=30)

0 commit comments

Comments
 (0)