Skip to content

Commit

Permalink
cleaned up test_decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
nfearnley committed Jun 8, 2024
1 parent 70a82bf commit b48cca8
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions tests/test_decimal.py
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit b48cca8

Please sign in to comment.