From fec78c03d407130b7a0b9aff1bcd8830b6de3596 Mon Sep 17 00:00:00 2001 From: lafrite Date: Tue, 25 Nov 2014 10:46:00 +0100 Subject: [PATCH] test with no * between number and letter - doctest in operator Conflicts: pymath/operator.py --- pymath/operator.py | 64 +++++++++++++++++++------------------------- test/test_polynom.py | 8 +++--- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/pymath/operator.py b/pymath/operator.py index 223b28e..d5dbf5d 100644 --- a/pymath/operator.py +++ b/pymath/operator.py @@ -75,24 +75,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 )' """ replacement = {"op"+str(i+1): ' '.join(self.add_parenthesis(op)) for (i,op) in enumerate(args)} @@ -107,24 +103,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 )' """ replacement = {"op"+str(i+1): ' '.join(self.add_parenthesis(op)) for (i,op) in enumerate(args)} @@ -139,21 +131,19 @@ class Operator(str): :*args: Operands for this operation :returns: list with the operator surrounded by operands - >>> mul = Operator("*", 2) - >>> add = Operator("+", 2) - >>> sub1 = Operator("-", 1) - >>> mul.__p2i__(1,2) + # TODO: order doctest |lun. nov. 24 07:17:29 CET 2014 + >>> 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