def test_question_4(self): self.assertEqual(str(insert(["[-1,3]", "(10,15)"], "[5,10]")), "[[-1, 3], [5, 14]]") self.assertEqual(str(insert(["[-1,3]", "(10,15)"], "[20,30)")), "[[-1, 3], [11, 14], [20, 29]]") self.assertEqual(str(insert(["(-1,3]", "(10,15)", "[16,20]", "[22,31)"], "(2,15]")), "[[0, 20], [22, 30]]") self.assertEqual(str(insert(["(-1,3]", "(10,15)", "[16,20]", "[22,31)"], "[-2,23)")), "[[-2, 30]]") self.assertEqual( str(insert(["(-1,3]", "(10,15)", "[16,20]", "[-15,-1)"], "[-2,9)")), "[[-15, 8], [11, 14], [16, 20]]" )
def test_question_4_Error(self): with self.assertRaises(ValueError): value=insert(['()', '[s,n]'], '(1,2)') with self.assertRaises(ValueError): value=insert(['()', '[3,4]'], '(1,6)')
def test_question_4(self): self.assertEqual(str(insert(['[-1,3]', '(10,15)'],'[5,10]')),"[[-1, 3], [5, 14]]"); self.assertEqual(str(insert(['[-1,3]', '(10,15)'],'[20,30)')),"[[-1, 3], [11, 14], [20, 29]]"); self.assertEqual(str(insert(['(-1,3]', '(10,15)', '[16,20]', '[22,31)'],'(2,15]')),"[[0, 20], [22, 30]]"); self.assertEqual(str(insert(['(-1,3]', '(10,15)', '[16,20]', '[22,31)'],'[-2,23)')),"[[-2, 30]]"); self.assertEqual(str(insert(['(-1,3]', '(10,15)', '[16,20]', '[-15,-1)'],'[-2,9)')),"[[-15, 8], [11, 14], [16, 20]]");
#Justify if the intervals are valid n=len(interval_list); for i in range(n): s=interval(interval_list[i]) if str(s)=='The interval is not valid': break #The next process will be ignored if no valid interval list has been inputed if user_list!='quit': #Change the interval list to a list of interval strings merge_int=interval_list; d=len(merge_int); #Let the author input the insert interval user_insert=input("Interval? Quit the program by entering quit\n"); #If we do not input quit, we will check the validity of the input interval while user_insert!='quit': #If the interval is correct, we will merge the interval and ask next one s=interval(user_insert); if str(s)!='The interval is not valid': merge_int=insert(merge_int,user_insert); print(merge_int); d=len(merge_int); for i in range(d): merge_int[i]=str(merge_int[i]); user_insert=input("Please input next interval. Intervals? Quit the program by entering quit\n"); #If the interval is not correct, we will ask the user to re-input until correct or quit while str(s)=='The interval is not valid': user_insert=input("The interval is not valid, please input again. Intervals? Quit the program by entering quit\n"); if user_insert=='quit': break; s=interval(user_insert);
def test_question_4_Error(self): with self.assertRaises(ValueError): value = insert(["()", "[s,n]"], "(1,2)") with self.assertRaises(ValueError): value = insert(["()", "[3,4]"], "(1,6)")