Ejemplo n.º 1
0
    def test_main_year_1998_1999(self):

        expected = 4

        stop_date = Date(31, '', Calendar.month_name[11], 1999)

        current_date = Date(1, Calendar.week_days[3], Calendar.month_name[0],
                            1998)

        self.assertEqual(expected, main(stop_date, current_date))
Ejemplo n.º 2
0
    def test_main(self):

        expected = 171

        stop_date = Date(31, '', Calendar.month_name[11], 2000)

        current_date = Date(1, Calendar.week_days[0], Calendar.month_name[0],
                            1900)

        self.assertEqual(expected, main(stop_date, current_date))
Ejemplo n.º 3
0
def main(stop_date: Date, current_date: Date):

    '''
    Start date: 1 Jan 1900 was a Monday.

    How many Sundays fell on the first of the month
    during the twentieth century
    (1 Jan 1901 to 31 Dec 2000)?
    :return:
    '''

    start_time = time.time()
    sundays = 0

    while current_date.get_year() <= stop_date.get_year():

        for day in range(2, 33, 1):
            '''
            print("{0}, {1}, {2}, {3}".format(current_date.get_day(),
                                              current_date.get_month(),
                                              current_date.get_year(),
                                              current_date.get_week()))
            '''
            try:
                if current_date.get_day() == 1 and \
                        current_date.get_week() == Calendar.week_days[6] and \
                        current_date.get_year() >= 1901:
                    sundays += 1
                    '''
                    print("\nSunday fell on the first of the month:")
                    print("{0}, {1}, {2}, {3}\n".format(current_date.get_day(),
                                                        current_date.get_month(),
                                                        current_date.get_year(),
                                                        current_date.get_week()))
                    '''

                # if current_date.get_day() == day:
                    # continue

                current_date.set_day(day)

            except ValueError:
                # print(err.args)
                break

    print_time_log(start_time, sundays)
    return sundays
Ejemplo n.º 4
0
 def test_date_set_week_error(self):
     with self.assertRaises(ValueError):
         Date.__set_week__('blabla')
Ejemplo n.º 5
0
 def test_date_set_year_error(self):
     with self.assertRaises(ValueError):
         Date.__set_year__(3000)