diff --git a/tests/test_decimal.py b/tests/test_decimal.py index 54a87e2f..7e6d54b8 100644 --- a/tests/test_decimal.py +++ b/tests/test_decimal.py @@ -1,48 +1,46 @@ +import pytest + from sizebot.lib.digidecimal import BaseDecimal, RawDecimal, round_fraction, fix_zeroes -def test_makeSureDecimalStillWorks(): +def test_make_sure_decimal_still_works() -> None: result = BaseDecimal("1.2") + BaseDecimal("2.3") assert result == BaseDecimal("3.5") -def test_roundDecimal_impliedAccuracy(): +def test_round_decimal_implied_accuracy() -> None: result = round(BaseDecimal("2.41")) assert result == BaseDecimal("2") -def test_roundDecimal_specifiedAccuracy(): +def test_round_decimal_specified_accuracy() -> None: result = round(BaseDecimal("2.41"), 1) assert result == BaseDecimal("2.4") -def test_roundDecimalFraction(): +def test_round_decimal_fraction() -> None: result = round_fraction(BaseDecimal("2.127"), 8) assert result == BaseDecimal("2.125") - -def test_toQuarters(): - result = format(BaseDecimal("2.25"), "%4") - assert result == "2¼" - - -def test_toQuarters_125(): - result = format(BaseDecimal("2.126"), "%4") - assert result == "2¼" - - -def test_toQuarters_noFraction(): - result = format(BaseDecimal("2.01"), "%4") - assert result == "2" - - -def test_trimZeros(): - result = fix_zeroes(RawDecimal("100.00")) - result = str(result) - assert result == "100" - - -def test_trimZeros_E(): - result = fix_zeroes(RawDecimal("1E2")) - result = str(result) +@pytest.mark.parametrize( + ("value", "spec", "expected"), + [ + (BaseDecimal("2.25"), "%4", "2¼"), + (BaseDecimal("2.126"), "%4", "2¼"), + (BaseDecimal("2.01"), "%4", "2"), + ] +) +def test_to_quarters(value: BaseDecimal, spec: str, expected: str) -> None: + result = format(value, spec) + assert result == expected + +@pytest.mark.parametrize( + ("value", "expected"), + [ + (RawDecimal("100.00"), "100"), + (BaseDecimal("1E2"), "100") + ] +) +def test_trim_zeros(value: RawDecimal, expected: str) -> None: + result = str(fix_zeroes(RawDecimal("100.00"))) assert result == "100"