Skip to content

Commit

Permalink
Merge pull request #917 from Mathics3/move_private_doctests_to_pytest10
Browse files Browse the repository at this point in the history
move private doctests to pytest in mathics.builtin.numeric
  • Loading branch information
rocky authored Dec 13, 2023
2 parents 080a2fe + a119aee commit 7c5a461
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 161 deletions.
8 changes: 0 additions & 8 deletions mathics/builtin/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,14 +958,6 @@ class Sum(IterationFunction, SympyFunction):
Verify algebraic identities:
>> Sum[x ^ 2, {x, 1, y}] - y * (y + 1) * (2 * y + 1) / 6
= 0
## Issue #302
## The sum should not converge since the first term is 1/0.
#> Sum[i / Log[i], {i, 1, Infinity}]
= Sum[i / Log[i], {i, 1, Infinity}]
#> Sum[Cos[Pi i], {i, 1, Infinity}]
= Sum[Cos[i Pi], {i, 1, Infinity}]
"""

summary_text = "discrete sum"
Expand Down
86 changes: 1 addition & 85 deletions mathics/builtin/intfns/combinatorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ class Binomial(MPMathFunction):
= 0
>> Binomial[-10.5, -3.5]
= 0.
## TODO should be ComplexInfinity but mpmath returns +inf
#> Binomial[-10, -3.5]
= Infinity
"""

attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED
Expand Down Expand Up @@ -411,90 +407,10 @@ class Subsets(Builtin):
The odd-numbered subsets of {a,b,c,d} in reverse order:
>> Subsets[{a, b, c, d}, All, {15, 1, -2}]
= {{b, c, d}, {a, b, d}, {c, d}, {b, c}, {a, c}, {d}, {b}, {}}
#> Subsets[{}]
= {{}}
#> Subsets[]
= Subsets[]
#> Subsets[{a, b, c}, 2.5]
: Position 2 of Subsets[{a, b, c}, 2.5] must be All, Infinity, a non-negative integer, or a List whose first element (required) is a non-negative integer, second element (optional) is a non-negative integer or Infinity, and third element (optional) is a nonzero integer
= Subsets[{a, b, c}, 2.5]
#> Subsets[{a, b, c}, -1]
: Position 2 of Subsets[{a, b, c}, -1] must be All, Infinity, a non-negative integer, or a List whose first element (required) is a non-negative integer, second element (optional) is a non-negative integer or Infinity, and third element (optional) is a nonzero integer
= Subsets[{a, b, c}, -1]
#> Subsets[{a, b, c}, {3, 4, 5, 6}]
: Position 2 of Subsets[{a, b, c}, {3, 4, 5, 6}] must be All, Infinity, a non-negative integer, or a List whose first element (required) is a non-negative integer, second element (optional) is a non-negative integer or Infinity, and third element (optional) is a nonzero integer
= Subsets[{a, b, c}, {3, 4, 5, 6}]
#> Subsets[{a, b, c}, {-1, 2}]
: Position 2 of Subsets[{a, b, c}, {-1, 2}] must be All, Infinity, a non-negative integer, or a List whose first element (required) is a non-negative integer, second element (optional) is a non-negative integer or Infinity, and third element (optional) is a nonzero integer
= Subsets[{a, b, c}, {-1, 2}]
#> Subsets[{a, b, c}, All]
= {{}, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c}}
#> Subsets[{a, b, c}, Infinity]
= {{}, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c}}
#> Subsets[{a, b, c}, ALL]
: Position 2 of Subsets[{a, b, c}, ALL] must be All, Infinity, a non-negative integer, or a List whose first element (required) is a non-negative integer, second element (optional) is a non-negative integer or Infinity, and third element (optional) is a nonzero integer
= Subsets[{a, b, c}, ALL]
#> Subsets[{a, b, c}, {a}]
: Position 2 of Subsets[{a, b, c}, {a}] must be All, Infinity, a non-negative integer, or a List whose first element (required) is a non-negative integer, second element (optional) is a non-negative integer or Infinity, and third element (optional) is a nonzero integer
= Subsets[{a, b, c}, {a}]
#> Subsets[{a, b, c}, {}]
: Position 2 of Subsets[{a, b, c}, {}] must be All, Infinity, a non-negative integer, or a List whose first element (required) is a non-negative integer, second element (optional) is a non-negative integer or Infinity, and third element (optional) is a nonzero integer
= Subsets[{a, b, c}, {}]
#> Subsets[{a, b}, 0]
= {{}}
#> Subsets[{1, 2}, x]
: Position 2 of Subsets[{1, 2}, x] must be All, Infinity, a non-negative integer, or a List whose first element (required) is a non-negative integer, second element (optional) is a non-negative integer or Infinity, and third element (optional) is a nonzero integer
= Subsets[{1, 2}, x]
#> Subsets[x]
: Nonatomic expression expected at position 1 in Subsets[x].
= Subsets[x]
#> Subsets[x, {1, 2}]
: Nonatomic expression expected at position 1 in Subsets[x, {1, 2}].
= Subsets[x, {1, 2}]
#> Subsets[x, {1, 2, 3}, {1, 3}]
: Nonatomic expression expected at position 1 in Subsets[x, {1, 2, 3}, {1, 3}].
= Subsets[x, {1, 2, 3}, {1, 3}]
#> Subsets[a + b + c]
= {0, a, b, c, a + b, a + c, b + c, a + b + c}
#> Subsets[f[a, b, c]]
= {f[], f[a], f[b], f[c], f[a, b], f[a, c], f[b, c], f[a, b, c]}
#> Subsets[a + b + c, {1, 3, 2}]
= {a, b, c, a + b + c}
#> Subsets[a* b * c, All, {6}]
= {a c}
#> Subsets[{a, b, c}, {1, Infinity}]
= {{a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c}}
#> Subsets[{a, b, c}, {1, Infinity, 2}]
= {{a}, {b}, {c}, {a, b, c}}
#> Subsets[{a, b, c}, {3, Infinity, -1}]
= {}
"""

messages = {
"nninfseq": "Position 2 of `1` must be All, Infinity, a non-negative integer, or a List whose first element (required) is a non-negative integer, second element (optional) is a non-negative integer or Infinity, and third element (optional) is a nonzero integer",
"nninfseq": "Position 2 of `1` must be All, Infinity, a non-negative integer, or a List whose first element (required) is a non-negative integer, second element (optional) is a non-negative integer or Infinity, and third element (optional) is a nonzero integer.",
"normal": "Nonatomic expression expected at position 1 in `1`.",
}

Expand Down
28 changes: 0 additions & 28 deletions mathics/builtin/intfns/divlike.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,6 @@ class Quotient(Builtin):
>> Quotient[23, 7]
= 3
#> Quotient[13, 0]
: Infinite expression Quotient[13, 0] encountered.
= ComplexInfinity
#> Quotient[-17, 7]
= -3
#> Quotient[-17, -4]
= 4
#> Quotient[19, -4]
= -5
"""

attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED
Expand Down Expand Up @@ -338,24 +328,6 @@ class QuotientRemainder(Builtin):
>> QuotientRemainder[23, 7]
= {3, 2}
#> QuotientRemainder[13, 0]
: The argument 0 in QuotientRemainder[13, 0] should be nonzero.
= QuotientRemainder[13, 0]
#> QuotientRemainder[-17, 7]
= {-3, 4}
#> QuotientRemainder[-17, -4]
= {4, -1}
#> QuotientRemainder[19, -4]
= {-5, -1}
#> QuotientRemainder[a, 0]
= QuotientRemainder[a, 0]
#> QuotientRemainder[a, b]
= QuotientRemainder[a, b]
#> QuotientRemainder[5.2,2.5]
= {2, 0.2}
#> QuotientRemainder[5, 2.]
= {2, 1.}
"""

attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED
Expand Down
3 changes: 0 additions & 3 deletions mathics/builtin/intfns/recurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ class HarmonicNumber(MPMathFunction):
>> HarmonicNumber[3.8]
= 2.03806
#> HarmonicNumber[-1.5]
= 0.613706
"""

rules = {
Expand Down
39 changes: 3 additions & 36 deletions mathics/builtin/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,21 +257,6 @@ class N(Builtin):
= F[3.14159265358979300000000000000]
>> N[F[Pi], 30, Method->"sympy"]
= F[3.14159265358979323846264338328]
#> p=N[Pi,100]
= 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
#> ToString[p]
= 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117068
#> N[1.012345678901234567890123, 20]
= 1.0123456789012345679
#> N[I, 30]
= 1.00000000000000000000000000000 I
#> N[1.012345678901234567890123, 50]
= 1.01234567890123456789012
#> % // Precision
= 24.
"""

options = {"Method": "Automatic"}
Expand Down Expand Up @@ -454,18 +439,6 @@ class Rationalize(Builtin):
Find the exact rational representation of 'N[Pi]'
>> Rationalize[N[Pi], 0]
= 245850922 / 78256779
#> Rationalize[N[Pi] + 0.8 I, x]
: Tolerance specification x must be a non-negative number.
= Rationalize[3.14159 + 0.8 I, x]
#> Rationalize[N[Pi] + 0.8 I, -1]
: Tolerance specification -1 must be a non-negative number.
= Rationalize[3.14159 + 0.8 I, -1]
#> Rationalize[x, y]
: Tolerance specification y must be a non-negative number.
= Rationalize[x, y]
"""

messages = {
Expand Down Expand Up @@ -769,17 +742,11 @@ class Sign(SympyFunction):
= 0
>> Sign[{-5, -10, 15, 20, 0}]
= {-1, -1, 1, 1, 0}
#> Sign[{1, 2.3, 4/5, {-6.7, 0}, {8/9, -10}}]
= {1, 1, 1, {-1, 0}, {1, -1}}
For a complex number, 'Sign' returns the phase of the number:
>> Sign[3 - 4*I]
= 3 / 5 - 4 I / 5
#> Sign[1 - 4*I] == (1/17 - 4 I/17) Sqrt[17]
= True
#> Sign[4, 5, 6]
: Sign called with 3 arguments; 1 argument is expected.
= Sign[4, 5, 6]
#> Sign["20"]
= Sign[20]
"""

summary_text = "complex sign of a number"
Expand Down
32 changes: 32 additions & 0 deletions test/builtin/arithmetic/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,35 @@ def test_cuberoot(str_expr, str_expected, msgs, failmsg):
check_evaluation(
str_expr, str_expected, expected_messages=msgs, failure_message=failmsg
)


@pytest.mark.parametrize(
("str_expr", "msgs", "str_expected", "fail_msg"),
[
## Issue #302
## The sum should not converge since the first term is 1/0.
(
"Sum[i / Log[i], {i, 1, Infinity}]",
None,
"Sum[i / Log[i], {i, 1, Infinity}]",
None,
),
(
"Sum[Cos[Pi i], {i, 1, Infinity}]",
None,
"Sum[Cos[i Pi], {i, 1, Infinity}]",
None,
),
],
)
def test_private_doctests_arithmetic(str_expr, msgs, str_expected, fail_msg):
""" """
check_evaluation(
str_expr,
str_expected,
to_string_expr=True,
to_string_expected=True,
hold_expected=True,
failure_message=fail_msg,
expected_messages=msgs,
)
Loading

0 comments on commit 7c5a461

Please sign in to comment.