예제 #1
0
 def mekeMathState(meth):
     vars = []
     cats = []
     if (meth.variables is not None):
         for v in meth.variables:
             t = meth.variables[v][0]
             if (JOcHelper.isNumber(t)):
                 vars.append(v)
                 cats.append(t)
     if (meth.argNames is not None):
         for i in range(len(meth.argNames)):
             t = meth.argTypes[i]
             if (JOcHelper.isNumber(t)):
                 vars.append(meth.argNames[i])
                 cats.append(t)
     if (len(vars) == 1):
         v = vars[0]
         r = random.random()
         if (r < 0.2):
             return v + random.choice(('++', '--')) + ';'
         elif (r < 0.5):
             return random.choice(('++', '--')) + v + ';'
         elif (r < 0.8):
             return v + ' ' + random.choice(('+', '-', '*')) + '= ' + v + ';'
         else:
             return v + ' = ' + v + random.choice(OC_MATH) + str(random.randint(2, 10)) + ';'
     elif (len(vars) > 1):
         i = int(random.random() * len(vars))
         v = vars[i]
         s = v + ' = (' + cats[i] + ') ('
         for i in range(len(vars)):
             v = vars[i]
             s += v if (i == 0) else (random.choice(OC_MATH) + v)
         s += ');'
         return s
예제 #2
0
 def makeRet(meth):
     vars = []
     r = meth.ret
     if (meth.variables is not None):
         for v in meth.variables:
             t = meth.variables[v][0]
             if (t == r):
                 vars.append(v)
             elif (JOcHelper.isNumber(r) and JOcHelper.isNumber(t)):
                 vars.append('(' + r + ')' + v)
     if (meth.argNames is not None):
         for i in range(len(meth.argNames)):
             t = meth.argTypes[i]
             if (t == r):
                 vars.append(meth.argNames[i])
             elif (JOcHelper.isNumber(r) and JOcHelper.isNumber(t)):
                 vars.append('(' + r + ')' + meth.argNames[i])
     if len(vars) > 0:
         return random.choice(vars)
     else:
         return JOcHelper.randValue(r)