Exemple #1
0
 def __init__(self, className, baseClass=None, protocol=None):
     JOcClass.__init__(self, className, baseClass, protocol)
     self.imports = []
     self.variables = {}
     self._include_classes = None  # 引用的类数组
     JOcHelper.randVars(self.variables, 0.85,
                        JRand.rand_nearest(8))  # 初始化私有类变量
Exemple #2
0
 def make_dir_tree(root_dir, depth, nums):
     dirs = []
     depth_map = {}
     for i in range(nums):
         d = JRand.rand_nearest(depth + 1)
         dir_path = None
         if (d > 1):
             levels = None
             if (d in depth_map):
                 levels = depth_map[d]
                 if (random.random() < 0.8):
                     parent = os.path.dirname(random.choice(levels))
                     dir_path = JFillerHelper.rand_dir_path_by_depth(
                         parent, 1)
                     levels.append(dir_path)
                 else:
                     dir_path = JFillerHelper.rand_dir_path_by_depth(
                         root_dir, d)
                     levels.append(dir_path)
             else:
                 dir_path = JFillerHelper.rand_dir_path_by_depth(
                     root_dir, d)
                 levels = [dir_path]
                 depth_map[d] = levels
         else:
             dir_path = root_dir
         if dir_path is not None:
             dirs.append(dir_path)
     return dirs
Exemple #3
0
 def randStatement(self, useClasses=None):
     r = JRand.rand_nearest(5)
     if (r == 0):
         self.__make__statement(useClasses)
     elif (r == 1):
         self.__make__if(useClasses)
     elif (r == 2):
         self.__make__while(useClasses)
     elif (r == 3):
         self.__make__for(useClasses)
     elif (r == 4):
         self.__make__switch(useClasses)
Exemple #4
0
 def makeClsDeclare(self, radix):
     methods = self.methods
     if (methods is None):
         methods = []
         self.methods = methods
     flag = False  # 是否有静态函数的标记
     size = radix - JRand.rand_nearest(radix) + 1
     for i in range(size):
         m = JOcMixMethod(self)
         m.index = i
         methods.append(m)
         scope = None
         if (i == size - 1) and (not flag):
             scope = '+'  # 强制添加一个静态函数
         else:
             scope = random.choice(OC_METH)
             if (JOcMixHelper.isClassMethod(scope)):
                 flag = True
         m.makeDeclare(scope)
Exemple #5
0
 def makeBody(self, refClasses=None):
     # 初始化局部变量
     if (self.argNames is None):
         JOcHelper.randVars(self.variables, 0.00, random.randint(0, 5))
     else:
         JOcHelper.randVars(self.variables, 0.85, JRand.rand_nearest(5))
     # 生成逻辑
     tree = JOcMixBlock(self)
     self.lineTree = tree
     if (refClasses is not None):
         others = refClasses[:]
         n = JRand.rand_int(1, len(refClasses))
         for i in range(n):
             cls = JRand.rand_lave_list(others, n, i, 1)
             tree.randStatement(cls)
     else:
         n = random.randint(1, 3)
         for i in range(n):
             tree.randStatement()
     if (self.ret != 'void'):
         tree.makeReturn()
Exemple #6
0
 def __make__declare(self):
     var_list = self.variables.keys()
     # 生成指令表
     msgNums = 1 + JRand.rand_nearest(4)  # [1, 5]
     for i in range(msgNums):
         while (True):
             n = JOcHelper.var(self.messages)
             if (n not in var_list):
                 self.messages.append(n)
                 break
     # 生成参数表
     argNums = msgNums if (msgNums != 1) else (0 if (
         random.random() < 0.5) else 1)
     if (argNums > 0):
         self.argTypes = []
         self.argNames = []
         for i in range(argNums):
             self.argTypes.append(JRand.chose_nearest(OC_BASE))
             while (True):
                 n = JOcHelper.var(self.argNames)
                 if (n not in var_list):
                     self.argNames.append(n)
                     break
Exemple #7
0
 def rand_file_ext(left=2, min_right=3, right_float=3):
     return '.' + JWords.rand_lowers(
         left, min_right + JRand.rand_nearest(right_float))