Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
 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]'])
Esempio n. 4
0
 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]]");
Esempio n. 5
0
 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]"])
Esempio n. 6
0
 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]]")