def test_merge_blocker_single_element(self): combined_blocker_list = [ Block(datetime(2018, 7, 20, 12, 0, 0), datetime(2018, 7, 20, 12, 30, 0), 'A'), ] result = _merge_blocker_list(combined_blocker_list) expected = [ Block(datetime(2018, 7, 20, 12, 0, 0), datetime(2018, 7, 20, 12, 30, 0), 'A') ] self.assertEqual(result, expected)
def test_merge_blocker_multiple_overlap(self): combined_blocker_list = [ Block(datetime(2018, 7, 20, 12, 0, 0), datetime(2018, 7, 20, 12, 30, 0), 'A'), Block(datetime(2018, 7, 20, 12, 30, 0), datetime(2018, 7, 20, 13, 0, 0), 'B'), Block(datetime(2018, 7, 20, 13, 00, 0), datetime(2018, 7, 20, 13, 30, 0), 'A'), ] result = _merge_blocker_list(combined_blocker_list) expected = [ Block(datetime(2018, 7, 20, 12, 0, 0), datetime(2018, 7, 20, 13, 30, 0), 'M') ] self.assertEqual(result, expected)
def test_return_available_window_valid_window(self): ''' start end 12pm 1pm 2pm 3pm |--------------------------------| block |----------| |----------| result |----------| ''' start = datetime(2018, 7, 20, 12, 0, 0) end = datetime(2018, 7, 20, 15, 0, 0) previous_block = Block(datetime(2018, 7, 20, 12, 0), datetime(2018, 7, 20, 13, 0), 'X') next_block = Block(datetime(2018, 7, 20, 14, 0), datetime(2018, 7, 20, 15, 0), 'X') self.assertEqual( _return_available_window(previous_block, next_block, start, end), (datetime(2018, 7, 20, 13, 0), datetime(2018, 7, 20, 14, 0)))
def test_merge_blocker_with_blocker_larger_and_overlapping_several(self): ''' 12 13 14 A |---------------------| B |----| B |----| ''' combined_blocker_list = [ Block(datetime(2018, 7, 20, 12, 0, 0), datetime(2018, 7, 20, 14, 0, 0), 'A'), Block(datetime(2018, 7, 20, 12, 30, 0), datetime(2018, 7, 20, 13, 0, 0), 'B'), Block(datetime(2018, 7, 20, 13, 30, 0), datetime(2018, 7, 20, 14, 0, 0), 'B'), ] result = _merge_blocker_list(combined_blocker_list) expected = [ Block(datetime(2018, 7, 20, 12, 0, 0), datetime(2018, 7, 20, 14, 0, 0), 'A') ] self.assertEqual(result, expected)
def test_return_available_window_no_next_block(self): ''' start end 12pm 1230 1pm |------------| block |------| result |-----| ''' start = datetime(2018, 7, 20, 12, 0, 0) end = datetime(2018, 7, 20, 13, 0, 0) previous_block = Block(datetime(2018, 7, 20, 12, 0), datetime(2018, 7, 20, 12, 30), 'X') next_block = None self.assertEqual( _return_available_window(previous_block, next_block, start, end), (datetime(2018, 7, 20, 12, 30), end))
def test_return_available_window_single_overlapping_block(self): ''' start end 12pm 1pm |------------| block |------------| result No window ''' start = datetime(2018, 7, 20, 12, 0, 0) end = datetime(2018, 7, 20, 13, 0, 0) previous_block = Block(datetime(2018, 7, 20, 12, 0), datetime(2018, 7, 20, 13, 0), 'X') next_block = None self.assertEqual( _return_available_window(previous_block, next_block, start, end), None)