def test_question_1(self): self.assertEqual(str(interval('[]')),"The interval is not valid"); self.assertEqual(str(interval('[a,b]')),"The interval is not valid"); self.assertEqual(str(interval('[1,,5]')),"The interval is not valid"); self.assertEqual(str(interval('(11)')),"The interval is not valid"); self.assertEqual(str(interval('[1,1)')),"The interval is not valid"); self.assertEqual(str(interval('[-2,5]')),"[-2,5] represents the numbers -2 to 5"); self.assertEqual(str(interval('[-2,5)')),"[-2,5) represents the numbers -2 to 4"); self.assertEqual(str(interval('(-2,5)')),"(-2,5) represents the numbers -1 to 4"); self.assertEqual(str(interval('(-2,5]')),"(-2,5] represents the numbers -1 to 5");
def test_question_1(self): self.assertEqual(str(interval("[]")), "The interval is not valid") self.assertEqual(str(interval("[a,b]")), "The interval is not valid") self.assertEqual(str(interval("[1,,5]")), "The interval is not valid") self.assertEqual(str(interval("(11)")), "The interval is not valid") self.assertEqual(str(interval("[1,1)")), "The interval is not valid") self.assertEqual(str(interval("[-2,5]")), "[-2,5] represents the numbers -2 to 5") self.assertEqual(str(interval("[-2,5)")), "[-2,5) represents the numbers -2 to 4") self.assertEqual(str(interval("(-2,5)")), "(-2,5) represents the numbers -1 to 4") self.assertEqual(str(interval("(-2,5]")), "(-2,5] represents the numbers -1 to 5")
else: return ['[1,-1]'] else: return ['[1,-1]'] else: return ['[1,-1]'] #Let the user input a list of intervals user_list=input("A list of intervals? Quit the program by entering quit\n"); #If the input is not quit, we will justify the validity of the interval list if user_list!='quit': interval_list=transform(user_list); #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 #If the input is not quit and not valid interval list, the user will re-input while user_list!='quit' and str(s)=='The interval is not valid': user_list=input("The input intervals are not valid, please input again. A list of intervals? Quit the program by entering quit\n"); if user_list!='quit': interval_list=transform(user_list); #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