eval polynom but does not work with constant polynoms. Need unittest

This commit is contained in:
Lafrite 2014-12-21 18:03:22 +01:00
parent a38ba53577
commit 2bbe6eca7d

View File

@ -62,6 +62,15 @@ class Polynom(object):
self._isPolynom = 1 self._isPolynom = 1
def __call__(self, value):
""" Evaluate the polynom in value
:returns: Expression ready to be simplify
"""
postfix_exp = [value if i==self._letter else i for i in self.postfix]
return Expression(postfix_exp)
def feed_coef(self, l_coef): def feed_coef(self, l_coef):
"""Feed coef of the polynom. Manage differently whether it's a number or an expression """Feed coef of the polynom. Manage differently whether it's a number or an expression
@ -102,7 +111,7 @@ class Polynom(object):
return 0 return 0
def __str__(self): def __str__(self):
return txt(self.postfix) return str(Expression(self.postfix))
def __repr__(self): def __repr__(self):
return "< Polynom " + str(self._coef) + ">" return "< Polynom " + str(self._coef) + ">"
@ -370,27 +379,28 @@ def test(p,q):
print("p : ",p) print("p : ",p)
print("q : ",q) print("q : ",q)
#print("\n Plus ------") print("\n Plus ------")
#print(p, "+", q) print(p, "+", q)
#for i in (p + q): for i in (p + q):
# #print(repr(i)) #print(repr(i))
# #print("\t", str(i.postfix)) #print("\t", str(i.postfix))
# print(i) print(i)
##print((p+q)[-1]._coef)
#print("\n Moins ------") print("\n Moins ------")
#for i in (p - q): for i in (p - q):
# #print(repr(i)) #print(repr(i))
# #print("\t", str(i.postfix)) #print("\t", str(i.postfix))
# print(i) print(i)
##print((p-q)[-1]._coef)
print("\n Multiplier ------") print("\n Multiplier ------")
for i in (p * q): for i in (p * q):
#print(repr(i)) #print(repr(i))
#print("\t", str(i.postfix)) #print("\t", str(i.postfix))
print(i) print(i)
#print((p*q)[-1]._coef)
print("\n Evaluer ------")
for i in q(3).simplify():
print(i)
if __name__ == '__main__': if __name__ == '__main__':