mathjson-solver 1.12.0__tar.gz → 1.13.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mathjson_solver-1.12.0/src/mathjson_solver.egg-info → mathjson_solver-1.13.0}/PKG-INFO +1 -1
- {mathjson_solver-1.12.0 → mathjson_solver-1.13.0}/setup.cfg +1 -1
- {mathjson_solver-1.12.0 → mathjson_solver-1.13.0}/setup.py +1 -1
- {mathjson_solver-1.12.0 → mathjson_solver-1.13.0}/src/mathjson_solver/__main__.py +17 -1
- {mathjson_solver-1.12.0 → mathjson_solver-1.13.0/src/mathjson_solver.egg-info}/PKG-INFO +1 -1
- {mathjson_solver-1.12.0 → mathjson_solver-1.13.0}/tests/test_with_pytest.py +10 -0
- {mathjson_solver-1.12.0 → mathjson_solver-1.13.0}/LICENSE +0 -0
- {mathjson_solver-1.12.0 → mathjson_solver-1.13.0}/README.md +0 -0
- {mathjson_solver-1.12.0 → mathjson_solver-1.13.0}/pyproject.toml +0 -0
- {mathjson_solver-1.12.0 → mathjson_solver-1.13.0}/src/mathjson_solver/__init__.py +0 -0
- {mathjson_solver-1.12.0 → mathjson_solver-1.13.0}/src/mathjson_solver.egg-info/SOURCES.txt +0 -0
- {mathjson_solver-1.12.0 → mathjson_solver-1.13.0}/src/mathjson_solver.egg-info/dependency_links.txt +0 -0
- {mathjson_solver-1.12.0 → mathjson_solver-1.13.0}/src/mathjson_solver.egg-info/top_level.txt +0 -0
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import numbers
|
|
2
|
-
from types import NoneType
|
|
3
2
|
from typing import Union
|
|
4
3
|
from functools import reduce
|
|
5
4
|
import math
|
|
@@ -9,6 +8,8 @@ import logging
|
|
|
9
8
|
import traceback
|
|
10
9
|
import datetime
|
|
11
10
|
|
|
11
|
+
NoneType = type(None)
|
|
12
|
+
|
|
12
13
|
|
|
13
14
|
class MathJSONException(Exception):
|
|
14
15
|
"""Exception for MathJSON processing issues"""
|
|
@@ -253,6 +254,20 @@ def create_mathjson_solver(solver_parameters):
|
|
|
253
254
|
raise ValueError(
|
|
254
255
|
"Case of 'Switch' should have exactly two parameters"
|
|
255
256
|
)
|
|
257
|
+
if comparison_safe_converter(
|
|
258
|
+
expression
|
|
259
|
+
) == comparison_safe_converter(f(x[0], c)):
|
|
260
|
+
return f(x[1], c)
|
|
261
|
+
else:
|
|
262
|
+
return f(s[2], c)
|
|
263
|
+
|
|
264
|
+
def StrictSwitch(s):
|
|
265
|
+
expression = f(s[1], c)
|
|
266
|
+
for x in s[3:]:
|
|
267
|
+
if len(x) != 2:
|
|
268
|
+
raise ValueError(
|
|
269
|
+
"Case of 'StrictSwitch' should have exactly two parameters"
|
|
270
|
+
)
|
|
256
271
|
if expression == f(x[0], c):
|
|
257
272
|
return f(x[1], c)
|
|
258
273
|
else:
|
|
@@ -431,6 +446,7 @@ def create_mathjson_solver(solver_parameters):
|
|
|
431
446
|
),
|
|
432
447
|
"Constants": Constants,
|
|
433
448
|
"Switch": Switch,
|
|
449
|
+
"StrictSwitch": StrictSwitch,
|
|
434
450
|
"If": If,
|
|
435
451
|
"Multiply": lambda s: reduce(
|
|
436
452
|
lambda a, b: float(a) * float(b), [f(x, c) for x in s[1:]]
|
|
@@ -132,6 +132,16 @@ from mathjson_solver import create_solver, MathJSONException, extract_variables
|
|
|
132
132
|
# ],
|
|
133
133
|
# 13
|
|
134
134
|
# ),
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# The next tests check the type-forgiving nature of Switch.
|
|
138
|
+
({"value": 2}, ["Switch", "value", 0, ["1", 11], ["2", 22]], 22),
|
|
139
|
+
({"value": "2"}, ["Switch", "value", 0, [1, 11], [2, 22]], 22),
|
|
140
|
+
|
|
141
|
+
# The next tests verify that the StrictSwitch is not forgiving.
|
|
142
|
+
({"value": 2}, ["StrictSwitch", "value", 0, ["1", 11], ["2", 22]], 0),
|
|
143
|
+
({"value": "2"}, ["StrictSwitch", "value", 0, [1, 11], [2, 22]], 0),
|
|
144
|
+
|
|
135
145
|
({"color": "red"}, ["Switch", "color", 0, ["blue", 10], ["red", 30]], 30),
|
|
136
146
|
({"color": "green"}, ["Switch", "color", 0, ["blue", 10], ["red", 30]], 0),
|
|
137
147
|
({"color": "green"}, ["Switch", "undefined", 0, ["blue", 10], ["red", 30]], 0),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mathjson_solver-1.12.0 → mathjson_solver-1.13.0}/src/mathjson_solver.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{mathjson_solver-1.12.0 → mathjson_solver-1.13.0}/src/mathjson_solver.egg-info/top_level.txt
RENAMED
|
File without changes
|