예제 #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))