From 64d5bed8fe9eed9d1d96b117e88a0421aac692ce Mon Sep 17 00:00:00 2001 From: Lafrite Date: Tue, 21 Apr 2015 18:10:14 +0200 Subject: [PATCH] All tests pass :D --- pymath/abstract_polynom.py | 13 +++++++++++++ pymath/explicable.py | 12 ++++++++++++ pymath/expression.py | 22 +++++++++++----------- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/pymath/abstract_polynom.py b/pymath/abstract_polynom.py index 9eb8894..bc2fcf6 100644 --- a/pymath/abstract_polynom.py +++ b/pymath/abstract_polynom.py @@ -307,6 +307,11 @@ class AbstractPolynom(Explicable): >>> Q = P.reduce() >>> Q < [3, 12, 6]> + >>> for i in Q.explain(): + ... print(i) + 6 x^{ 2 } + ( 3 + 4 + 5 ) x + 1 + 2 + 6 x^{ 2 } + ( 7 + 5 ) x + 3 + 6 x^{ 2 } + 12 x + 3 >>> Q.steps [< [< [1, 2, '+'] >, < [3, 4, '+', 5, '+'] >, 6]>, < [3, < [7, 5, '+'] >, 6]>] """ @@ -580,6 +585,14 @@ class AbstractPolynom(Explicable): def __xor__(self, power): return self.__pow__(power) +if __name__ == '__main__': + P = AbstractPolynom([[1,2],[3,4,5],6]) + Q = P.reduce() + for i in Q.explain(): + print(i) + + #import doctest + #doctest.testmod() # ----------------------------- diff --git a/pymath/explicable.py b/pymath/explicable.py index d764132..fb91efd 100644 --- a/pymath/explicable.py +++ b/pymath/explicable.py @@ -4,6 +4,9 @@ from .render import txt, tex class Renderable(object): + """ + A Renderable object is an object which can work with Render class. It means that it has to have attribute postfix_tokens. + """ STR_RENDER = tex DEFAULT_RENDER = tex @@ -60,6 +63,15 @@ class Renderable(object): def __exit__(self, type, value, traceback): Renderable.set_render(self.old_render) return TmpRenderEnv() + + def __eq__(self, other): + """ Two Renderable objects are the same if they have same postfix_tokens """ + try: + return self.postfix_tokens == other.postfix_tokens + except AttributeError: + return False + + class Explicable(Renderable): diff --git a/pymath/expression.py b/pymath/expression.py index 5d1e8d7..c44c2a1 100644 --- a/pymath/expression.py +++ b/pymath/expression.py @@ -350,11 +350,11 @@ def untest(exp): if __name__ == '__main__': #print('\n') - A = Expression("( -8 x + 8 ) ( -8 - ( -6 x ) )") - Ar = A.simplify() + #A = Expression("( -8 x + 8 ) ( -8 - ( -6 x ) )") + #Ar = A.simplify() #print("Ar.steps -> ", Ar.steps) - for i in Ar.explain(): - print(i) + #for i in Ar.explain(): + # print(i) #print("------------") #for i in Ar.explain(): # print(i) @@ -362,20 +362,20 @@ if __name__ == '__main__': #print(type(Ar)) - print('\n-----------') - A = Expression("2 / 3 + 4 / 5") - Ar = A.simplify() + #print('\n-----------') + #A = Expression("2 / 3 + 4 / 5") + #Ar = A.simplify() #print("Ar.steps -> ", Ar.steps) #for i in Ar.steps: # print(i) #print("------------") - for i in Ar.explain(): - print(i) + #for i in Ar.explain(): + # print(i) #print(type(Ar)) - #import doctest - #doctest.testmod() + import doctest + doctest.testmod() # ----------------------------- # Reglages pour 'vim'