Пример #1
0
def meetup_day(year, month, weekday_str, day_order):

    class MeetupDayException(Exception):
        pass

    days_of_week = {'Monday': 0, 'Tuesday': 1, 'Wednesday': 2, 'Thursday': 3,
                    'Friday': 4, 'Saturday': 5, 'Sunday': 6}

    days_descriptions = {'1st': 1, '2nd': 2, '3rd': 3, '4th': 4, '5th': 5,
                        'last': 'last',
                        'teenth': (13, 14, 15, 16, 17, 18, 19)}

    #days_in_month = 0

    weekday = days_of_week[weekday_str]

    # calculate all dates in month
    number_of_days = days_in_month(month, is_leap_year(year))
    month_dates = [date(year, month, day) for day in range(1, number_of_days + 1)]

    # all weekdays in month
    month_weekdays = [(day, day.weekday()) for day in month_dates]

    required_day = days_descriptions[day_order]

    # collect all dates with required weekday
    all_dates_with_required_weekday = []
    for item in month_weekdays:
        if weekday in item:
            all_dates_with_required_weekday.append(item[0])

    # select required date using description
    if required_day == 'last':
        result = all_dates_with_required_weekday[-1]
    elif type(required_day) is int:
        if len(all_dates_with_required_weekday) >= required_day:
            result = all_dates_with_required_weekday[required_day - 1]
        else:
            raise MeetupDayException()
    elif type(required_day) is tuple:
        for item in all_dates_with_required_weekday:
            if item.day in required_day:
                return item
        raise MeetupDayException()      # no such day
    else:
        raise MeetupDayException()      # date not found

    return result
Пример #2
0
 def test_century(self):
     self.assertIs(is_leap_year(1900), False)
def test_is_leap3():
    with pytest.raises(ValueError):
        is_leap_year("fasdkjgfas")
Пример #4
0
 def test_year_not_divisible_by_4(self):
     self.assertIs(is_leap_year(2015), False)
Пример #5
0
 def test_year_divisible_by_400(self):
     self.assertIs(is_leap_year(2000), True)
Пример #6
0
 def test_leap_year(self):
     self.assertTrue(is_leap_year(1996))
Пример #7
0
 def test_year_divisible_by_400(self):
     self.assertIs(is_leap_year(2000), True)
Пример #8
0
 def test_leap_year(self):
     self.assertIs(is_leap_year(1996), True)
Пример #9
0
 def test_year_divisible_by_100_but_not_divisible_by_400(self):
     self.assertIs(is_leap_year(200), False)
     self.assertIs(is_leap_year(1400), False)
     self.assertIs(is_leap_year(600), False)
     self.assertIs(is_leap_year(1900), False)
     self.assertIs(is_leap_year(1000), False)
Пример #10
0
 def test_another_century(self):
     self.assertIs(is_leap_year(2000), True)
Пример #11
0
 def test_correct(self):
     self.assertEqual(leap.is_leap_year(1600), "1600 is a leap year!")
     self.assertEqual(leap.is_leap_year(1996), "1996 is a leap year!")
     self.assertEqual(leap.is_leap_year(2000), "2000 is a leap year!")
Пример #12
0
 def test_year_divisible_by_100_not_divisible_by_400(self):
     self.assertFalse(is_leap_year(2100))
Пример #13
0
 def test_year_divisible_by_4_not_divisible_by_100(self):
     self.assertTrue(is_leap_year(2016))
Пример #14
0
 def test_non_leap_year(self):
     self.assertFalse(is_leap_year(1997))
Пример #15
0
 def test_leap_year(self):
     self.assertIs(is_leap_year(1996), True)
Пример #16
0
 def test_century(self):
     self.assertIs(is_leap_year(1900), False)
Пример #17
0
 def test_year_divisible_by_4(self):
     self.assertIs(is_leap_year(1996), True)
     self.assertIs(is_leap_year(8), True)
     self.assertIs(is_leap_year(1412), True)
     self.assertIs(is_leap_year(1236), True)
Пример #18
0
 def test_year_divisible_by_4_not_divisible_by_100(self):
     self.assertIs(is_leap_year(1996), True)
Пример #19
0
 def test2(self):
     self.assertTrue(is_leap_year("2024"))
Пример #20
0
 def test_year_1900(self):
     self.assertIs(is_leap_year(1900), False)
Пример #21
0
 def test3(self):
     self.assertFalse(is_leap_year("1981"))
Пример #22
0
 def test_year_divisible_by_4_not_divisible_by_100(self):
     self.assertIs(is_leap_year(1996), True)
Пример #23
0
 def test1(self):
     self.assertTrue(is_leap_year("2020"))
Пример #24
0
 def test_year_divisible_by_200_not_divisible_by_400(self):
     self.assertIs(is_leap_year(1800), False)
Пример #25
0
 def test_current_year_2018_is_not_a_leap_year(self):
     self.assertIs(is_leap_year(), False)
def test_is_leap2():
    assert is_leap_year("2021") == False
Пример #27
0
 def test_non_leap_even_year(self):
     self.assertFalse(leap.is_leap_year(1998))
def test_is_leap1():
    assert is_leap_year("2020") == True
Пример #29
0
 def test_century(self):
     self.assertFalse(leap.is_leap_year(1900))
Пример #30
0
 def test_exceptional_century(self):
     self.assertIs(is_leap_year(2400), True)
Пример #31
0
 def test_exceptional_century(self):
     self.assertTrue(leap.is_leap_year(2400))
Пример #32
0
 def test_non_leap_year(self):
     self.assertIs(is_leap_year(1997), False)
Пример #33
0
 def test_leap_year(self):
     self.assertTrue(leap.is_leap_year(1996))
Пример #34
0
 def test_exceptional_century(self):
     self.assertIs(is_leap_year(2400), True)
Пример #35
0
 def test_year_divisible_not_divisible(self):
     self.assertIs(is_leap_year(999), False)
Пример #36
0
 def test_non_leap_year(self):
     self.assertIs(is_leap_year(1997), False)
 def test_year_divisible_by_4_not_divisible_by_100(self):
     self.assertTrue(is_leap_year(2016))
Пример #38
0
 def test_year_divisible_by_100_not_divisible_by_400(self):
     self.assertIs(is_leap_year(2100), False)
Пример #39
0
 def test_year_divisible_by_2_not_divisible_by_4(self):
     self.assertIs(is_leap_year(1970), False)
Пример #40
0
 def test_year_2016(self):
     self.assertIs(is_leap_year(2016), True)
Пример #41
0
 def test_year_divisible_by_409990(self):
     self.assertIs(is_leap_year(1900), False)
Пример #42
0
 def test_year_not_divisible_by_4(self):
     self.assertIs(is_leap_year(2015), False)
Пример #43
0
 def test_century(self):
     self.assertFalse(is_leap_year(1900))