Ejemplo n.º 1
0
    def test_contains(self):
        slot = Slot(2, 7) # [2, 7]
        self.assertEqual(slot.contains(1, 2), False)
        self.assertEqual(slot.contains(1, 3), False)
        
        self.assertEqual(slot.contains(2, 3), True)
        self.assertEqual(slot.contains(2, 7), True)

        self.assertEqual(slot.contains(2, 7.5), False)
        self.assertEqual(slot.contains(7, 8), False)
Ejemplo n.º 2
0
    def test_fill(self):
        slot = Slot(2, 7) # [2, 7]
        # Should raise exception if trying to fill slot with something that doesn't fit
        self.assertRaises(Exception, slot.fill, 1, 2)

        # If fully fills slot, return empty array
        self.assertEqual(slot.fill(2, 7), [])

        self.assertEqual(slot.fill(2, 3), [Slot(3, 7)])
        self.assertEqual(slot.fill(3, 4), [Slot(2, 3), Slot(4, 7)])
        self.assertEqual(slot.fill(5, 7), [Slot(2, 5)])
Ejemplo n.º 3
0
    def test_fill(self):
        slot = Slot(2, 7)  # [2, 7]
        # Should raise exception if trying to fill slot with something that doesn't fit
        self.assertRaises(Exception, slot.fill, 1, 2)

        # If fully fills slot, return empty array
        self.assertEqual(slot.fill(2, 7), [])

        self.assertEqual(slot.fill(2, 3), [Slot(3, 7)])
        self.assertEqual(slot.fill(3, 4), [Slot(2, 3), Slot(4, 7)])
        self.assertEqual(slot.fill(5, 7), [Slot(2, 5)])
Ejemplo n.º 4
0
    def test_find_slot(self):
        timeline = Timeline(util.nov1)
        my_slot, containing_slot_index = timeline.find_slot(4, 0.5)
        self.assertEqual(Slot(4, 4.5), my_slot)
        self.assertEqual(0, containing_slot_index)

        # Test where prefered slot is not available
        timeline.slots = [Slot(1, 3), Slot(4, float('inf'))]
        my_slot, containing_slot_index = timeline.find_slot(0, 2.5)
        self.assertEqual(Slot(4, 6.5), my_slot)
        self.assertEqual(1, containing_slot_index)

        # Check that the slot dates are correct
        self.assertEqual(util.nov7, my_slot.start_date)
        self.assertEqual(util.nov9, my_slot.end_date)
        return
Ejemplo n.º 5
0
 def test_find_slot_with_ending_date2(self):
     # This tests an infinite loop case
     delta1 = timedelta(0.25)
     timeline = Timeline(util.nov1 + delta1)
     my_slot, containing_slot_index = timeline.find_slot_with_ending_date(
         util.nov7, 0.1)
     self.assertEqual(Slot(4.4, 4.5), my_slot)
     return
Ejemplo n.º 6
0
    def find_slot(self, earliest_start_day, width):
        # Default to the last, infinite slot
        start_day, end_day = update_days(self.slots[-1].start_day, width)
        new_slot = Slot(start_day, end_day)
        containing_slot_index = len(self.slots) - 1

        modify_start_date = False
        start_day, end_day = update_days(earliest_start_day, width)
        for i, s in enumerate(self.slots):
            if modify_start_date:
                start_day, end_day = update_days(s.start_day, width)
            if s.contains(start_day, end_day):
                new_slot = Slot(start_day, end_day)
                containing_slot_index = i
                break
            else:
                modify_start_date = True

        # Set slot dates
        new_slot.start_date = self.date_from_day(new_slot.start_day)
        new_slot.end_date = self.date_from_day(new_slot.end_day)
        return new_slot, containing_slot_index
Ejemplo n.º 7
0
    def test_contains(self):
        slot = Slot(2, 7)  # [2, 7]
        self.assertEqual(slot.contains(1, 2), False)
        self.assertEqual(slot.contains(1, 3), False)

        self.assertEqual(slot.contains(2, 3), True)
        self.assertEqual(slot.contains(2, 7), True)

        self.assertEqual(slot.contains(2, 7.5), False)
        self.assertEqual(slot.contains(7, 8), False)
Ejemplo n.º 8
0
    def find_slot(self, earliest_start_day, width):
        # Default to the last, infinite slot
        start_day, end_day = update_days(self.slots[-1].start_day, width)
        new_slot = Slot(start_day, end_day)
        containing_slot_index = len(self.slots) - 1

        modify_start_date = False
        start_day, end_day = update_days(earliest_start_day, width)
        for i, s in enumerate(self.slots):
            if modify_start_date:
                start_day, end_day = update_days(s.start_day, width)
            if s.contains(start_day, end_day):
                new_slot = Slot(start_day, end_day)
                containing_slot_index = i
                break
            else:
                modify_start_date = True

        # Set slot dates
        new_slot.start_date = self.date_from_day(new_slot.start_day)
        new_slot.end_date = self.date_from_day(new_slot.end_day)
        return new_slot, containing_slot_index
Ejemplo n.º 9
0
 def __init__(self, cur_date):
     self.slots = [Slot(0, float('inf'))]
     self.cur_date = dovetail.util.standardize_date(cur_date)
     self.dates = []
Ejemplo n.º 10
0
 def test_find_slot_with_ending_date(self):
     timeline = Timeline(util.nov1)
     my_slot, containing_slot_index = timeline.find_slot_with_ending_date(
         util.nov7, 0.1)
     self.assertEqual(Slot(4.4, 4.5), my_slot)
     return
Ejemplo n.º 11
0
 def test_claim_slot_on_partially_filled_days(self):
     timeline = Timeline(util.nov1)
     timeline.claim_slot(Slot(4, 4.5), 0)
     my_slot, containing_slot_index = timeline.find_slot(4.1, 0.5)
     self.assertEqual(Slot(4.5, 5), my_slot)
     return
Ejemplo n.º 12
0
 def test_claim_slot(self):
     timeline = Timeline(util.nov1)
     timeline.claim_slot(Slot(4, 4.5), 0)
     self.assertEqual([Slot(0, 4), Slot(4.5, float('inf'))], timeline.slots)
     return
Ejemplo n.º 13
0
 def test_find_slot_at_end(self):
     timeline = Timeline(util.nov1)
     timeline.claim_slot(Slot(0, 1.0), 0)
     my_slot, containing_slot_index = timeline.find_slot(0, 1.0)
     return