def test___init__(self): """Test method :meth:`plugins.doomsday.Date.__init__` **Tested:** - The attributes of a valid date are correct after initialization. - A ValueError is raised when initializing an invalid date. """ date = doomsday.Date(2015, 5, 13) self.assertEqual(date.year, 2015) self.assertEqual(date.month, 5) self.assertEqual(date.day, 13) with self.assertRaises(ValueError): doomsday.Date(2015, 2, 29)
def test_is_valid(self): """Test method :meth:`plugins.doomsday.Date.is_valid` **Tested:** - False is returned for a year below 1583. - False is returned for a month below 1. - False is returned for a month above 12. - False is returned for a day below 1. - False is returned for a day above the amount of days in the month. - True is returned for a valid day. """ date = doomsday.Date(1583, 1, 1) date.year = 1582 self.assertFalse(date.is_valid()) date.year = 2015 date.month = 0 self.assertFalse(date.is_valid()) date.month = 13 self.assertFalse(date.is_valid()) date.month = 2 date.day = 0 self.assertFalse(date.is_valid()) date.day = 29 self.assertFalse(date.is_valid()) date.day = 28 self.assertTrue(date.is_valid())
def run(): """Execute the challenges.011e module.""" year = int(utils.get_input("Year (1583 - ...) > ")) month = int(utils.get_input("Month (1 - 12) > ")) ndays = dd.ndays_in_month(month, year) day = int(utils.get_input("Day (1 - {}) > ".format(ndays))) date = dd.Date(year, month, day) print("{} is a {}.".format(date, date.weekday(h=True)))
def test_cumulative_day_of_year(self): """Test method :meth:`plugins.doomsday.Date.cumulative_day_of_year` **Tested:** - The correct cumulative day of the year for the date is returned. """ date = doomsday.Date(2015, 5, 13) self.assertEqual(date.cumulative_day_of_year(), 133)
def test___str__(self): """Test method :meth:`plugins.doomsday.Date.__str__` **Tested:** - The returned string is correct. """ date = doomsday.Date(2015, 5, 13) self.assertEqual(date.__str__(), '2015-5-13')
def run(): """Execute the challenges.013e module.""" year = int(utils.get_input("Year (1583 - ...) > ")) month = int(utils.get_input("Month (1 - 12) > ")) ndays = dd.ndays_in_month(month, year) day = int(utils.get_input("Day (1 - {}) > ".format(ndays))) date = dd.Date(year, month, day) cumulday = date.cumulative_day_of_year() print("{} is day number {} of the year {}.".format(date, cumulday, date.year))
def test_weekday(self): """Test method :meth:`plugins.doomsday.Date.weekday` **Tested:** - The correct weekday of the date is returned as an integer. - The correct weekday of the date is returned as a string. """ date = doomsday.Date(2015, 5, 13) self.assertEqual(date.weekday(), 3) self.assertEqual(date.weekday(h=True), 'wednesday')