feat: upgrade toolbox for v1.2.1
This commit is contained in:
@@ -49,6 +49,108 @@ def test_calculate_方程矩阵统计与进制():
|
||||
assert combinations["result"]["exact"] == "120"
|
||||
|
||||
|
||||
def test_calculate_高级微积分与多元分析():
|
||||
series = calculate(
|
||||
{
|
||||
"operation": "series",
|
||||
"expression": "exp(x)",
|
||||
"variable": "x",
|
||||
"point": "0",
|
||||
"order": 5,
|
||||
}
|
||||
)
|
||||
gradient = calculate(
|
||||
{
|
||||
"operation": "gradient",
|
||||
"expression": "x^2*y + sin(y)",
|
||||
"variables": "x,y",
|
||||
}
|
||||
)
|
||||
hessian = calculate(
|
||||
{
|
||||
"operation": "hessian",
|
||||
"expression": "x^2 + x*y + y^2",
|
||||
"variables": "x,y",
|
||||
}
|
||||
)
|
||||
roots = calculate(
|
||||
{
|
||||
"operation": "polynomial_roots",
|
||||
"expression": "x^3 - 1 = 0",
|
||||
"variable": "x",
|
||||
}
|
||||
)
|
||||
|
||||
assert "x**4/24" in series["result"]["exact"]
|
||||
assert gradient["result"]["exact"] == "[[2*x*y], [x**2 + cos(y)]]"
|
||||
assert hessian["result"]["exact"] == "[[2, 1], [1, 2]]"
|
||||
assert len(roots["result"]) == 3
|
||||
|
||||
|
||||
def test_calculate_线性代数与方程组():
|
||||
system = calculate(
|
||||
{
|
||||
"operation": "solve_system",
|
||||
"expression": "x + y = 5; x - y = 1",
|
||||
"variables": "x,y",
|
||||
}
|
||||
)
|
||||
rank = calculate(
|
||||
{"operation": "matrix_rank", "expression": "1,2,3;2,4,6"}
|
||||
)
|
||||
nullspace = calculate(
|
||||
{"operation": "matrix_nullspace", "expression": "1,2;2,4"}
|
||||
)
|
||||
eigenvalues = calculate(
|
||||
{"operation": "matrix_eigenvalues", "expression": "2,0;0,3"}
|
||||
)
|
||||
|
||||
assert system["result"][0]["x"]["exact"] == "3"
|
||||
assert system["result"][0]["y"]["exact"] == "2"
|
||||
assert rank["result"]["exact"] == "1"
|
||||
assert nullspace["result"][0]["exact"] == "[[-2], [1]]"
|
||||
assert set(eigenvalues["result"]) == {"2", "3"}
|
||||
|
||||
|
||||
def test_calculate_统计包含四分位数与极差():
|
||||
result = calculate(
|
||||
{"operation": "statistics", "expression": "1,2,3,4,5"}
|
||||
)["result"]
|
||||
|
||||
assert result["sum"] == 15
|
||||
assert result["q1"] == 2
|
||||
assert result["q3"] == 4
|
||||
assert result["range"] == 4
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("payload", "field"),
|
||||
[
|
||||
(
|
||||
{
|
||||
"operation": "series",
|
||||
"expression": "exp(x)",
|
||||
"order": "not-an-integer",
|
||||
},
|
||||
"order",
|
||||
),
|
||||
(
|
||||
{
|
||||
"operation": "polynomial_roots",
|
||||
"expression": "x + y",
|
||||
"variable": "x",
|
||||
},
|
||||
"expression",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_calculate_高级操作返回可读校验错误(payload, field):
|
||||
with pytest.raises(ValidationError) as exc_info:
|
||||
calculate(payload)
|
||||
|
||||
assert field in exc_info.value.detail
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"source",
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user