paper-dynasty-card-creation/tests/test_helpers.py
2024-11-01 08:50:29 -05:00

58 lines
1.8 KiB
Python

from creation_helpers import pd_positions_df, mround, sanitize_chance_output
def test_positions_df():
cardset_19_pos = pd_positions_df(19)
assert True == True
def test_mround():
assert mround(6.4) == 6.4
assert mround(6.66) == 6.65
assert mround(2.14, base=1.0) == 2.0
assert mround(6.69, base=0.25) == 6.75
def test_sanitize():
# def my_round_decimal(i: float):
# return Decimal(i).quantize(Decimal('0.05'), ROUND_HALF_EVEN)
# def my_round(num: float, to: float = 0.05):
# num, to = Decimal(str(num)), Decimal(str(to))
# return float(round(num / to) * to)
# assert my_round(6) == 6
# assert my_round(5.96) == 5.95
# assert my_round(5.84) == 5.85
# assert my_round(3.123) == 3.1
# assert math.floor(my_round(6)) == 6
# assert math.floor(my_round(5.96)) == 5
assert sanitize_chance_output(6) == 6.0
assert sanitize_chance_output(1.21) == 1.2
assert sanitize_chance_output(4.77) == 4.75
assert sanitize_chance_output(4.78) == 4.8
assert sanitize_chance_output(12.0000000002) == 12.0
assert sanitize_chance_output(12.12, rounding=1.0) == 12.0
assert sanitize_chance_output(1.05, rounding=1.0) == 1.0
# step_1 = Decimal(6) / Decimal(0.05)
# step_1_5 = round(step_1, )
# step_2 = round(step_1)
# step_3 = float(step_2 * Decimal(0.05))
# step_4 = Decimal(step_3)
# assert Decimal(6) == Decimal(6).quantize(Decimal('0.05'), ROUND_HALF_EVEN)
# assert round(step_1) == 120
# # assert step_1 == 120
# assert step_1_5 == 120
# assert step_2 == 120
# assert step_3 == 6.0
# assert step_4 == Decimal('6.0')
# rounded_val = step_4.quantize(Decimal("0.05"), ROUND_HALF_EVEN)
# assert rounded_val == 6
# assert sanitize_chance_output(6) == 6