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]')
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')
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')
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')
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): ## 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])
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]")