88td1s = timedelta (seconds = 1 )
99
1010
11- def test_flood_forward ():
11+ def test_flood_differing_data_meet_at_gap_midpoint ():
1212 events = [
1313 Event (timestamp = now , duration = 10 , data = {"a" : 0 }),
14- Event (timestamp = now + 15 * td1s , duration = 5 , data = {"b" : 1 }),
14+ Event (timestamp = now + 14 * td1s , duration = 5 , data = {"b" : 1 }),
1515 ]
16+
1617 flooded = flood (events )
17- assert (flooded [0 ].timestamp + flooded [0 ].duration ) - flooded [
18- 1
19- ].timestamp == timedelta (0 )
18+
19+ assert flooded == [
20+ Event (timestamp = now , duration = 12 , data = {"a" : 0 }),
21+ Event (timestamp = now + 12 * td1s , duration = 7 , data = {"b" : 1 }),
22+ ]
2023
2124
2225def test_flood_forward_merge ():
@@ -29,17 +32,6 @@ def test_flood_forward_merge():
2932 assert flooded [0 ].duration == timedelta (seconds = 20 )
3033
3134
32- def test_flood_backward ():
33- events = [
34- Event (timestamp = now , duration = 5 , data = {"a" : 0 }),
35- Event (timestamp = now + 10 * td1s , duration = 10 , data = {"b" : 1 }),
36- ]
37- flooded = flood (events )
38- assert (flooded [0 ].timestamp + flooded [0 ].duration ) - flooded [
39- 1
40- ].timestamp == timedelta (0 )
41-
42-
4335def test_flood_backward_merge ():
4436 events = [
4537 Event (timestamp = now , duration = 5 ),
@@ -97,8 +89,8 @@ def test_flood_normalization_preserves_non_overlapping_tail():
9789
9890 assert flooded == [
9991 Event (timestamp = now , duration = 5 , data = {"title" : "first" }),
100- Event (timestamp = now + 5 * td1s , duration = 7 , data = {"title" : "second" }),
101- events [ 2 ] ,
92+ Event (timestamp = now + 5 * td1s , duration = 4.5 , data = {"title" : "second" }),
93+ Event ( timestamp = now + 9.5 * td1s , duration = 3.5 , data = { "title" : "third" }) ,
10294 ]
10395
10496
@@ -137,11 +129,12 @@ def test_flood_with_custom_pulsetime():
137129 total_duration_default = sum ((e .duration for e in flooded_default ), timedelta (0 ))
138130 assert total_duration_default == timedelta (seconds = 10 )
139131
140- # pulsetime=31: gap (30s) <= pulsetime, so event 1 extends to meet event 2
132+ # pulsetime=31: gap (30s) <= pulsetime, so both events extend to midpoint
141133 flooded_custom = flood (events , pulsetime = 31 )
142- assert len (flooded_custom ) == 2
143- total_duration_custom = sum ((e .duration for e in flooded_custom ), timedelta (0 ))
144- assert total_duration_custom == timedelta (seconds = 40 )
134+ assert flooded_custom == [
135+ Event (timestamp = now , duration = 20 , data = {"a" : 0 }),
136+ Event (timestamp = now + 20 * td1s , duration = 20 , data = {"b" : 1 }),
137+ ]
145138
146139
147140def test_flood_idempotent ():
0 commit comments