calcs/concrete-beam2/test_concrete_beam2.py
smillmorel d5ac3fca7e Add structural calculation worksheets
Collection of engineering calculation projects (Python + Typst), each with
input, calc script, tests, results, and generated PDF where available.
2026-09-21 12:19:20 -04:00

70 lines
2 KiB
Python

from pathlib import Path
import importlib.util
import pytest
import yaml
HERE = Path(__file__).resolve().parent
spec = importlib.util.spec_from_file_location("concrete_beam2_calc", HERE / "calc.py")
assert spec is not None and spec.loader is not None
calc_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(calc_module)
compute = calc_module.compute
def load_input():
with (HERE / "input.yaml").open(encoding="utf-8") as handle:
return yaml.safe_load(handle)
@pytest.fixture
def result():
return compute(load_input())
def test_example_demands(result):
v = result["values"]
assert v["self_weight_klf"] == pytest.approx(0.1)
assert v["wu_klf"] == pytest.approx(0.7325)
assert v["Mu_kipft"] == pytest.approx(23.44)
assert v["Vu_kip"] == pytest.approx(5.86)
def test_example_flexure(result):
v = result["values"]
assert v["a_in"] == pytest.approx(1.519608, rel=1e-5)
assert v["et"] == pytest.approx(0.017137, rel=1e-3)
assert v["phi"] == pytest.approx(0.9)
assert v["phiMn_kipft"] == pytest.approx(26.133456, rel=1e-5)
assert result["checks"]["flexure"]["ok"] is True
def test_example_min_steel_and_shear(result):
v = result["values"]
assert v["As_min_in2"] == pytest.approx(0.384, rel=1e-4)
assert v["phiVc_kip"] == pytest.approx(7.887205, rel=1e-4)
assert result["checks"]["minimum_steel"]["ok"] is True
assert result["checks"]["shear"]["ok"] is True
def test_alternate_units_match_default(result):
alt = load_input()
alt.update(
{
"span": "192 in",
"tributary": "75 in",
"fc": "3000 psi",
}
)
converted = compute(alt)
for key in ("span_ft", "tributary_ft", "fc_ksi", "Mu_kipft", "phiMn_kipft", "Vu_kip"):
assert converted["values"][key] == pytest.approx(result["values"][key], rel=1e-6)
def test_wrong_dimension_is_rejected():
bad = load_input()
bad["span"] = "16 kip"
with pytest.raises(ValueError, match="span"):
compute(bad)