|
1 |
| -import re |
2 | 1 | from pprint import pprint
|
3 | 2 | from datetime import datetime, timedelta, timezone
|
4 | 3 |
|
|
20 | 19 | tag,
|
21 | 20 | Rule,
|
22 | 21 | )
|
| 22 | +from aw_transform.filter_period_intersect import _intersecting_eventpairs |
23 | 23 |
|
24 | 24 |
|
25 | 25 | def test_simplify_string():
|
@@ -68,6 +68,46 @@ def test_filter_keyval_regex():
|
68 | 68 | assert len(events_re) == 2
|
69 | 69 |
|
70 | 70 |
|
| 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 | + |
71 | 111 | def test_filter_period_intersect():
|
72 | 112 | td1h = timedelta(hours=1)
|
73 | 113 | td30min = timedelta(minutes=30)
|
|
0 commit comments