Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from visma.functions.constant import Constant
from visma.functions.variable import Variable
from tests.tester import getTokens


######################
Expand Down Expand Up @@ -39,3 +40,21 @@ def test_Variable():
assert isinstance(variable2, Expression)
assert variable2.__str__() == '{3log{x}}'
'''


#######################
# functions.structure #
#######################


def test_reduce():

expr = getTokens("(2x+x)")
assert str(expr) == "3.0{x}"
assert expr.type == "Variable"

expr = getTokens("(3x+4*(x+(2x))+2y)")
assert str(expr) == "{(15.0{x}+2.0{y})}"

expr = getTokens("((2x+4x)+(2y+4y))")
assert str(expr) == "{(6.0{x}+6.0{y})}"
9 changes: 9 additions & 0 deletions visma/functions/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def __init__(self, tokens=None, coefficient=None, power=None):
self.tokens = []
if tokens is not None:
self.tokens.extend(tokens)
self.get_reduced()
self.type = 'Expression'

def __str__(self):
Expand All @@ -194,6 +195,14 @@ def __str__(self):
represent += "{(" + str(self.operand) + ")}"
return represent

def get_reduced(self):
'''Simpilifies the expression
'''
from visma.simplify.simplify import simplify
self.tokens, _, _, _, _ = simplify(self.tokens)
if(self.__class__ == Expression):
self.reduced = True


class Equation(Expression):
"""Class for equation type
Expand Down