Skip to content

Commit 4ee812a

Browse files
authored
Add arg checking to Curl... (#1472)
We use Curl as a developer doc example, so we should have this more correct.
1 parent 8ca7af6 commit 4ee812a

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

mathics/builtin/vectors/math_ops.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ class Curl(SympyFunction):
115115
"""
116116

117117
attributes = A_PROTECTED
118+
119+
# Set checking that the number of arguments required is two or three.
120+
eval_error = Builtin.generic_argument_error
121+
expected_args = (2, 3)
122+
118123
rules = {
119124
"Curl[{f1_, f2_}, {x1_, x2_}]": " D[f2, x1] - D[f1, x2]",
120125
"Curl[{f1_, f2_, f3_}, {x1_, x2_, x3_}]": """{

test/builtin/vectors/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-

test/builtin/vectors/test_mathops.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
"""
33
Unit tests for mathics.builtin.vectors.math_ops
44
5-
In particular, Norm[].
5+
In particular, Curl[] and Norm[].
66
"""
77

88
from test.helper import check_evaluation
99

10+
import pytest
11+
1012

1113
def test_norm():
1214
for str_expr, expected_message in (
@@ -48,3 +50,31 @@ def test_norm():
4850
),
4951
):
5052
check_evaluation(str_expr=str_expr, str_expected=str_expected)
53+
54+
55+
@pytest.mark.parametrize(
56+
("str_expr", "msgs", "assert_fail_msg"),
57+
[
58+
(
59+
"Curl[a]",
60+
["Curl called with 1 argument; 2 or 3 arguments are expected."],
61+
"Curl with one argument",
62+
),
63+
(
64+
"Curl[a, b, c, d]",
65+
["Curl called with 4 arguments; 2 or 3 arguments are expected."],
66+
"Curl with more than three arguments",
67+
),
68+
],
69+
)
70+
def test_wrong_number_of_arguments(str_expr, msgs, assert_fail_msg):
71+
""" """
72+
check_evaluation(
73+
str_expr,
74+
str_expr,
75+
to_string_expr=True,
76+
to_string_expected=True,
77+
hold_expected=True,
78+
failure_message=assert_fail_msg,
79+
expected_messages=msgs,
80+
)

0 commit comments

Comments
 (0)