def test_parse_float_handles_string_integer(): string_integer = "2" assert isinstance(num_utils.parse_float(string_integer), float) assert num_utils.parse_float(string_integer) == 2.0
def test_parse_float_handles_string_float_with_thousands_comma_and_spaces(): float_with_thousands_comma_and_spaces = "3, 000, 000 . 4 " assert isinstance( num_utils.parse_float(float_with_thousands_comma_and_spaces), float) assert num_utils.parse_float( float_with_thousands_comma_and_spaces) == 3000000.4
def test_parse_float_raises_value_error_when_not_parsed(): with pytest.raises(ValueError): num_utils.parse_float(object()) with pytest.raises(ValueError): num_utils.parse_float("xd,2")
def test_parse_float_handles_string_float_with_thousands_comma(): float_with_thousands_comma = "2,000.2" assert isinstance(num_utils.parse_float(float_with_thousands_comma), float) assert num_utils.parse_float(float_with_thousands_comma) == 2000.2
def test_parse_float_handles_string_float_with_comma(): float_with_comma = "3,14" assert isinstance(num_utils.parse_float(float_with_comma), float) assert num_utils.parse_float(float_with_comma) == 3.14
def test_parse_float_handles_string_float_with_dot(): float_with_dot = "3.14" assert isinstance(num_utils.parse_float(float_with_dot), float) assert num_utils.parse_float(float_with_dot) == 3.14
def test_parse_float_handles_string_integer_with_spaces(): string_integer_with_spaces = "10 000" assert isinstance(num_utils.parse_float(string_integer_with_spaces), float) assert num_utils.parse_float(string_integer_with_spaces) == 10000.0
def __init__(self, title, ratio_1, ratio_x, ratio_2): log.debug("creating Match(" "title={title}, " "ratio_1={ratio_1}, " "ratio_x={ratio_x}, " "ratio_2={ratio_2})...".format(title=title, ratio_1=ratio_1, ratio_x=ratio_x, ratio_2=ratio_2)) self.title = title self.ratio_1 = parse_float(ratio_1) self.ratio_x = parse_float(ratio_x) self.ratio_2 = parse_float(ratio_2) self.ratio_min, self.ratio_med, self.ratio_max = sorted( (self.ratio_1, self.ratio_x, self.ratio_2)) self.ratios = { "1": self.ratio_1, "X": self.ratio_x, "2": self.ratio_2, } self.ranks = { "min": self.ratio_min, "med": self.ratio_med, "max": self.ratio_max, } self.outcome_ranks = {"1": [], "X": [], "2": []} self.ranks_outcomes = { "min": [], "med": [], "max": [], } self.ranks_ratios = {} for outcome, outcome_ratio in self.ratios.items(): for rank, rank_ratio in self.ranks.items(): if outcome_ratio == rank_ratio: self.outcome_ranks[outcome].append(rank) self.ranks_outcomes[rank].append(outcome) self.ranks_ratios[rank] = rank_ratio for outcome, ranks in self.outcome_ranks.items(): if len(ranks) > 1: self.outcome_ranks[outcome] = "/".join(ranks) else: self.outcome_ranks[outcome] = ranks[0] for rank, outcomes in self.ranks_outcomes.items(): if len(outcomes) > 1: self.ranks_outcomes[rank] = "/".join(outcomes) else: self.ranks_outcomes[rank] = outcomes[0] self.tuple = ((title, ) + tuple(self.ratios.values()) + tuple(self.outcome_ranks.values()) + tuple(self.ranks_ratios.values()) + tuple(self.ranks_outcomes.values()))