Skip to content

Commit 6f854da

Browse files
Add new test cases for advanced equations in conftest.py
1 parent 6295340 commit 6f854da

8 files changed

Lines changed: 26 additions & 26 deletions

File tree

tests/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,29 @@ class RawCase:
6464
("v = 5.0 +- 0.1", "v"),
6565
],
6666
),
67+
RawCase(
68+
name="trig_exp",
69+
equation=["I", "I0 * exp(-t/tau) * sin(omega*t + phi)"],
70+
variables=[
71+
("I0 = 2.0 +- 0.05", r"I_0"),
72+
("t = 0.25 +- 0.01", "t"),
73+
("tau = 1.2 +- 0.02", r"\tau"),
74+
("omega = 3.14 +- 0.01", r"\omega"),
75+
("phi = 0.1 +- 0.02", r"\phi"),
76+
],
77+
),
78+
RawCase(
79+
name="rational_mixed",
80+
equation=["Z", "(a*b + c)/(d - e*f)"],
81+
variables=[
82+
("a = 1.5 +- 0.01", "a"),
83+
("b = 2.5 +- 0.02", "b"),
84+
("c = 0.75 +- 0.005", "c"),
85+
("d = 10 +- 0.1", "d"),
86+
("e = 0.5 +- 0.01", "e"),
87+
("f = 4 +- 0.2", "f"),
88+
],
89+
),
6790
]
6891

6992

tests/test_calculator.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from __future__ import annotations
44

5-
import pytest
6-
75
from tests.conftest import RawCase
86
from tests.legacy_calculator import run_legacy_calculator
97
from uncertainty_calculator import Digits, Equation, UncertaintyCalculator, Variable
@@ -20,7 +18,6 @@ def test_calculator_output_matches_legacy(
2018
include_equation_number,
2119
):
2220
"""Refactored calculator should match the legacy implementation."""
23-
2421
expected_output = run_legacy_calculator(
2522
equation=raw_case.equation,
2623
variables=raw_case.variables,
@@ -47,7 +44,6 @@ def test_calculator_output_matches_legacy(
4744

4845
def test_run_can_be_called_multiple_times_with_new_inputs():
4946
"""Calculator should not leak state between runs when inputs change."""
50-
5147
digits = Digits(mu=2, sigma=2)
5248
calc = UncertaintyCalculator(
5349
equation=Equation(lhs="y", rhs="x"),
@@ -72,7 +68,6 @@ def test_run_can_be_called_multiple_times_with_new_inputs():
7268

7369
def test_variable_dataclass_input():
7470
"""Calculator should accept dataclass inputs and return a string output."""
75-
7671
equation_obj = Equation(lhs=r"\zeta", rhs=r"K*x")
7772
variables_obj = [
7873
Variable(name="K", value="2", uncertainty="0.1", latex_name="K"),
@@ -95,7 +90,6 @@ def test_variable_dataclass_input():
9590

9691
def test_mixed_input_types():
9792
"""Numeric values provided as float/int should be accepted."""
98-
9993
equation = Equation(lhs="y", rhs="x")
10094
variables = [Variable(name="x", value=10.5, uncertainty=0.5, latex_name="x")]
10195
digits = Digits(mu=2, sigma=2)
@@ -111,4 +105,3 @@ def test_mixed_input_types():
111105
)
112106

113107
calc.run()
114-

tests/test_compute.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def _simple_parse_state(value: str, uncertainty: str = "0.1"):
1818

1919
def test_compute_zero_uncertainty_sets_zero_derivative_and_sigma():
2020
"""Zero uncertainty should produce zero derivatives and zero sigma."""
21-
2221
parse_state = _simple_parse_state(value="2", uncertainty="0")
2322
compute_state = compute(parse_state, digits=Digits(mu=2, sigma=2))
2423

@@ -27,4 +26,3 @@ def test_compute_zero_uncertainty_sets_zero_derivative_and_sigma():
2726
assert pdv_expr == S.Zero
2827
assert pdv_num == S.Zero
2928
assert compute_state.result_sigma == "0"
30-

tests/test_formatting.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@
1010

1111
def test_latex_number_basic_formatting():
1212
"""latex_number should render rational and integer inputs."""
13-
1413
assert latex_number(sympify("3/2")) == "\\frac{3}{2}"
1514
assert latex_number(2) == "2"
16-

tests/test_parsing.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
def test_parse_equation_trims_and_builds_dataclass():
1313
"""Whitespace should be stripped when building Equation."""
14-
1514
raw = [" A ", " B + C "]
1615
equation = parse_equation(raw)
1716
assert equation.lhs == "A"
@@ -20,14 +19,12 @@ def test_parse_equation_trims_and_builds_dataclass():
2019

2120
def test_parse_equation_invalid_length_raises():
2221
"""Invalid equation length should raise ValueError."""
23-
2422
with pytest.raises(ValueError):
2523
parse_equation(["only-one-side"])
2624

2725

2826
def test_parse_variables_parses_value_and_uncertainty():
2927
"""Legacy tuple definitions should convert to Variable dataclasses."""
30-
3128
raw = [
3229
("X = 1 +- 0.1", "X"),
3330
("Y = 2 +- 0.2", "Y"),
@@ -41,19 +38,16 @@ def test_parse_variables_parses_value_and_uncertainty():
4138

4239
def test_parse_variables_invalid_definition():
4340
"""Bad legacy variable definitions should be rejected."""
44-
4541
with pytest.raises(ValueError):
4642
parse_variables([("invalid", "x")])
4743

4844

4945
def test_parsing_rejects_duplicate_variable_names():
5046
"""Duplicate variable names should raise a ValueError."""
51-
5247
equation = Equation(lhs="y", rhs="x + z")
5348
variables = [
5449
Variable(name="x", value=1, uncertainty=0.1, latex_name="x"),
5550
Variable(name="x", value=2, uncertainty=0.2, latex_name="x_dup"),
5651
]
5752
with pytest.raises(ValueError, match="Duplicate variable name detected"):
5853
parse_inputs(equation, variables)
59-

tests/test_rendering.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ def _simple_parse_state(value: str, uncertainty: str = "0.1"):
1717

1818
def test_render_output_combined_contains_sigma_line():
1919
"""Combined rendering should include sigma line and equation alignment."""
20-
2120
parse_state = _simple_parse_state(value="2", uncertainty="0.5")
2221
compute_state = compute(parse_state, digits=Digits(mu=2, sigma=2))
23-
options = RenderOptions(last_unit=None, separate=False, insert=False, include_equation_number=False)
22+
options = RenderOptions(
23+
last_unit=None, separate=False, insert=False, include_equation_number=False
24+
)
2425

2526
output = render_output(parse_state, compute_state, options)
2627
assert "\\begin{aligned}" in output
@@ -30,7 +31,6 @@ def test_render_output_combined_contains_sigma_line():
3031

3132
def test_zero_uncertainty_renders_sigma_without_empty_sqrt():
3233
"""Sigma rendering should short-circuit when uncertainties are zero."""
33-
3434
digits = Digits(mu=2, sigma=2)
3535
calc = UncertaintyCalculator(
3636
equation=Equation(lhs="y", rhs="x"),
@@ -45,4 +45,3 @@ def test_zero_uncertainty_renders_sigma_without_empty_sqrt():
4545
output = calc.run()
4646
assert "\\sigma_{y}&=0" in output
4747
assert "sqrt{" not in output
48-

tests/test_types.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@
99

1010
def test_digits_dataclass_behaves_like_config():
1111
"""Digits should store configured precision values."""
12-
1312
digits = Digits(mu=4, sigma=5)
1413
assert digits.mu == 4
1514
assert digits.sigma == 5
1615

1716

1817
def test_digits_requires_positive_integers():
1918
"""Digits must enforce positive integer validation."""
20-
2119
with pytest.raises(ValueError, match="mu must be a positive integer"):
2220
Digits(mu=0, sigma=2)
2321
with pytest.raises(ValueError, match="sigma must be a positive integer"):
2422
Digits(mu=2, sigma=-1)
25-

tests/test_validation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
def test_missing_variable_validation():
1111
"""Validation should fail when equation references undefined symbols."""
12-
1312
equation = Equation(lhs="y", rhs="m*x + b") # 'b' is missing
1413
variables = [
1514
Variable(name="m", value=1, uncertainty=0.1, latex_name="m"),
@@ -29,4 +28,3 @@ def test_missing_variable_validation():
2928

3029
with pytest.raises(ValueError, match="Symbol 'b' used in equation but not defined"):
3130
calc.run()
32-

0 commit comments

Comments
 (0)