def test_InsertInt(self): self.assertEqual( interval.to_string( interval.insert( [interval('[1,3]'), interval('[6,9]')], interval('[2,5]'))), '[1,9]') self.assertEqual( interval.to_string( interval.insert([ interval('[1,2]'), interval('(3,5)'), interval('[6,7)'), interval('(8,10]'), interval('[12,16]') ], interval('[4,9]'))), '[1,2], (3,10], [12,16]')
if input_string == "quit": sys.exit(1) input_string = input_string.replace(" ", "") string_list = input_string.split(",") list_interval = [] for i in range(0, len(string_list), 2): list_interval.append( interval(string_list[i] + ',' + string_list[i + 1])) list_interval = interval.mergeOverlapping(list_interval) print(interval.to_string(list_interval)) break except KeyboardInterrupt: sys.exit(1) except Exception: print('Invalid list of intervals') pass while True: try: inp = input("Interval? ") if inp == "quit": sys.exit(1) break else: inp = interval(inp) list_interval = interval.insert(list_interval, inp) print(interval.to_string(list_interval)) except KeyboardInterrupt: sys.exit(1) except Exception: print("Invalid interval")
input_string = input("List of intervals? ") if input_string == "quit": sys.exit(1) input_string = input_string.replace(" ","") string_list = input_string.split(",") list_interval=[] for i in range(0,len(string_list),2): list_interval.append(interval(string_list[i]+','+string_list[i+1])) list_interval = interval.mergeOverlapping(list_interval) print (interval.to_string(list_interval)) break except KeyboardInterrupt: sys.exit(1) except Exception: print ('Invalid list of intervals') pass while True: try: inp = input("Interval? ") if inp =="quit": sys.exit(1) break else: inp = interval(inp) list_interval = interval.insert(list_interval,inp) print (interval.to_string(list_interval)) except KeyboardInterrupt: sys.exit(1) except Exception: print ("Invalid interval")
def test_InsertInt(self): self.assertEqual(interval.to_string(interval.insert([interval('[1,3]'),interval('[6,9]')], interval('[2,5]'))), '[1,9]') self.assertEqual(interval.to_string(interval.insert([interval('[1,2]'),interval('(3,5)'),interval('[6,7)'),interval('(8,10]'),interval('[12,16]')], interval('[4,9]'))), '[1,2], (3,10], [12,16]')