def generate_condition(self): if self.role == Condition.UseNative: return RandomData.random_choice(self.UseNative_Roles) elif self.role == Condition.UseData: return RandomData.random_choice(self.UseData_Roles) else: raise Exception("role error")
def __init__(self, role): self.UseNative_Roles = [ ("今年年份", RandomData.current_year()), ("本月月份", RandomData.current_month()), ("今天几号", RandomData.current_day()), ("今天周几[1-7]", RandomData.current_weekday()), ("北京奥运那年", "2008"), Calc.index_value( None, *[RandomData.get_letter_digit() for i in range(4)]), ] self.UseData_Roles = [ Calc.sum(*[RandomData.get_int() for i in range(4)]), Calc.get_even(*[RandomData.get_int() for i in range(4)]), Calc.get_odd(*[RandomData.get_int() for i in range(4)]), Calc.max(*[RandomData.get_int() for i in range(4)]), Calc.min(*[RandomData.get_int() for i in range(4)]), ] if role == self.Any: role = RandomData.random_choice([self.UseData, self.UseNative]) self.role = role
def choice(): return RandomData.random_choice(ConditionConnection.Kinds)
def index_value(index=None, *args): if index is None: index = RandomData.random_choice(range(len(args))) ans = args[index] return '%s里第%s个内容' % ('、'.join(map(str, args)), index + 1), ans