Download tests/test_engineering.py from Surajnitp/flowmarg: direct link, hf CLI and curl.
- Browser
- Download file 3.35 kB
-
https://huggingface.co/spaces/Surajnitp/flowmarg/resolve/main/tests/test_engineering.py
- Command line
-
hf download hf://spaces/Surajnitp/flowmarg/tests/test_engineering.py
-
curl -L -o test_engineering.py https://huggingface.co/spaces/Surajnitp/flowmarg/resolve/main/tests/test_engineering.py
3.35 kB
| """ | |
| 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"]) | |