Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: fixed tests for union_no_overlap
  • Loading branch information
ErikBjare committed Jun 8, 2021
1 parent d6f783d commit 9d8cb41
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 38 deletions.
38 changes: 0 additions & 38 deletions aw_transform/union_no_overlap.py
Expand Up @@ -82,41 +82,3 @@ def union_no_overlap(events1: List[Event], events2: List[Event]) -> List[Event]:
events_union += events1[e1_i:]
events_union += events2[e2_i:]
return events_union


def test_union_no_overlap():
from pprint import pprint

now = datetime(2018, 1, 1, 0, 0)
td1h = timedelta(hours=1)
events1 = [
Event(timestamp=now + 2 * i * td1h, duration=td1h, data={"test": 1})
for i in range(3)
]
events2 = [
Event(timestamp=now + (2 * i + 0.5) * td1h, duration=td1h, data={"test": 2})
for i in range(3)
]

events_union = _union_no_overlap(events1, events2)
# pprint(events_union)
dur = sum((e.duration for e in events_union), timedelta(0))
assert dur == timedelta(hours=4, minutes=30)
assert sorted(events_union, key=lambda e: e.timestamp)

events_union = _union_no_overlap(events2, events1)
# pprint(events_union)
dur = sum((e.duration for e in events_union), timedelta(0))
assert dur == timedelta(hours=4, minutes=30)
assert sorted(events_union, key=lambda e: e.timestamp)

events1 = [
Event(timestamp=now + (2 * i) * td1h, duration=td1h, data={"test": 1})
for i in range(3)
]
events2 = [Event(timestamp=now, duration=5 * td1h, data={"test": 2})]
events_union = _union_no_overlap(events1, events2)
pprint(events_union)
dur = sum((e.duration for e in events_union), timedelta(0))
assert dur == timedelta(hours=5, minutes=0)
assert sorted(events_union, key=lambda e: e.timestamp)
39 changes: 39 additions & 0 deletions tests/test_transforms.py
Expand Up @@ -15,6 +15,7 @@
split_url_events,
simplify_string,
union,
union_no_overlap,
categorize,
tag,
Rule,
Expand Down Expand Up @@ -410,3 +411,41 @@ def test_tags():

assert len(events[0].data["$tags"]) == 2
assert len(events[1].data["$tags"]) == 0


def test_union_no_overlap():
from pprint import pprint

now = datetime(2018, 1, 1, 0, 0)
td1h = timedelta(hours=1)
events1 = [
Event(timestamp=now + 2 * i * td1h, duration=td1h, data={"test": 1})
for i in range(3)
]
events2 = [
Event(timestamp=now + (2 * i + 0.5) * td1h, duration=td1h, data={"test": 2})
for i in range(3)
]

events_union = union_no_overlap(events1, events2)
# pprint(events_union)
dur = sum((e.duration for e in events_union), timedelta(0))
assert dur == timedelta(hours=4, minutes=30)
assert sorted(events_union, key=lambda e: e.timestamp)

events_union = union_no_overlap(events2, events1)
# pprint(events_union)
dur = sum((e.duration for e in events_union), timedelta(0))
assert dur == timedelta(hours=4, minutes=30)
assert sorted(events_union, key=lambda e: e.timestamp)

events1 = [
Event(timestamp=now + (2 * i) * td1h, duration=td1h, data={"test": 1})
for i in range(3)
]
events2 = [Event(timestamp=now, duration=5 * td1h, data={"test": 2})]
events_union = union_no_overlap(events1, events2)
pprint(events_union)
dur = sum((e.duration for e in events_union), timedelta(0))
assert dur == timedelta(hours=5, minutes=0)
assert sorted(events_union, key=lambda e: e.timestamp)

0 comments on commit 9d8cb41

Please sign in to comment.