Пример #1
0
 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))
Пример #2
0
 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)))
Пример #3
0
 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)))
Пример #4
0
 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))
Пример #5
0
 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)))
Пример #6
0
    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)
Пример #7
0
 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)))
Пример #8
0
 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)))
Пример #9
0
    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)
Пример #10
0
    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))
Пример #11
0
    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))
Пример #12
0
    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))
Пример #13
0
    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))
Пример #14
0
    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))
Пример #15
0
    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))
Пример #16
0
 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)
Пример #17
0
 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)
Пример #18
0
    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""")
Пример #19
0
 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])
Пример #20
0
    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""")
Пример #21
0
    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))
Пример #22
0
    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))
Пример #23
0
 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])
Пример #24
0
 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
Пример #25
0
 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
Пример #26
0
    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])
Пример #27
0
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
Пример #28
0
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
Пример #29
0
    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)))
Пример #30
0
    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)))
Пример #31
0
    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])
Пример #32
0
 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)))
Пример #33
0
 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)))
Пример #34
0
 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)))
Пример #35
0
 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)))
Пример #36
0
    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))
Пример #37
0
 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)))
Пример #38
0
 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)))
Пример #39
0
 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
Пример #40
0
 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
Пример #41
0
    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))
Пример #42
0
 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)))
Пример #43
0
 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)))
Пример #44
0
 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)
Пример #45
0
 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)
Пример #46
0
 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)))
Пример #47
0
 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)))
Пример #48
0
 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)))