You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

63 lines
2.5 KiB

import pytest
import chatbug.tool_functions as tool_functions
from tests import helper
def test_math_evaluate_1():
result = tool_functions.math_evaluate("1+2*pi")
assert result == "1 + 2*pi = 7.28318530717959"
def test_math_evaluate_2a():
result = tool_functions.math_evaluate("2**4")
assert result == "2**4 = 16"
def test_math_evaluate_2b():
""" test that ^ notation is also working, original sympy cannot do this """
result = tool_functions.math_evaluate("2^4")
assert result == "2**4 = 16"
def test_math_evaluate_3():
result = tool_functions.math_evaluate("Integral(exp(-x**2), (x, -oo, oo))")
assert result == "Integral(exp(-x**2), (x, -oo, oo)) = sqrt(pi) = 1.77245385090552"
def test_math_evaluate_4():
result = tool_functions.math_evaluate("(2**x)**2")
assert result == "(2**x)**2 = 2**(2*x) = 2.0**(2*x)"
def test_math_evaluate_5():
result = tool_functions.math_evaluate("sin(pi/2) + cos(0)")
assert result == "sin(pi/2) + cos(0) = 2"
def test_math_evaluate_solve_a():
result = tool_functions.math_evaluate("solve 240=x*r+x*r^2+x*r^3+s and r=1.618 and s=5 for x, r, s")
assert result == "Solved equation system 240 = r**3*x + r**2*x + r*x + s, r = 1.61800000000000 and s = 5 for x=27.7393327937747=~27.739, r=1.61800000000000=~1.618 and s=5.00000000000000=~5.000."
def test_math_evaluate_solve_b():
result = tool_functions.math_evaluate("solve 250=x+x*r+s and r=1.618 and s=0 for x, r, s")
assert result == "Solved equation system 250 = r*x + s + x, r = 1.61800000000000 and s = 0 for x=95.4927425515661=~95.493, r=1.61800000000000=~1.618 and s=0."
def test_math_solver_1():
result = tool_functions.math_evaluate("solve x = 1 for x")
assert result == "solved x = 1 for x = {1}"
def test_math_solver_2():
result = tool_functions.math_evaluate("solve (x + 1)*(x - 1) = 1 for x")
assert result == "solved (x + 1)*(x - 1*1) = 1 for x = {-sqrt(2), sqrt(2)}"
def test_math_solver_3a():
result = tool_functions.math_evaluate("solve 2*x + 3*y = 7 and x - y = 1 for x, y")
assert result == "Solved equation system 2*x + 3*y = 7 and x - y = 1 for x=2 and y=1."
def test_math_solver_3b():
result = tool_functions.math_evaluate("solve 2*x + 3*y = 7, x - y = 1 for x and y")
assert result == "Solved equation system 2*x + 3*y = 7 and x - y = 1 for x=2 and y=1."
def test_math_solver_4():
result = tool_functions.math_evaluate("solve 2*x**3 + 3*y = 7 and x - y = 1 for x, y")
assert result == "Solved equation system 2*x**3 + 3*y = 7 and x - y = 1 for x=~1.421 and y=~0.421."