Beispiel #1
0
    def _get_correct_leap_year(self, prefer_dates_from, current_year):
        if prefer_dates_from == 'future':
            return get_next_leap_year(current_year)
        if prefer_dates_from == 'past':
            return get_previous_leap_year(current_year)

        # Default case ('current_period'): return closer leap year
        next_leap_year = get_next_leap_year(current_year)
        previous_leap_year = get_previous_leap_year(current_year)
        next_leap_year_is_closer = next_leap_year - current_year < current_year - previous_leap_year
        return next_leap_year if next_leap_year_is_closer else previous_leap_year
def test_get_next_leap_year(year, expected_next_leap_year):
    assert get_next_leap_year(year) == expected_next_leap_year