from decimal import ROUND_HALF_EVEN, Decimal import math from batters.calcs_batter import bp_singles, wh_singles, sanitize_chance_output from creation_helpers import sanitize_chance_output, mround 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 # 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 def test_mround(): assert mround(6) == 6.0 assert mround(1.21) == 1.2 assert mround(4.77) == 4.75 assert mround(4.78) == 4.8 def test_decimals(): assert Decimal(8) == 8 def test_bp_singles(): assert bp_singles(23) == 5 assert bp_singles(6) == 5 assert bp_singles(3) == 0 def test_wh_singles(): assert wh_singles(11, .36) == 3.75 assert wh_singles(12, .45) == Decimal('7.95')