random generation for Equation

This commit is contained in:
Benjamin Bertrand 2016-03-22 10:42:00 +03:00
parent ba324ec995
commit f648e94a37

View File

@ -14,19 +14,24 @@ __all__ = ['Equation']
class Equation(object):
"""A calculus expression. Today it can andle only expression with numbers later it will be able to manipulate unknown"""
# @classmethod
# def random(self, form="", conditions=[], val_min=-10, val_max=10):
# """Create a random expression from form and with conditions
#
# :param form: the form of the expression (/!\ variables need to be in brackets {})
# :param conditions: condition on variables (/!\ variables need to be in brackets {})
# :param val_min: min value for generate variables
# :param val_max: max value for generate variables
#
# """
# random_generator = RdExpression(form, conditions)
# return Expression(random_generator(val_min, val_max))
#
@classmethod
def random(self, form="", conditions=[], val_min=-10, val_max=10):
"""Create a random expression from form and with conditions
:param form: the form of the expression (/!\ variables need to be in brackets {})
:param conditions: condition on variables (/!\ variables need to be in brackets {})
:param val_min: min value for generate variables
:param val_max: max value for generate variables
>>> Equation.random("{a}x + {b} = 0") # doctest:+ELLIPSIS
< Equation [..., 0]>
>>> Equation.random("{a}x + {b} = _", conditions = ["{a}==2"]) # doctest:+ELLIPSIS
< Equation [2 x ...]>
"""
random_generator = RdExpression(form, conditions)
return Equation(random_generator(val_min, val_max))
def __init__(self, exp_str = "", left_poly = Expression([0]), right_poly = Expression([0])):
"""Create the equation