def test_insert(self): self.assertEqual( str(interval.insert(["[1,3]", "[6,9]", "[3,6)"], "[2,5]")), '[[1, 9]]') self.assertEqual( str( interval.insert( ["[-10,-7]", "(-4,1]", "[3,6)", "(5,12)", "[11,23]"], "[4,8]")), '[[-10, -7], (-4, 1], [3, 23]]') self.assertRaises(ValueError, interval.insert, ["[1,3]", "[6,9]", "[3,6)"], interval.interval('(0,1)'))
def main(): interval_list = raw_input('List of intervals?') split_intlist=interval_list.split(", ") result = [interval(i) for i in split_intlist] try: split_intlist=interval_list.split(", ") result = [interval(i) for i in split_intlist] #list holds for the interval objects except ValueError: print('Invalid interval') except IndexError: print('Invalid interval') while True: input_str = raw_input('Interval?').lower() if input_str == 'quit': exit('End') try: newint = interval(input_str) result=insert(result,newint) str_re = [str(i) for i in result] join_str = ', '.join(str_re) print (join_str) except ValueError: print('Invalid interval')
def test_insert_2(self): intlist = [ interval('(-13,-5)'), interval('(-5,2]'), interval('(7,10]') ] self.assertEqual(str(insert(intlist, interval("[20,24]"))), '[(-13,-5), (-5,2], (7,10], [20,24]]')
def test_insert_3(self): intlist = [ interval('[-10,1]'), interval('[3,13)'), interval('[15,24]') ] self.assertEqual(str(insert(intlist, interval("[-2,5]"))), '[[-10,13), [15,24]]')
def test_insert_3(self): a = ['[1,3]', '[6,9]'] lst = [] for item in a: lst.append(interval.interval(item)) b = interval.interval('[4,5]') c = interval.insert(lst, b) self.assertEqual(str(c), '[[1,9]]')
def test_insert_2(self): a = ['[1,2]', '(3,5)', '[6,7)', '(8,10]', '[12,16]'] lst = [] for item in a: lst.append(interval.interval(item)) b = interval.interval('[4,9]') c = interval.insert(lst, b) self.assertEqual(str(c), '[[1,2], (3,10], [12,16]]')
def test_insert_4(self): a = ['[1,2)', '(2,9]'] lst = [] for item in a: lst.append(interval.interval(item)) b = interval.interval('(3,10]') c = interval.insert(lst, b) self.assertEqual(str(c), '[[1,2), (2,10]]')
def test_insert_1(self): intlist = [ interval('[-10,-7]'), interval('(-4,1]'), interval('[3,12)'), interval('[15,23]') ] self.assertEqual(str(insert(intlist, interval("[24,24]"))), '[[-10,-7], (-4,1], [3,12), [15,24]]')
def test_insert(self): """test the insert function""" int1 = interval('[1,2]') int2 = interval("(3,5)") int3 = interval("[6,7)") int4 = interval("(8,10]") int5 = interval("[12,16]") intervals_l = [int1, int2, int3, int4, int5] newint = interval("[4,9]") self.assertEqual(str(insert(intervals_l, newint)), str([interval("[1,2]"), interval("(3,10]"), interval("[12,16]")]))
def insert_interval_loop(intervals): while (True): try: input_string = ask_for_interval() newint = parse_interval_input(input_string) intervals = insert(intervals, newint) print interval_list_to_string(intervals) except (IntervalParseException, InvalidIntervalException): print "Invalid interval" except Exception as e: raise e
def prompt_user(): """get list of intervals to start, then get one more interval at a time. 'quit' or ctrl+c exits""" active_intervals = [] while True: try: user_input = input("List of intervals?") if user_input.lower() == 'quit': return # Raises a ValueError and loops back if user_input is not correctly structured # as a sequence of intervals active_intervals = interval.get_interval_list(user_input) break except KeyboardInterrupt: # Exit if the user enters Ctrl+C sys.exit(0) except EOFError: # Exit if the user enters Ctrl+D sys.exit(0) except ValueError: print("Invalid list of intervals") # active_intervals maintains a list of intervals merged from the user input so far # Here we iteratively ask for more intervals or exit while True: try: user_input = input("Interval?") if user_input.lower() == 'quit': return # Raises a ValueError and loops back if user_input is not a correctly structured interval active_intervals = interval.insert(active_intervals, interval.interval(user_input)) print(active_intervals) except KeyboardInterrupt: # Exit if the user enters Ctrl+C sys.exit(0) except EOFError: # Exit if the user enters Ctrl+D sys.exit(0) except ValueError: print("Invalid interval")
def test_insert(self): """test the insert function""" int1 = interval('[1,2]') int2 = interval("(3,5)") int3 = interval("[6,7)") int4 = interval("(8,10]") int5 = interval("[12,16]") intervals_l = [int1, int2, int3, int4, int5] newint = interval("[4,9]") self.assertEqual( str(insert(intervals_l, newint)), str([interval("[1,2]"), interval("(3,10]"), interval("[12,16]")]))
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
def main(): valid_intervals_list = False intervals_list = [] while not valid_intervals_list: try: input_string = input("List of intervals?") if input_string.lower() == "quit": return intervals_list = interval.get_intervals_list(input_string) valid_intervals_list = True except Exception as e: print(e) print("Invalid list of intervals") while True: try: input_string = input("Interval?") if input_string.lower() == "quit": return it = interval.Interval(input_string) intervals_list = interval.insert(intervals_list, it) print(intervals_list) except Exception as e: print(e)
def test_insert_3(self): intlist = [interval('[-10,1]'),interval('[3,13)'),interval('[15,24]')] self.assertEqual(str(insert(intlist,interval("[-2,5]"))), '[[-10,13), [15,24]]')
def test_insert_2(self): intlist = [interval('(-13,-5)'),interval('(-5,2]'),interval('(7,10]')] self.assertEqual(str(insert(intlist,interval("[20,24]"))), '[(-13,-5), (-5,2], (7,10], [20,24]]')
def test_insert_1(self): intlist = [interval('[-10,-7]'),interval('(-4,1]'),interval('[3,12)'),interval('[15,23]')] self.assertEqual(str(insert(intlist,interval("[24,24]"))), '[[-10,-7], (-4,1], [3,12), [15,24]]')
def test_insert_2(self): lst = ["[1,2]", "(3,5)", "[6,7)", "(8,10]", "[12,16]"] interval_list = [interval(i) for i in lst] str_re = [str(i) for i in insert(interval_list, interval("[4,9]")) ] join_str = ', '.join(str_re) self.assertEqual(join_str, "[1,2], (3,10], [12,16]")
def test_insert(self): lst = ["[1,3]", "[6,9]"] interval_list = [interval(i) for i in lst] str_re = [str(i) for i in insert(interval_list, interval("[2,5]")) ] join_str = ', '.join(str_re) self.assertEqual(join_str, "[1,9]")
def test_insert(self): self.assertEqual( str( list( map(lambda x, y: insert(x, y), self.insertList, self.insertInt))), self.answer_insert)
def test_insert(self): lst = ["[1,3]", "[6,9]"] interval_list = [interval(i) for i in lst] str_re = [str(i) for i in insert(interval_list, interval("[2,5]"))] join_str = ', '.join(str_re) self.assertEqual(join_str, "[1,9]")
def test_insert_2(self): lst = ["[1,2]", "(3,5)", "[6,7)", "(8,10]", "[12,16]"] interval_list = [interval(i) for i in lst] str_re = [str(i) for i in insert(interval_list, interval("[4,9]"))] join_str = ', '.join(str_re) self.assertEqual(join_str, "[1,2], (3,10], [12,16]")
if inputstring == "quit": sys.exit() inputstring = inputstring.replace(" ","") stringlist = inputstring.split(",") intervallist=[] for index in range(0,len(stringlist),2): thisstring = stringlist[index]+","+stringlist[index+1] intervallist.append(interval(thisstring)) break except KeyboardInterrupt: sys.exit() except Exception: print ('Invalid list input') pass while True: try: inputint = raw_input("Interval? ") if inputint =="quit": sys.exit() inputint = interval(inputint) intervallist = insert(intervallist,inputint) for thisint in intervallist: print(thisint), print("") except KeyboardInterrupt: sys.exit() except Exception: print ("Invalid interval")
def test_insert(self): self.assertEqual(str(list(map(lambda x,y: insert(x,y),self.insertList,self.insertInt))),self.answer_insert)
try: inputstring = raw_input("List of intervals? ") if inputstring == "quit": sys.exit() inputstring = inputstring.replace(" ", "") stringlist = inputstring.split(",") intervallist = [] for index in range(0, len(stringlist), 2): thisstring = stringlist[index] + "," + stringlist[index + 1] intervallist.append(interval(thisstring)) break except KeyboardInterrupt: sys.exit() except Exception: print('Invalid list input') pass while True: try: inputint = raw_input("Interval? ") if inputint == "quit": sys.exit() inputint = interval(inputint) intervallist = insert(intervallist, inputint) for thisint in intervallist: print(thisint), print("") except KeyboardInterrupt: sys.exit() except Exception: print("Invalid interval")
try: while True: x = raw_input('List of intervals? ') if x == 'quit': sys.exit() try: temp = x.split(', ') result = [interval(i) for i in temp] break except ValueError: print "Invalid Intervals.Expected input format: [1,2], [3,4]" except IndexError: print "empty input!" while True: y = raw_input('Intervals? ') if y == 'quit': sys.exit() try: newint = interval(y) except ValueError: print "Invalid Interval. Incorrect: Lower and upper bounds" else: result = insert(result, newint) str_result = [str(i) for i in result] print ', '.join(str_result) except KeyboardInterrupt, ValueError: print "\n Interrupted!" except EOFError: print "\n Interrupted!"
def test_insert(self): self.assertEqual(str(interval.insert(["[1,3]", "[6,9]", "[3,6)"], "[2,5]")), '[[1, 9]]') self.assertEqual(str(interval.insert(["[-10,-7]", "(-4,1]", "[3,6)","(5,12)","[11,23]"],"[4,8]")), '[[-10, -7], (-4, 1], [3, 23]]') self.assertRaises(ValueError, interval.insert, ["[1,3]", "[6,9]", "[3,6)"], interval.interval('(0,1)'))