Skip to content

Commit 2864801

Browse files
committed
Run test_rounding() with multiple argvalues
1 parent 548a9fd commit 2864801

File tree

1 file changed

+25
-34
lines changed

1 file changed

+25
-34
lines changed

tests/test_zebra_utils.py

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,33 @@
55
Use 'make test' to run all tests.
66
"""
77

8+
import pytest
9+
810
from zebra_puzzles.zebra_utils import round_using_std
911

1012

11-
def test_rounding() -> None:
13+
@pytest.mark.parametrize(
14+
argnames=["value", "std", "value_rounded", "std_rounded"],
15+
argvalues=[
16+
# Test a value that is not rounded
17+
(0.4, 0.3, "0.4", "0.3"),
18+
# Test a value and standard deviation that is rounded
19+
(0.464, 0.31, "0.5", "0.3"),
20+
# Test rounding of a negative number
21+
(-0.464, 0.31, "-0.5", "0.3"),
22+
# Test rounding that requires trailing zeros
23+
(-0.460, 0.001, "-0.460", "0.001"),
24+
# Test default rounding when the standard deviation is unknown (0)
25+
(0.464, 0, "0.46", "0"),
26+
# Test default rounding when the standard deviation is unknown and the value has a trailing zero
27+
(0.40, 0, "0.40", "0"),
28+
# Test rounding of a number much smaller than the standard deviation
29+
(0.0002, 0.3, "0.0", "0.3"),
30+
],
31+
)
32+
def test_rounding(value, std, value_rounded, std_rounded) -> None:
1233
"""Test the rounding function."""
1334
# Test a value that is not rounded
14-
value_rounded, std_rounded = round_using_std(value=0.4, std=0.3)
15-
assert value_rounded == "0.4"
16-
assert std_rounded == "0.3"
17-
18-
# Test a value and standard deviation that is rounded
19-
value_rounded, std_rounded = round_using_std(value=0.464, std=0.31)
20-
assert value_rounded == "0.5"
21-
assert std_rounded == "0.3"
22-
23-
# Test rounding of a negative number
24-
value_rounded, std_rounded = round_using_std(value=-0.464, std=0.31)
25-
assert value_rounded == "-0.5"
26-
assert std_rounded == "0.3"
27-
28-
# Test rounding that requires trailing zeros
29-
value_rounded, std_rounded = round_using_std(value=-0.460, std=0.001)
30-
assert value_rounded == "-0.460"
31-
assert std_rounded == "0.001"
32-
33-
# Test default rounding when the standard deviation is unknown (0)
34-
value_rounded, std_rounded = round_using_std(value=0.464, std=0)
35-
assert value_rounded == "0.46"
36-
assert std_rounded == "0"
37-
38-
# Test default rounding when the standard deviation is unknown and the value has a trailing zero
39-
value_rounded, std_rounded = round_using_std(value=0.40, std=0)
40-
assert value_rounded == "0.40"
41-
assert std_rounded == "0"
42-
43-
# Test rounding of a number much smaller than the standard deviation
44-
value_rounded, std_rounded = round_using_std(value=0.0002, std=0.3)
45-
assert value_rounded == "0.0"
46-
assert std_rounded == "0.3"
35+
value_rounded, std_rounded = round_using_std(value=value, std=std)
36+
assert value_rounded == value_rounded
37+
assert std_rounded == std_rounded

0 commit comments

Comments
 (0)