def test_indefiniteIntegral(): """Test primitive indefinite integral""" answer = sympify("3x^2/2") assert indefiniteIntegral(expr, symbol) == answer """Test partial integral""" answer = sympify("3xy^2/2") assert indefiniteIntegral(y_expr, y_symbol) == answer """Test indefinite integral of 2'nd order""" answer = sympify("x^3/2") assert indefiniteIntegral(expr, symbol, 2) == answer
def test_sympify(): answer = parse_expr("3*x*y**2") """Test normal sympy syntax""" expr = sympify("3*x*y**2") assert expr == answer """Test implicit multiplication""" expr = sympify("3xy**2") assert expr == answer """Test xor""" expr = sympify("3xy^2") assert expr == answer
def solve(expr, symbol, parse=True): """ Solves an expression Args: expr: the expression to solve symbol: the symbol to solve for parse: if the expression should be parsed to sympy Returns: A solved expression """ if parse: expr = sympify(expr) symbol = sympify(symbol) return __solve(expr, symbol)[0]
def derivative(expr, symbol, order=1, parse=True): """ Finds the derivative Args: expr: the expression to evaluate symbol: the symbol to evaluate with respect to order: order of the derivative parse: if the expression should be parsed to sympy Returns: An evaluated derivative """ if parse: expr = sympify(expr) symbol = sympify(symbol) return __diff(expr, symbol, order)
def limit(expr, symbol, to, dir="+", parsed=True): """ Find the limit Args: expr: the expression to find the limit of symbol: the symbol to limit to: the value to limit to dir: "+" if it should come from positive side "-" if it should come from negative. Defaults to positive parsed: if the expression should be parsed Returns: What the expression limits to """ if parsed: expr = sympify(expr) symbol = sympify(symbol) return __limit(expr, symbol, to, dir)
def evaluate(expr, parse=True): """ Evaluates a given expression Args: expr: the expression to evaluate parse: if the expression should be parsed to sympy Returns: An evaluated expression """ if parse: expr = sympify(expr) return expr.evalf()
def test_definiteIntegral(): """Test primitive definite integral""" start = sympify("0") end = sympify("10") answer = sympify("150") assert definiteIntegral(expr, symbol, start, end) == answer """Test partial definite integral""" answer = sympify("150x") assert definiteIntegral(y_expr, y_symbol, start, end) == answer """Test definite integral with variable as bound""" end = sympify("a") answer = sympify("3a^2/2") assert definiteIntegral(expr, symbol, start, end) == answer
def test_solve(): """Test primitive solve""" expr = "3+x=2" symbol = sympify("x") answer = sympify("-1") assert solve(expr, symbol) == answer
def test_evaluate(): """Test primitive expression""" expr = evaluate("350*150") answer = sympify("52500") assert expr == answer
import pytest from calc.integrate import indefiniteIntegral, definiteIntegral from parser.parser import sympify expr = "3x" symbol = sympify("x") y_expr = "3xy" y_symbol = sympify("y") def test_indefiniteIntegral(): """Test primitive indefinite integral""" answer = sympify("3x^2/2") assert indefiniteIntegral(expr, symbol) == answer """Test partial integral""" answer = sympify("3xy^2/2") assert indefiniteIntegral(y_expr, y_symbol) == answer """Test indefinite integral of 2'nd order""" answer = sympify("x^3/2") assert indefiniteIntegral(expr, symbol, 2) == answer def test_definiteIntegral(): """Test primitive definite integral""" start = sympify("0") end = sympify("10") answer = sympify("150") assert definiteIntegral(expr, symbol, start, end) == answer """Test partial definite integral""" answer = sympify("150x")