diff --git a/pymath/calculus/equation.py b/pymath/calculus/equation.py index b03d95e..dee4cb2 100644 --- a/pymath/calculus/equation.py +++ b/pymath/calculus/equation.py @@ -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