def test_can_give_total_time_for_month(self): m = Month(2012, 10) w = Week() w.set_day(4, TimeRange(Time(7), Time(17, 10))) m.add_week(40, w) m.add_week(42, w) self.assertEquals(m.get_total_time(), Hours(20, 20))
def test_can_return_week(self): m = Month(2012, 10) w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) m.add_week(40, w) self.assertEquals( m.get_week(40).get_day(0), TimeRange(Time(7), Time(17)))
def test_can_enter_times_into_first_incomplete_week(self): m = Month(2012, 11) w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) w.set_day(3, TimeRange(Time(8), Time(18))) m.add_week(44, w) self.assertEquals(m.get_day(1), TimeRange(Time(8), Time(18)))
def test_can_return_half_week(self): m = Month(2012, 11) w = Week() w.set_day(2, TimeRange(Time(7), Time(17))) w.set_day(3, TimeRange(Time(8), Time(18))) m.add_week(44, w) self.assertEquals(m.get_week(44).get_day(2), None)
def test_can_enter_times_from_last_week_in_month(self): m = Month(2012, 10) w = Week() w.set_day(2, TimeRange(Time(7), Time(17))) w.set_day(3, TimeRange(Time(7), Time(17))) m.add_week(44, w) self.assertEquals(m.get_day(31), TimeRange(Time(7), Time(17))) self.assertNotEquals(m.get_day(32), TimeRange(Time(7), Time(17)))
def test_doesnt_schedule_hours_scheduled_by_taken_week(self): y = Year(2012) taken = Week() taken.set_day(0, TimeRange(Time(13, 30), Time(17))) y.add_taken(40, taken) w = y.get_schedule_for_week(40, Hours(47, 50)) self.assertEquals(w.get_total_time(), Hours(44, 20))
def test_uses_blocked_week_when_scheduling(self): y = Year(2012) blocked = Week() blocked.set_day(0, TimeRange(Time(8, 30), Time(13, 30))) y.add_blocked(40, blocked) w = y.get_schedule_for_week(40, Hours(57, 50)) self.assertEquals(w.get_day(0).get_start(), Time(13, 30))
def test_uses_taken_week_when_scheduling(self): y = Year(2012) taken = Week() taken.set_day(0, TimeRange(Time(13, 30), Time(17))) y.add_taken(40, taken) w = y.get_schedule_for_week(40, Hours(57, 50)) self.assertEquals(w.get_day(0).get_start(), Time(17))
def test_returns_correctly_annotated_week_for_start_of_month(self): m = Month(2012, 11) w = Week() for i in xrange(7): w.set_day(i, TimeRange(Time(7), Time(17))) m.add_week(44, w) aw = m.get_week(44) self.assertEquals(aw.get_earliest_day_in_month(), 1) self.assertEquals(aw.get_first_valid_day(), 3) self.assertEquals(aw.get_last_valid_day(), 6)
def test_can_be_printed(self): w = Week() for i in xrange(7): w.set_day(i, TimeRange(Time(7), Time(17))) self.assertEquals(str(w), """M: 7:00-17:00 T: 7:00-17:00 O: 7:00-17:00 T: 7:00-17:00 F: 7:00-17:00 L: 7:00-17:00 S: 7:00-17:00""")
def test_first_day_is_shorter_if_day_is_taken(self): taken_week = Week() taken_week.set_day(0, TimeRange(Time(7), Time(17))) week = generate_week(Hours(40), taken_week) ranges = [TimeRange(Time(17), Time(20)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(14))] for i in xrange(5): self.assertEquals(week.get_day(i), ranges[i])
def test_can_be_printed(self): w = Week() for i in xrange(7): w.set_day(i, TimeRange(Time(7), Time(17))) self.assertEquals( str(w), """M: 7:00-17:00 T: 7:00-17:00 O: 7:00-17:00 T: 7:00-17:00 F: 7:00-17:00 L: 7:00-17:00 S: 7:00-17:00""")
def test_respects_both_blocked_and_taken_weeks(self): y = Year(2012) blocked = Week() blocked.set_day(0, TimeRange(Time(8, 30), Time(13, 30))) y.add_blocked(40, blocked) taken = Week() taken.set_day(1, TimeRange(Time(7), Time(17))) y.add_taken(40, taken) w = y.get_schedule_for_week(40, Hours(57, 50)) self.assertEquals(w.get_day(0).get_start(), Time(13, 30)) self.assertEquals(w.get_day(1).get_start(), Time(17))
def test_first_day_is_shorter_if_day_is_taken(self): taken_week = Week() taken_week.set_day(0, TimeRange(Time(7), Time(17))) week = generate_week(Hours(40), taken_week) ranges = [ TimeRange(Time(17), Time(20)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(17)), TimeRange(Time(7), Time(14)) ] for i in xrange(5): self.assertEquals(week.get_day(i), ranges[i])
def _get_assistance_week(self): w = Week() w.set_day(0, TimeRange(Time(13, 30), Time(17))) w.set_day(1, TimeRange(Time(6, 30), Time(8, 30))) w.set_day(2, TimeRange(Time(7), Time(17))) w.set_day(3, TimeRange(Time(6, 30), Time(8, 30))) return w
def test_generates_realistic_schedule(self): taken_week = Week() taken = [TimeRange(Time(8, 30), Time(13, 30)), TimeRange(Time(6, 30), Time(13, 30)), TimeRange(Time(7), Time(17)), TimeRange(Time(6, 30), Time(13, 30))] for i in xrange(len(taken)): taken_week.set_day(i, taken[i]) week = generate_week(Hours(30, 20), taken_week) ranges = [TimeRange(Time(13, 30), Time(20)), # 23:50 left TimeRange(Time(13, 30), Time(20)), # 17:20 left TimeRange(Time(17), Time(20)), # 14:20 left TimeRange(Time(13, 30), Time(20)), # 7:50 left TimeRange(Time(7), Time(14, 50))] # 0:00 left for i in xrange(len(ranges)): self.assertEquals(week.get_day(i), ranges[i])
def generate_week(hours, taken_week=None, latest_time=None): latest_time = latest_time or DEFAULT_LATEST_TIME longest_day = DEFAULT_LONGEST_DAY week = Week() day = 0 while hours > Hours(0): assert (day < 7) taken_hours = taken_week.get_day(day) if taken_week != None else None generated_day = generate_day( longest_day if hours > longest_day else hours, taken_hours, latest_time) if generated_day.get_length().get_total_minutes() > 0: week.set_day(day, generated_day) day += 1 hours -= generated_day.get_length() return week
def generate_week(hours, taken_week = None, latest_time = None): latest_time = latest_time or DEFAULT_LATEST_TIME longest_day = DEFAULT_LONGEST_DAY week = Week() day = 0 while hours > Hours(0): assert(day < 7) taken_hours = taken_week.get_day(day) if taken_week != None else None generated_day = generate_day(longest_day if hours > longest_day else hours, taken_hours, latest_time) if generated_day.get_length().get_total_minutes() > 0: week.set_day(day, generated_day) day += 1 hours -= generated_day.get_length() return week
def test_can_be_concatenated(self): w1 = Week() w2 = Week() w1.set_day(0, TimeRange(Time(8, 30), Time(13, 30))) w2.set_day(0, TimeRange(Time(13, 30), Time(17))) w1.set_day(1, TimeRange(Time(7), Time(12))) w2.set_day(2, TimeRange(Time(8), Time(13))) w3 = w1 + w2 self.assertEquals(w3.get_day(0), TimeRange(Time(8, 30), Time(17))) self.assertEquals(w3.get_day(1), TimeRange(Time(7), Time(12))) self.assertEquals(w3.get_day(2), TimeRange(Time(8), Time(13)))
def test_generates_realistic_schedule(self): taken_week = Week() taken = [ TimeRange(Time(8, 30), Time(13, 30)), TimeRange(Time(6, 30), Time(13, 30)), TimeRange(Time(7), Time(17)), TimeRange(Time(6, 30), Time(13, 30)) ] for i in xrange(len(taken)): taken_week.set_day(i, taken[i]) week = generate_week(Hours(30, 20), taken_week) ranges = [ TimeRange(Time(13, 30), Time(20)), # 23:50 left TimeRange(Time(13, 30), Time(20)), # 17:20 left TimeRange(Time(17), Time(20)), # 14:20 left TimeRange(Time(13, 30), Time(20)), # 7:50 left TimeRange(Time(7), Time(14, 50)) ] # 0:00 left for i in xrange(len(ranges)): self.assertEquals(week.get_day(i), ranges[i])
def test_can_add_week_52_of_previous_year_to_january(self): m = Month(2012, 1) w = Week() w.set_day(6, TimeRange(Time(7), Time(10))) m.add_week(52, w) self.assertEquals(m.get_day(1), TimeRange(Time(7), Time(10)))
def test_can_add_week_1_of_next_year_to_december(self): m = Month(2012, 12) w = Week() w.set_day(0, TimeRange(Time(7), Time(10))) m.add_week(1, w) self.assertEquals(m.get_day(31), TimeRange(Time(7), Time(10)))
def test_can_report_total_hours_and_minutes(self): w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) w.set_day(1, TimeRange(Time(10), Time(10, 30))) self.assertEquals(w.get_total_time(), Hours(10, 30))
def test_can_be_modified_with_latest_time(self): taken_week = Week() taken_week.set_day(0, TimeRange(Time(7), Time(17))) week = generate_week(Hours(40), taken_week, Time(22)) self.assertEquals(week.get_day(0), TimeRange(Time(17), Time(22)))
def _get_daycare_week(self): w = Week() w.set_day(0, TimeRange(Time(8, 30), Time(13, 30))) w.set_day(1, TimeRange(Time(8, 30), Time(13, 30))) w.set_day(3, TimeRange(Time(8, 30), Time(13, 30))) return w
def test_can_enter_times_from_second_week(self): m = Month(2012, 10) w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) m.add_week(41, w) self.assertEquals(m.get_day(8), TimeRange(Time(7), Time(17)))
def test_can_return_week(self): m = Month(2012, 10) w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) m.add_week(40, w) self.assertEquals(m.get_week(40).get_day(0), TimeRange(Time(7), Time(17)))
def test_returns_annotated_weeks(self): m = Month(2012, 10) w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) m.add_week(40, w) self.assertEquals(type(m.get_week(40)), AnnotatedWeek)
def test_can_set_day(self): w = Week() w.set_day(0, TimeRange(Time(7), Time(17))) self.assertEquals(w.get_day(0), TimeRange(Time(7), Time(17)))