File size: 3,353 Bytes
2379054
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
TEST SUITE - core/engineering.py
Tests PASS/REVIEW/FAIL boundaries
"""

import pytest
from core.engineering import (
    calculate_lift_value,
    calculate_slue_value,
    calculate_cant_value,
    calculate_twist,
    check_radius_for_speed,
    create_engineering_finding,
    TrackData,
    NR_LIMITS
)

class TestEngineeringCalculations:
    """Test core engineering calculations"""
    
    def test_calculate_lift_value(self):
        assert calculate_lift_value(10.0, 10.025) == 25.0
        assert calculate_lift_value(None, 10.025) is None
        assert calculate_lift_value(10.0, None) is None
    
    def test_calculate_slue_value(self):
        assert calculate_slue_value(1.5, 1.525) == 25.0
        assert calculate_slue_value(None, 1.525) is None
    
    def test_calculate_cant_value(self):
        assert calculate_cant_value(12.0, 12.065) == 65.0
        assert calculate_cant_value(None, 12.065) is None
    
    def test_calculate_twist(self):
        assert calculate_twist(10.0, 10.025, 5.0) == 5.0
        assert calculate_twist(None, 10.025, 5.0) is None
        assert calculate_twist(10.0, 10.025, 0) is None
    
    def test_check_radius_for_speed(self):
        result, required = check_radius_for_speed(160, 75, 110, 65)
        assert result == False  # 160m is not enough for 75mph with these cants
        assert required > 160

class TestComplianceFindings:
    """Test PASS/REVIEW/FAIL boundaries"""
    
    def test_lift_within_limit(self):
        finding = create_engineering_finding(
            "Lift", 25.0, 30.0, "Test", "Test evidence", 1, 1000
        )
        assert finding['status'] == "PASS"
        assert finding['priority'] == "LOW"
    
    def test_lift_exceeding_1_5x_limit(self):
        finding = create_engineering_finding(
            "Lift", 40.0, 30.0, "Test", "Test evidence", 1, 1000
        )
        assert finding['status'] == "REVIEW"
        assert finding['priority'] == "MEDIUM"
    
    def test_lift_exceeding_2x_limit(self):
        finding = create_engineering_finding(
            "Lift", 65.0, 30.0, "Test", "Test evidence", 1, 1000
        )
        assert finding['status'] == "FAIL"
        assert finding['priority'] == "HIGH"
    
    def test_radius_meets_minimum(self):
        finding = create_engineering_finding(
            "Radius", 160.0, 150.0, "Test", "Test evidence", 1, 1000,
            limit_type="min"
        )
        assert finding['status'] == "PASS"
    
    def test_radius_below_minimum(self):
        finding = create_engineering_finding(
            "Radius", 120.0, 150.0, "Test", "Test evidence", 1, 1000,
            limit_type="min"
        )
        assert finding['status'] == "FAIL"
        assert finding['priority'] == "HIGH"

class TestTrackData:
    """Test TrackData dataclass"""
    
    def test_to_dict(self):
        td = TrackData(track_no=1, chainages=[1000, 1010])
        td.lifts[1000] = 25.0
        td.slues[1000] = 15.0
        
        result = td.to_dict()
        assert result['lift'][1000] == 25.0
        assert result['slue'][1000] == 15.0
    
    def test_get_lift(self):
        td = TrackData(track_no=1, chainages=[1000, 1010])
        td.lifts[1000] = 25.0
        assert td.get_lift(1000) == 25.0
        assert td.get_lift(2000) is None

if __name__ == "__main__":
    pytest.main([__file__, "-v"])