Added math expressions parser

This commit is contained in:
2023-10-09 07:03:54 +03:00
parent 2b260b0762
commit 5763c996c4
13 changed files with 922 additions and 0 deletions

0
parser/tests/__init__.py Normal file
View File

View File

@ -0,0 +1,14 @@
from parser import Parser
def test_Parser():
parser = Parser("(-b + sqrt(b^2-4a c))/(2a)")
assert parser.variables_names == {"c", "a", "b"}
assert parser.evaluate({"a": 1, "b": -3, "c": 2}) == 1.0
assert all(
parser.evaluate({"a": [1, 1, 1], "b": [-5, -6, -9], "c": [6, 9, 20]})
== [2.0, 3.0, 4.0]
)