diff --git a/examples/pure-hatch/tests/examplePy/test_temperature.py b/examples/pure-hatch/tests/examplePy/test_temperature.py index c8ac1eef1..6ea90f32a 100644 --- a/examples/pure-hatch/tests/examplePy/test_temperature.py +++ b/examples/pure-hatch/tests/examplePy/test_temperature.py @@ -1,6 +1,6 @@ """Pytest-based unit test examples for the temperature module""" -import math +import pytest from examplePy import temperature @@ -43,56 +43,29 @@ def test_temperature_workflow(): assert abs(result - 50.0) < 0.01 -def test_fahrenheit_to_celsius_positive(): - """Test F to C calculation for positive values""" - value = 95 - expected_result = 35 +@pytest.mark.parametrize( + "value, expected", + [ + pytest.param(95, 35, id="positive"), + pytest.param(-13, -25, id="negative"), + pytest.param(0, -17.7778, id="zero"), + ], +) +def test_fahrenheit_to_celsius(value, expected): + """Check known Fahrenheit/Celsius pairs, including zero Fahrenheit.""" result = temperature.fahrenheit_to_celsius(value) - - assert result == expected_result - - -def test_fahrenheit_to_celsius_negative(): - """Test F to C calculation for negative values""" - value = -13 - expected_result = -25 - result = temperature.fahrenheit_to_celsius(value) - - assert result == expected_result - - -def test_fahrenheit_to_celsius_zero(): - """Test F to C calculation for zero""" - value = 0 - expected_result = -17.7778 - result = temperature.fahrenheit_to_celsius(value) - - # Test that the result is close to the expected value, within tolerances - assert math.isclose(result, expected_result, abs_tol=0.0001) - - -def test_celsius_to_fahrenheit_positive(): - """Test C to F calculation for positive values""" - value = 100 - expected_result = 212 - result = temperature.celsius_to_fahrenheit(value) - - assert result == expected_result - - -def test_celsius_to_fahrenheit_negative(): - """Test C to F calculation for negative values""" - value = -20 - expected_result = -4 + assert result == pytest.approx(expected, abs=0.0001) + + +@pytest.mark.parametrize( + "value, expected", + [ + pytest.param(100, 212, id="positive"), + pytest.param(-20, -4, id="negative"), + pytest.param(0, 32, id="zero"), + ], +) +def test_celsius_to_fahrenheit(value, expected): + """Check known Celsius/Fahrenheit pairs.""" result = temperature.celsius_to_fahrenheit(value) - - assert result == expected_result - - -def test_celsius_to_fahrenheit_zero(): - """Test C to F calculation for zero""" - value = 0 - expected_result = 32 - result = temperature.celsius_to_fahrenheit(value) - - assert result == expected_result + assert result == pytest.approx(expected, abs=0.0001) diff --git a/examples/pure-setuptools/tests/examplePy/test_temperature.py b/examples/pure-setuptools/tests/examplePy/test_temperature.py index 9c6e3d5a3..49829064f 100644 --- a/examples/pure-setuptools/tests/examplePy/test_temperature.py +++ b/examples/pure-setuptools/tests/examplePy/test_temperature.py @@ -1,60 +1,32 @@ -"""Pytest-based unit test examples for the temperature module""" - -import math +"""Parametrized conversion cases for the example temperature module.""" +import pytest from examplePy import temperature -def test_fahrenheit_to_celsius_positive(): - """Test F to C calculation for positive values""" - value = 95 - expected_result = 35 - result = temperature.fahrenheit_to_celsius(value) - - assert result == expected_result - - -def test_fahrenheit_to_celsius_negative(): - """Test F to C calculation for negative values""" - value = -13 - expected_result = -25 +@pytest.mark.parametrize( + "value, expected", + [ + pytest.param(95, 35, id="positive"), + pytest.param(-13, -25, id="negative"), + pytest.param(0, -17.7778, id="zero"), + ], +) +def test_fahrenheit_to_celsius(value, expected): + """Check known Fahrenheit/Celsius pairs, including zero Fahrenheit.""" result = temperature.fahrenheit_to_celsius(value) - - assert result == expected_result - - -def test_fahrenheit_to_celsius_zero(): - """Test F to C calculation for zero""" - value = 0 - expected_result = -17.7778 - result = temperature.fahrenheit_to_celsius(value) - - # Test that the result is close to the expected value, within tolerances - assert math.isclose(result, expected_result, abs_tol=0.0001) - - -def test_celsius_to_fahrenheit_positive(): - """Test C to F calculation for positive values""" - value = 100 - expected_result = 212 - result = temperature.celsius_to_fahrenheit(value) - - assert result == expected_result - - -def test_celsius_to_fahrenheit_negative(): - """Test C to F calculation for negative values""" - value = -20 - expected_result = -4 + assert result == pytest.approx(expected, abs=0.0001) + + +@pytest.mark.parametrize( + "value, expected", + [ + pytest.param(100, 212, id="positive"), + pytest.param(-20, -4, id="negative"), + pytest.param(0, 32, id="zero"), + ], +) +def test_celsius_to_fahrenheit(value, expected): + """Check known Celsius/Fahrenheit pairs.""" result = temperature.celsius_to_fahrenheit(value) - - assert result == expected_result - - -def test_celsius_to_fahrenheit_zero(): - """Test C to F calculation for zero""" - value = 0 - expected_result = 32 - result = temperature.celsius_to_fahrenheit(value) - - assert result == expected_result + assert result == pytest.approx(expected, abs=0.0001)