def test_insert(self): input_1 = '(-9, -6], [1, 16], [24, 36)' input_2 = '(16, 24)' result = Interval.insert(input_1, input_2) int_1 = result[0] int_2 = result[1] self.assertTrue(int_1) self.assertEqual(int_1.lower, -9) self.assertEqual(int_1.upper, -6) self.assertEqual(int_1.lowerBound, "(") self.assertEqual(int_1.upperBound, "]") self.assertTrue(int_2) self.assertEqual(int_2.lower, 1) self.assertEqual(int_2.upper, 36) self.assertEqual(int_2.lowerBound, "[") self.assertEqual(int_2.upperBound, ")")
user_input = raw_input("Interval?: ") if user_input == "quit": continue_flag = False else: try: # Validate the users interval input. Strips white spaces. user_input = user_input.strip().replace(' ', '') # Uses a regular expression to verify the format of the input lone_interval_pattern = '([\(|\[]-?\d+,-?\d+[\)|\]])' match = re.findall(lone_interval_pattern, user_input) # If there is a match continues with the program, if not, an exception is raised. if match: user_input = match[0] interval_to_insert = Interval(user_input) interval_objects_list = Interval.insert( interval_objects_list, interval_to_insert) print interval_objects_list else: raise IntervalException( "User Interval Input with invalid format. Try again") except IntervalException as e: print e except IntervalException as e: print "Interval Error:", e except ValueError as e: print "Interval Error:", e """ interval3 = Interval('[-10,-7]') interval4 = Interval('(-4,1]')
except: print("Invalid list") while True: addOn = input("interval? ") if addOn == "quit": print('Sorry to see you go.') sys.exit() try: test = Interval(addOn) except: print("Invalid Input") continue ans = Interval.insert(userInput, addOn) userInput = userInput + ', ' + addOn print(ans) # except: # print("Invalid Input") # while True: # try: # addOn = input("interval? ") # if addOn == "quit": # print('Sorry to see you go.') # sys.exit() # try: # ans = Interval.insert(userInput, addOn)
user_input = raw_input("Interval?: ") if user_input == "quit": continue_flag = False else: try: # Validate the users interval input. Strips white spaces. user_input = user_input.strip().replace(' ', '') # Uses a regular expression to verify the format of the input lone_interval_pattern = '([\(|\[]-?\d+,-?\d+[\)|\]])' match = re.findall(lone_interval_pattern, user_input) # If there is a match continues with the program, if not, an exception is raised. if match: user_input = match[0] interval_to_insert = Interval(user_input) interval_objects_list = Interval.insert(interval_objects_list, interval_to_insert) print interval_objects_list else: raise IntervalException("User Interval Input with invalid format. Try again") except IntervalException as e: print e except IntervalException as e: print "Interval Error:", e except ValueError as e: print "Interval Error:", e """ interval3 = Interval('[-10,-7]')
print("Invalid list") while True: addOn = input("interval? ") if addOn == "quit": print('Sorry to see you go.') sys.exit() try: test = Interval(addOn) except: print("Invalid Input") continue ans = Interval.insert(userInput, addOn) userInput = userInput + ', ' + addOn print(ans) # except: # print("Invalid Input") # while True: # try: # addOn = input("interval? ") # if addOn == "quit": # print('Sorry to see you go.') # sys.exit() # try: