def test_mergeOverlapping(self):
        self.assertEqual(
            str(
                interval.mergeOverlapping([
                    '[-10, -7]', '(-4, 1]', '[3, 6)', '(8,12)', "[15,23]",
                    "[4,8]"
                ])), '[[-10, -7], (-4, 1], [3, 12), [15, 23]]')
        self.assertEqual(
            str(
                interval.mergeOverlapping(
                    ["[1,5]", "[2,6)", "(8,10]", "[8,18]"])),
            '[[1, 6), [8, 18]]')

        self.assertRaises(ValueError, interval.mergeOverlapping,
                          ["[1,5]", "[2,6)", "(8,10]", "(0,0)"])
Exemple #2
0
 def test_mergeOverlapping_4(self):
     a = ['[1,5)', '(5,7]', '(7,10]']
     lst = []
     for item in a:
         lst.append(interval.interval(item))
     b = interval.mergeOverlapping(lst)
     self.assertEqual(str(b), '[[1,5), (5,10]]')
Exemple #3
0
 def test_mergeOverlapping_3(self):
     a = ['[1,5)', '(2,4]', '[5,6]']
     lst = []
     for item in a:
         lst.append(interval.interval(item))
     b = interval.mergeOverlapping(lst)
     self.assertEqual(str(b), '[[1,6]]')
Exemple #4
0
 def test_mergeOverlapping_1(self):
     intlist = [
         interval('[-10,-7]'),
         interval('(-7,1]'),
         interval('[3,12)'),
         interval('[10,23]')
     ]
     self.assertEqual(str(mergeOverlapping(intlist)), '[[-10,1], [3,23]]')
    def test_mergeOverlapping(self):
        """test the mergeOverlapping function"""
        int1 = interval("[1,5]")
        int2 = interval("[2,6)")
        int3 = interval("(8,10]")
        int4 = interval("[8,18]")
        interval_for_merge = [int1, int2, int3, int4]

        merged_list = [interval("[1,6)"), interval("[8,18]")]
        self.assertEqual(str(mergeOverlapping(interval_for_merge)), str(merged_list))
    def test_mergeOverlapping(self):
        """test the mergeOverlapping function"""
        int1 = interval("[1,5]")
        int2 = interval("[2,6)")
        int3 = interval("(8,10]")
        int4 = interval("[8,18]")
        interval_for_merge = [int1, int2, int3, int4]

        merged_list = [interval("[1,6)"), interval("[8,18]")]
        self.assertEqual(str(mergeOverlapping(interval_for_merge)),
                         str(merged_list))
Exemple #7
0
def loop():
    # loop for input of the first list
    while True:   
        try:
            init_IntervalList = input("List of intervals? ")
            init_IntervalList = init_IntervalList.replace(' ', '')
            if init_IntervalList.upper() == 'QUIT':
                exit('End')
            else:
                Intervals=init_IntervalList.split(',')
                IntervalList=[]
                i=0
                if len(Intervals)%2:
                    raise InputError
                else:
                    while (i<len(Intervals)):
                        interval=Intervals[i]+','+Intervals[i+1]
                        i=i+2
                        IntervalList.append(Interval(interval))
                    IntervalList = mergeOverlapping(IntervalList)  
                    break
        except InputError:
            print('Invalid interval!')
            pass
    #loop for Input Interval
    while True:   
        try:
            init_Interval = input("Interval? ")
            init_Interval = init_Interval.replace(' ', '')
            if init_Interval.upper() == 'QUIT':
                exit('End')
            else:
                new_interval = Interval(init_Interval)
                IntervalList = insert(IntervalList,new_interval)
                print (*IntervalList,sep=',')
        except InputError:
            print('Invalid interval!')
            pass
Exemple #8
0
 def test_mergeOverlapping_1(self):
     intlist = [interval('[-10,-7]'),interval('(-7,1]'),interval('[3,12)'),interval('[10,23]')]
     self.assertEqual(str(mergeOverlapping(intlist)), '[[-10,1], [3,23]]')
Exemple #9
0
 def test_mergeOverlapping_2(self):
     lst =  ["[1,3]","[2,6)" , "[5,7]" , "[10,12]"]
     interval_list =  [interval(i) for i in lst]
     str_re = [str(i) for i in mergeOverlapping(interval_list)] 
     join_str = ', '.join(str_re)
     self.assertEqual(join_str, "[1,7], [10,12]")
Exemple #10
0
 def test_mergeOverlapping_3(self):
     lst =  ["[1,4]","(3,5)" , "[6,7)" , "(8,10]", "[12,16]"]
     interval_list =  [interval(i) for i in lst]
     str_re = [str(i) for i in mergeOverlapping(interval_list)] 
     join_str = ', '.join(str_re)
     self.assertEqual(join_str, "[1,5), [6,7), (8,10], [12,16]")
Exemple #11
0
 def test_mergeOverlapping_3(self):
     intlist = [interval('[10,11]'), interval('(5,16]')]
     self.assertEqual(str(mergeOverlapping(intlist)), '[(5,16]]')
Exemple #12
0
 def test_mergeOverlapping(self):
     lst =  ["[1,5]","[2,6)" , "(8,10]" , "[8,18]"]
     interval_list =  [interval(i) for i in lst]
     str_re = [str(i) for i in mergeOverlapping(interval_list)] 
     join_str = ', '.join(str_re)
     self.assertEqual(join_str, "[1,6), [8,18]")  
 def test_mergeOverlapping(self):
     self.assertEqual(
         str(list(map(lambda x: mergeOverlapping(x),
                      self.test_Overlapping))), self.answer_Overlapping)
Exemple #14
0
 def test_mergeOverlapping_2(self):
     intlist = [interval('(-1,3]'), interval('(5,9]'), interval('[11,12)')]
     self.assertEqual(str(mergeOverlapping(intlist)),
                      '[(-1,3], (5,9], [11,12)]')
 def test_mergeOverlapping(self):
     self.assertEqual(str(list(map(lambda x: mergeOverlapping(x),self.test_Overlapping))),self.answer_Overlapping)
Exemple #16
0
 def test_mergeOverlapping(self):
     lst = ["[1,5]", "[2,6)", "(8,10]", "[8,18]"]
     interval_list = [interval(i) for i in lst]
     str_re = [str(i) for i in mergeOverlapping(interval_list)]
     join_str = ', '.join(str_re)
     self.assertEqual(join_str, "[1,6), [8,18]")
Exemple #17
0
 def test_mergeOverlapping_2(self):
     intlist = [interval('(-1,3]'),interval('(5,9]'),interval('[11,12)')]
     self.assertEqual(str(mergeOverlapping(intlist)), '[(-1,3], (5,9], [11,12)]')
Exemple #18
0
 def test_mergeOverlapping_3(self):
     lst = ["[1,4]", "(3,5)", "[6,7)", "(8,10]", "[12,16]"]
     interval_list = [interval(i) for i in lst]
     str_re = [str(i) for i in mergeOverlapping(interval_list)]
     join_str = ', '.join(str_re)
     self.assertEqual(join_str, "[1,5), [6,7), (8,10], [12,16]")
Exemple #19
0
 def test_mergeOverlapping_2(self):
     lst = ["[1,3]", "[2,6)", "[5,7]", "[10,12]"]
     interval_list = [interval(i) for i in lst]
     str_re = [str(i) for i in mergeOverlapping(interval_list)]
     join_str = ', '.join(str_re)
     self.assertEqual(join_str, "[1,7], [10,12]")
Exemple #20
0
 def test_mergeOverlapping_3(self):
     intlist = [interval('[10,11]'),interval('(5,16]')]
     self.assertEqual(str(mergeOverlapping(intlist)), '[(5,16]]')
Exemple #21
0
 def test_mergeOverlapping(self):
     self.assertEqual(str(interval.mergeOverlapping(['[-10, -7]', '(-4, 1]', '[3, 6)', '(8,12)', "[15,23]", "[4,8]"])), '[[-10, -7], (-4, 1], [3, 12), [15, 23]]')
     self.assertEqual(str(interval.mergeOverlapping(["[1,5]", "[2,6)", "(8,10]", "[8,18]"])), '[[1, 6), [8, 18]]')
     
     self.assertRaises(ValueError, interval.mergeOverlapping, ["[1,5]", "[2,6)", "(8,10]", "(0,0)"])