expression and test

This commit is contained in:
lafrite 2014-11-11 09:58:47 +01:00
parent bd3bdd6885
commit 80261d97d3
2 changed files with 3 additions and 24 deletions

View File

@ -19,27 +19,15 @@ class Expression(object):
""" """
if type(exp) == str: if type(exp) == str:
#self._exp = exp #self._exp = exp
print("\t type(exp) :" + str(type(exp)))
self.postfix_tokens = str2tokens(exp) # les tokens seront alors stockés dans self.tokens temporairement self.postfix_tokens = str2tokens(exp) # les tokens seront alors stockés dans self.tokens temporairement
elif type(exp) == list: elif type(exp) == list:
print("\t type(exp) :" + str(type(exp)))
self.postfix_tokens = exp self.postfix_tokens = exp
print("\t self.postfix_tokens :" + str(self.postfix_tokens))
def __str__(self): def __str__(self):
""" """
Overload str Overload str
If you want to changer render set Expression.RENDER If you want to changer render set Expression.RENDER
""" """
print("\t self.STR_RENDER :" + str(self.STR_RENDER))
print("\t self.postfix_tokens :" + str(self.postfix_tokens))
print("\t self.STR_RENDER(self.postfix_tokens) :" + str(self.STR_RENDER(self.postfix_tokens)))
return self.STR_RENDER(self.postfix_tokens) return self.STR_RENDER(self.postfix_tokens)
def render(self, render = lambda x:str(x)): def render(self, render = lambda x:str(x)):

View File

@ -21,18 +21,9 @@ class TestExpression(unittest.TestCase):
def test_init_from_exp(self): def test_init_from_exp(self):
pass pass
def test_infix_tokens(self): def test_list(self):
pass exp = Expression([2, 3, "+"])
self.assertEqual(exp.postfix_tokens, [2, 3, "+"])
def test_postfix_tokens(self):
pass
def test_isNumber(self):
pass
def test_isOperator(self):
pass
def test_simplify_frac(self): def test_simplify_frac(self):
exp = Expression("1/2 - 4") exp = Expression("1/2 - 4")