def insert(intervals, newint): #Combine all the intervals together intervals.append(newint) #Merge all the intervals merge_intervals = mergeOverlapping(intervals) #Order the merged intervals merge_intervals = sorted(merge_intervals, key=lambda x: x[0]) return merge_intervals
def insert(intervals,newint): #Combine all the intervals together intervals.append(newint); #Merge all the intervals merge_intervals=mergeOverlapping(intervals); #Order the merged intervals merge_intervals=sorted(merge_intervals,key=lambda x:x[0]); return merge_intervals
def test_question_3_Error(self): with self.assertRaises(ValueError): value=mergeOverlapping(['()', '[0,15]']) with self.assertRaises(ValueError): value=mergeOverlapping(['(1,-1)', '[a,b]','(c,2]'])
def test_question_3(self): self.assertEqual(str(mergeOverlapping(['[-1,3]', '(10,15)'])),"[[-1, 3], [11, 14]]"); self.assertEqual(str(mergeOverlapping(['[-1,3)', '(4,15]'])),"[[-1, 2], [5, 15]]"); self.assertEqual(str(mergeOverlapping(['[-1,3)', '(4,15]', '[2,5]'])),"[[-1, 15]]"); self.assertEqual(str(mergeOverlapping(['(-10,3)', '[4,15]', '(-16,-10]'])),"[[-15, 2], [4, 15]]"); self.assertEqual(str(mergeOverlapping(['(-10,3)', '[4,15]', '(-16,-10]','[-20,-8)'])),"[[-20, 2], [4, 15]]");
def test_question_3_Error(self): with self.assertRaises(ValueError): value = mergeOverlapping(["()", "[0,15]"]) with self.assertRaises(ValueError): value = mergeOverlapping(["(1,-1)", "[a,b]", "(c,2]"])
def test_question_3(self): self.assertEqual(str(mergeOverlapping(["[-1,3]", "(10,15)"])), "[[-1, 3], [11, 14]]") self.assertEqual(str(mergeOverlapping(["[-1,3)", "(4,15]"])), "[[-1, 2], [5, 15]]") self.assertEqual(str(mergeOverlapping(["[-1,3)", "(4,15]", "[2,5]"])), "[[-1, 15]]") self.assertEqual(str(mergeOverlapping(["(-10,3)", "[4,15]", "(-16,-10]"])), "[[-15, 2], [4, 15]]") self.assertEqual(str(mergeOverlapping(["(-10,3)", "[4,15]", "(-16,-10]", "[-20,-8)"])), "[[-20, 2], [4, 15]]")