Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: rfc: refactor: run_float_fn -> run_float_fn_approx #507

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,26 @@ def f(hugr: Package, expected: Any, fn_name: str = "main"):
return f



@pytest.fixture
def run_int_fn():
return _run_fn("run_int_function")


@pytest.fixture
def run_float_fn():
return _run_fn("run_float_function")
def run_float_fn_approx():
"""Like run_int_fn, but takes optional additional parameters `rel`, `abs` and `nan_ok`
as per `pytest.approx`."""
run_fn = _run_fn("run_float_function")

def run_approx(
hugr: Package,
expected: float,
fn_name: str = "main",
*,
rel: float | None = None,
abs: float | None = None,
nan_ok: bool = False,
):
return run_fn(hugr, pytest.approx(expected, rel=rel, abs=abs, nan_ok=nan_ok))

return run_approx
4 changes: 2 additions & 2 deletions tests/integration/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def run_rem() -> int:
run_int_fn(hugr, expected=2, fn_name="run_rem")


def test_angle_exec(validate, run_float_fn):
def test_angle_exec(validate, run_float_fn_approx):
module = GuppyModule("test_angle_exec")
module.load_all(angles)

Expand All @@ -247,4 +247,4 @@ def main() -> float:
hugr = module.compile()
validate(hugr)
import math
run_float_fn(hugr, expected=pytest.approx(-6 * math.pi))
run_float_fn_approx(hugr, expected=-6 * math.pi)
Loading