add random_str to create random string
This commit is contained in:
parent
f67e0541b8
commit
694cda47ca
@ -8,6 +8,11 @@ from .generic import flatten_list
|
||||
|
||||
from .arithmetic import gcd
|
||||
|
||||
def random_str(form, conditions = [], val_min = -10, val_max = 10):
|
||||
""" Create a random string using RdExpression class """
|
||||
random_str_generator = RdExpression(form, conditions)
|
||||
return random_str_generator(val_min, val_max)
|
||||
|
||||
class RdExpression(object):
|
||||
"""
|
||||
|
||||
@ -132,22 +137,17 @@ def desc_rdExp(rdExp):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
form = "{a}*-14 / (2*{b}) / -23 / 4"
|
||||
cond = ["{a} + {b} in [1, 2, 3, 4, 5]", "{a} not in [1]", "{b} not in [1]"]
|
||||
rdExp1 = RdExpression(form, cond)
|
||||
desc_rdExp(rdExp1)
|
||||
rdExp2 = RdExpression(form)
|
||||
desc_rdExp(rdExp2)
|
||||
form = "({a};{b})"
|
||||
cond = []
|
||||
print(random_str(form, cond))
|
||||
|
||||
form = "{a+a*10}*4 + {a} + 2*{b}"
|
||||
cond = ["{a} + {b} in [1, 2, 3, 4, 5]", "abs({a}) not in [1]", "{b} not in [1]", "gcd({a},{b}) == 1"]
|
||||
rdExp3 = RdExpression(form, cond)
|
||||
desc_rdExp(rdExp3)
|
||||
print(random_str(form, cond))
|
||||
|
||||
form = "{a+a*10}*4 + {a} + 2*{b}"
|
||||
cond = ["{a-b} + {b} in list(range(20))", "abs({a}) not in [1]", "{b} not in [1]", "gcd({a},{b}) == 1"]
|
||||
rdExp3 = RdExpression(form, cond)
|
||||
desc_rdExp(rdExp3)
|
||||
print(random_str(form, cond))
|
||||
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
|
Loading…
Reference in New Issue
Block a user