diff --git a/pymath/calculus/polynom.py b/pymath/calculus/polynom.py index c0d43d2..163bcbf 100644 --- a/pymath/calculus/polynom.py +++ b/pymath/calculus/polynom.py @@ -146,9 +146,6 @@ class Polynom(AbstractPolynom): 3 h^{ 2 } + 8 h + 6 >>> R = P(Q) """ - # if isNumerand(value) or Expression.isExpression(value): - # postfix_exp = [value if i==self._letter else i for i in self.postfix_tokens] - # else: postfix_exp = [ Expression(value) if i == self._letter else i for i in self.postfix_tokens] diff --git a/pymath/calculus/test/test_polynom.py b/pymath/calculus/test/test_polynom.py index 04ef823..7a30d89 100644 --- a/pymath/calculus/test/test_polynom.py +++ b/pymath/calculus/test/test_polynom.py @@ -8,6 +8,7 @@ from pymath.calculus.polynom import Polynom from pymath.calculus.fraction import Fraction from pymath.calculus.expression import Expression from pymath.calculus.render import txt +from pymath.calculus.operator import op class TestPolynom(unittest.TestCase): @@ -69,45 +70,37 @@ class TestPolynom(unittest.TestCase): def test_postfix(self): p = Polynom([1, 2, 3]) - #ans = [1, 2, "x", "*", "+", 3, "x", 2, "^", "*", "+"] - ans = [3, 'x', 2, '^', '*', 2, 'x', '*', '+', 1, '+'] + ans = [3, 'x', 2, op.pw, op.mul, 2, 'x', op.mul, op.add, 1, op.add] self.assertEqual(ans, p.postfix_tokens) def test_postfix_monom(self): p = Polynom([0, 2]) - ans = [2, "x", "*"] + ans = [2, "x", op.mul] self.assertEqual(ans, p.postfix_tokens) def test_postfix_0_coef(self): p = Polynom([0, 2, 0, 4]) - #ans = [2, "x", "*", 4, "x", 3, "^", "*", "+"] - ans = [4, 'x', 3, '^', '*', 2, 'x', '*', '+'] + ans = [4, 'x', 3, op.pw, op.mul, 2, 'x', op.mul, op.add] self.assertEqual(ans, p.postfix_tokens) def test_postfix_1_coef(self): p = Polynom([0, 1, 1]) - #ans = ["x", "x", 2, "^", "+"] - ans = ["x", 2, "^", "x", "+"] + ans = ["x", 2, op.pw, "x", op.add] self.assertEqual(ans, p.postfix_tokens) def test_postfix_neg_coef(self): - # TODO: Choix arbitraire (vis à vis des + et des -) il faudra faire en - # fonction de render |sam. juin 14 09:45:55 CEST 2014 p = Polynom([-1, -2, -3]) - #ans = [-1, -2, "x", "*", "+", -3, "x", 2, "^", "*", "+"] - ans = [3, 'x', 2, '^', '*', '-', 2, 'x', '*', '-', 1, '-'] + ans = [3, 'x', 2, op.pw, op.mul, op.sub1, 2, 'x', op.mul, op.sub, 1, op.sub] self.assertEqual(ans, p.postfix_tokens) def test_postfix_multi_coef(self): p = Polynom([1, [2, 3], 4]) - #ans = [1, 2, "x", "*", "+", 3, "x", "*", "+", 4, "x", 2, "^", "*", "+"] - ans = [4, 'x', 2, '^', '*', 2, 'x', '*', '+', 3, 'x', '*', '+', 1, '+'] + ans = [4, 'x', 2, op.pw, op.mul, 2, 'x', op.mul, op.add, 3, 'x', op.mul, op.add, 1, op.add] self.assertEqual(ans, p.postfix_tokens) def test_postfix_arithm_coef(self): p = Polynom([1, Expression([2, 3, "+"]), 4]) - #ans = [1, 2, 3, "+", "x", "*", "+", 4, "x", 2, "^", "*", "+"] - ans = [4, 'x', 2, '^', '*', 2, 3, '+', 'x', '*', '+', 1, '+'] + ans = [4, 'x', 2, op.pw, op.mul, 2, 3, op.add, 'x', op.mul, op.add, 1, op.add] self.assertEqual(ans, p.postfix_tokens) def test_reduce_nilpo(self):