diff --git a/pymath/operator.py b/pymath/operator.py index 3a0a54c..66d2aa8 100644 --- a/pymath/operator.py +++ b/pymath/operator.py @@ -81,24 +81,20 @@ class Operator(str): :*args: Operands for this operation :returns: String with operator and his operands - >>> mul = Operator("*", 2) - >>> add = Operator("+", 2) - >>> sub1 = Operator("-", 1) - >>> div = Operator("/", 1) - >>> mul.__txt__('1','2') + >>> op.mul.__txt__('1','2') '1 * 2' - >>> add.__txt__('1','2') + >>> op.add.__txt__('1','2') '1 + 2' - >>> f = save_mainOp('2 + 3',add) - >>> mul.__txt__(f, '4') + >>> f = save_mainOp('2 + 3',op.add) + >>> op.mul.__txt__(f, '4') '( 2 + 3 ) * 4' - >>> f = save_mainOp('-3',sub1) - >>> sub1.__txt__(f) + >>> f = save_mainOp('-3',op.sub1) + >>> op.sub1.__txt__(f) '- ( -3 )' - >>> sub1.__txt__('-3') + >>> op.sub1.__txt__('-3') '- ( -3 )' - >>> f = save_mainOp('2 + 3',add) - >>> sub1.__txt__(f) + >>> f = save_mainOp('2 + 3',op.add) + >>> op.sub1.__txt__(f) '- ( 2 + 3 )' """ return self._render(self._txt, *args) @@ -109,24 +105,20 @@ class Operator(str): :*args: Operands for this operation :returns: String with operator and his operands - >>> mul = Operator("*", 2) - >>> add = Operator("+", 2) - >>> sub1 = Operator("-", 1) - >>> div = Operator("/", 1) - >>> mul.__tex__('1','2') + >>> op.mul.__tex__('1','2') '1 \\\\times 2' - >>> add.__tex__('1','2') + >>> op.add.__tex__('1','2') '1 + 2' - >>> f = save_mainOp('2 + 3',add) - >>> mul.__tex__(f, '4') + >>> f = save_mainOp('2 + 3',op.add) + >>> op.mul.__tex__(f, '4') '( 2 + 3 ) \\\\times 4' - >>> f = save_mainOp('-3',sub1) - >>> sub1.__tex__(f) + >>> f = save_mainOp('-3',op.sub1) + >>> op.sub1.__tex__(f) '- ( -3 )' - >>> sub1.__tex__('-3') + >>> op.sub1.__tex__('-3') '- ( -3 )' - >>> f = save_mainOp('2 + 3',add) - >>> sub1.__tex__(f) + >>> f = save_mainOp('2 + 3',op.add) + >>> op.sub1.__tex__(f) '- ( 2 + 3 )' """ return self._render(self._tex, *args) @@ -138,21 +130,18 @@ class Operator(str): :returns: list with the operator surrounded by operands # TODO: order doctest |lun. nov. 24 07:17:29 CET 2014 - >>> mul = Operator("*", 2) - >>> add = Operator("+", 2) - >>> sub1 = Operator("-", 1) - >>> mul.__p2i__(1,2) + >>> op.mul.__p2i__(1,2) [1, '*', 2] - >>> f = save_mainOp([2, add, 3],add) - >>> mul.__p2i__(f, 4) + >>> f = save_mainOp([2, op.add, 3],op.add) + >>> op.mul.__p2i__(f, 4) ['(', 2, '+', 3, ')', '*', 4] - >>> f = save_mainOp([sub1, 3],sub1) - >>> sub1.__p2i__(f) + >>> f = save_mainOp([op.sub1, 3],op.sub1) + >>> op.sub1.__p2i__(f) ['-', '(', '-', 3, ')'] - >>> sub1.__p2i__(-3) + >>> op.sub1.__p2i__(-3) ['-', '(', -3, ')'] - >>> f = save_mainOp([2, add, 3],add) - >>> sub1.__p2i__(f) + >>> f = save_mainOp([2, op.add, 3],op.add) + >>> op.sub1.__p2i__(f) ['-', '(', 2, '+', 3, ')'] """ # TODO: Attention à gestion des fractions qui se comportent chelou avec les parenthèses |dim. nov. 9 09:21:52 CET 2014 diff --git a/test/test_polynom.py b/test/test_polynom.py index 17edd7b..de491fb 100644 --- a/test/test_polynom.py +++ b/test/test_polynom.py @@ -98,25 +98,25 @@ class TestPolynom(unittest.TestCase): def test_reduce(self): p = Polynom([1, [2, 3], 4]) - self.assertEqual(str(p.reduce()[-1]),'4 * x ^ 2 + 5 * x + 1') + self.assertEqual(str(p.reduce()[-1]),'4 x ^ 2 + 5 x + 1') def test_add_int(self): p = Polynom([1, 2, 3]) q = (p + 2)[-1] - self.assertEqual(str(q), '3 * x ^ 2 + 2 * x + 3') + self.assertEqual(str(q), '3 x ^ 2 + 2 x + 3') def test_add_frac(self): p = Polynom([1, 2, 3]) f = Fraction(1, 2) q = (p + f)[-1] #ans = repr(Polynom([Expression(Fraction(3, 2)), Expression(2), Expression(3)])) - self.assertEqual(str(q),'3 * x ^ 2 + 2 * x + 3 / 2') + self.assertEqual(str(q),'3 x ^ 2 + 2 x + 3 / 2') def test_add_poly(self): p = Polynom([1, 0, 3]) q = Polynom([0, 2, 3]) r = (p + q)[-1] - self.assertEqual(str(r), '6 * x ^ 2 + 2 * x + 1') + self.assertEqual(str(r), '6 x ^ 2 + 2 x + 1') def test_radd_int(self): pass