-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_apply_lr.py
79 lines (76 loc) · 2.16 KB
/
test_apply_lr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pytest
from transportation_splitter import *
@pytest.mark.parametrize(
"case_label, original_length_meters, original_lr, split_lr, expected_is_applicable, expected_new_lr",
[
(
"lr bigger than split", # case "label" to identify it more easily when fails
1000, # original segment length (meters)
[0, 0.8], # original lr (relative)
[0, 0.5], # split lr (relative)
True, # expected is_applicable
None, # expected new lr (relative)
),
("lr outside than split", 1000, [0.7, 0.8], [0, 0.5], False, None),
(
"lr inside split",
1000,
[0.1, 0.4],
[0, 0.5],
True,
[0.2, 0.8],
),
(
"lr inside split with snap",
1000,
[0, 0.499991],
[0, 0.5],
True,
None,
),
(
"lr overlapping part small but keep",
1000,
[0.49998, 0.8],
[0, 0.5],
True,
[0.99996, 1],
),
(
"lr overlapping part too small",
1000,
[0.499991, 0.8],
[0, 0.5],
False,
None,
),
],
)
def test_apply_lr_on_split(
case_label,
original_length_meters,
original_lr,
split_lr,
expected_is_applicable,
expected_new_lr,
):
split_segment = SplitSegment(
None,
None,
SplitPoint(
None, None, lr=split_lr[0], lr_meters=split_lr[0] * original_length_meters
),
SplitPoint(
None, None, lr=split_lr[1], lr_meters=split_lr[1] * original_length_meters
),
)
is_applicable, new_lr = apply_lr_on_split(
original_lr,
split_segment,
original_length_meters,
min_overlapping_length_meters=0.01,
)
assert (
is_applicable == expected_is_applicable
), f"is_applicable mismatch for case '{case_label}'"
assert new_lr == expected_new_lr, f"new_lr mismatch for case '{case_label}'"