Skip to content

Commit

Permalink
Merge pull request #110 from Blueprints-org/109-feature-request-add-a…
Browse files Browse the repository at this point in the history
…-latex-to-formula-91n

(#109) Add latex to formula 9.1N from NEN-EN 1992-1-1+C2:2011
  • Loading branch information
bro-wi authored Mar 28, 2024
2 parents f7ffd1d + 2fb3fe5 commit 6537a4b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from blueprints.codes.eurocode.nen_en_1992_1_1_c2_2011 import NEN_EN_1992_1_1_C2_2011
from blueprints.codes.formula import Formula
from blueprints.codes.latex_formula import LatexFormula, latex_fraction, latex_max_curly_brackets
from blueprints.type_alias import MM, MM2, MPA
from blueprints.validations import raise_if_negative

Expand Down Expand Up @@ -56,3 +57,19 @@ def _evaluate(
"""For more detailed documentation see the class docstring."""
raise_if_negative(f_ctm=f_ctm, f_yk=f_yk, b_t=b_t, d=d)
return max(0.26 * (f_ctm / f_yk) * b_t * d, 0.0013 * b_t * d)

def latex(self) -> LatexFormula:
"""Returns LatexFormula object for formula 9.1N."""
return LatexFormula(
return_symbol=r"A_{s,min}",
result=f"{self:.2f}",
equation=latex_max_curly_brackets(
rf"0.26 \cdot {latex_fraction(r'f_{ctm}', r'f_{yk}')} \cdot b_t \cdot d",
r"0.0013 \cdot b_t \cdot d",
),
numeric_equation=latex_max_curly_brackets(
rf"0.26 \cdot {latex_fraction(f'{self.f_ctm:.2f}', f'{self.f_yk:.2f}')} \cdot {self.b_t:.2f} \cdot {self.d:.2f}",
rf"0.0013 \cdot {self.b_t:.2f} \cdot {self.d:.2f}",
),
comparison_operator_label="=",
)
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,31 @@ def test_raise_error_when_negative_d_is_given(self) -> None:

with pytest.raises(NegativeValueError):
Form9Dot1nMinimumTensileReinforcementBeam(f_ctm=f_ctm, f_yk=f_yk, b_t=b_t, d=d)

@pytest.mark.parametrize(
("representation", "expected_result"),
[
(
"complete",
r"A_{s,min} = \max \left\{0.26 \cdot \frac{f_{ctm}}{f_{yk}} \cdot b_t \cdot d; 0.0013 \cdot b_t \cdot d\right\} = "
r"\max \left\{0.26 \cdot \frac{2.00}{355.00} \cdot 50.00 \cdot 150.00; 0.0013 \cdot 50.00 \cdot 150.00\right\} = 10.99",
),
("short", "A_{s,min} = 10.99"),
],
)
def test_latex(self, representation: str, expected_result: str) -> None:
"""Test the latex representation."""
# Example values
f_ctm = 2 # MPa
f_yk = 355 # MPa
b_t = 50 # mm
d = 150 # mm

latex = Form9Dot1nMinimumTensileReinforcementBeam(f_ctm=f_ctm, f_yk=f_yk, b_t=b_t, d=d).latex()

actual = {
"complete": latex.complete,
"short": latex.short,
}

assert actual[representation] == expected_result, f"{representation} representation failed."
16 changes: 14 additions & 2 deletions tests/codes/test_latex_formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

import pytest

from blueprints.codes.latex_formula import LatexFormula, latex_fraction, latex_max_curly_brackets
from blueprints.codes.latex_formula import LatexFormula, latex_fraction, latex_max_curly_brackets, latex_min_curly_brackets


@pytest.fixture()
def fixture_latex_formula() -> LatexFormula:
"""Fixture for testing."""
return LatexFormula(return_symbol="E", result="500", equation="mc^2", numeric_equation="5*10^2", comparison_operator_label="=")
return LatexFormula(
return_symbol="E",
result="500",
equation="mc^2",
numeric_equation="5*10^2",
comparison_operator_label="=",
)


class TestLatexFormula:
Expand Down Expand Up @@ -50,3 +56,9 @@ def test_latex_max_curly_brackets() -> None:
"""Test the latex_max_curly_brackets function."""
result = latex_max_curly_brackets(r"a+b", r"500", r"c-d")
assert result == r"\max \left\{a+b; 500; c-d\right\}"


def test_min_curly_brackets() -> None:
"""Test the latex_min_curly_brackets function."""
result = latex_min_curly_brackets(r"a+b", r"500", r"c-d")
assert result == r"\min \left\{a+b; 500; c-d\right\}"

0 comments on commit 6537a4b

Please sign in to comment.