示例#1
0
 def test_merge_overlappings(self):
     self.assertEqual(
         interval.mergeOverlapping(
             '[-10,-7], (-8,1], [3,6), (4,12), [15,23]'),
         '[-10,1], [3,12), [15,23]')
     self.assertEqual(
         interval.mergeOverlapping('[1,5],[2,6),(8,10],[8,18]'),
         '[1,5], [8,18]')
示例#2
0
def main():
    """
    Prompts user for intervals, which it merges. Exits on "quit".
    """
    intlist = []
    while True:
        try:
            inp = input('List of intervals? ')
            if inp == "quit":
                return
            intlist = interval.parseList(inp)
            intlist = interval.mergeOverlapping(intlist)
            interval.printList(intlist)
            break
        except (IntervalError, ValueError):
            print('Error inputting intervals')
    while True:
        istr = input('interval? ')
        if istr == "quit":
            break
        try:
            val = interval(istr)
            intlist = interval.insert(intlist, val)
            interval.printList(intlist)
        except (IntervalError, ValueError):
            print('Invalid interval')
示例#3
0
def main():
	while True:
		try:
			list_of_intervals = input("List of intervals? ")
			if list_of_intervals == 'quit':
				print ('')
				sys.exit(1)

			list_of_intervals = interval.mergeOverlapping(list_of_intervals)
			break
		except KeyboardInterrupt:
			sys.exit(1)
		except Exception:
			print ('Invalid list of intervals')
			pass

	while True:
		try:
			interv = input('Interval? ')
			if interv == 'quit':
				print ('')
				break
			else:
				interval(interv)
				list_of_intervals = interval.insert(list_of_intervals, interv)
				print (list_of_intervals)
		except KeyboardInterrupt:
			sys.exit(1)
		except:
			print ('Invalid interval')
示例#4
0
def main() :
    """
    Prompts user for intervals, which it merges. Exits on "quit".
    """
    intlist = []
    while True :
        try :
            inp = input('List of intervals? ')
            if inp == "quit":
                return
            intlist = interval.parseList(inp)
            intlist = interval.mergeOverlapping(intlist)
            interval.printList(intlist)
            break
        except (IntervalError, ValueError):
            print('Error inputting intervals')
    while True :
        istr = input('interval? ')
        if istr == "quit" :
            break
        try :
            val = interval(istr)
            intlist = interval.insert(intlist,val)
            interval.printList(intlist)
        except (IntervalError, ValueError) :
            print('Invalid interval')
示例#5
0
 def test_mergeOverlapping(self):
     ## testing examples:
     int1 = interval('[1,3]')
     int2 = interval('[2,4]')
     int3 = interval('[4,5]')
     int5 = interval('[7,10]')
     int6 = interval('[8,12]')
     int7 = interval('[11,13]')
     mergedInt123 = interval('[1,5]')
     mergedInt56 = interval('[7,12]')
     mergedInt57 = interval('[7,13]')
     mergedInts = [mergedInt123,mergedInt56]
     adjmergedInts = [mergedInt123,mergedInt57]
     nonmergedInts = [int1,int5]
     ## test merged lists:
     self.assertEqual(interval.mergeOverlapping([int1,int2,int3,int5,int6]), mergedInts)
     ## test adjacent merges:
     self.assertEqual(interval.mergeOverlapping([int1,int3,int5,int7]), adjmergedInts)
     ## test non-merge
     self.assertEqual(interval.mergeOverlapping([int1,int5]), nonmergedInts)
示例#6
0
 def test_mergeOverlapping(self):
     ## testing examples:
     int1 = interval('[1,3]')
     int2 = interval('[2,4]')
     int3 = interval('[4,5]')
     int5 = interval('[7,10]')
     int6 = interval('[8,12]')
     int7 = interval('[11,13]')
     mergedInt123 = interval('[1,5]')
     mergedInt56 = interval('[7,12]')
     mergedInt57 = interval('[7,13]')
     mergedInts = [mergedInt123, mergedInt56]
     adjmergedInts = [mergedInt123, mergedInt57]
     nonmergedInts = [int1, int5]
     ## test merged lists:
     self.assertEqual(
         interval.mergeOverlapping([int1, int2, int3, int5, int6]),
         mergedInts)
     ## test adjacent merges:
     self.assertEqual(interval.mergeOverlapping([int1, int3, int5, int7]),
                      adjmergedInts)
     ## test non-merge
     self.assertEqual(interval.mergeOverlapping([int1, int5]),
                      nonmergedInts)
    def test_mergeOverlapping(self):

        # test to merge a list of intervals
        
        self.assertEquals(interval.mergeOverlapping(self.list),[self.interval3, self.interval4])
示例#8
0
 def test_merge_overlappings(self):
     self.assertEqual(
         interval.mergeOverlapping("[-10,-7], (-8,1], [3,6), (4,12), [15,23]"), "[-10,1], [3,12), [15,23]"
     )
     self.assertEqual(interval.mergeOverlapping("[1,5],[2,6),(8,10],[8,18]"), "[1,5], [8,18]")