Added math expressions parser
This commit is contained in:
0
parser/tests/__init__.py
Normal file
0
parser/tests/__init__.py
Normal file
14
parser/tests/test_parser.py
Normal file
14
parser/tests/test_parser.py
Normal 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]
|
||||
)
|
Reference in New Issue
Block a user