-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |