Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions mathics/builtin/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,6 @@ class RecursionLimit(Predefined):
>> a = a + a
: Recursion depth of 512 exceeded.
= $Aborted

#> $RecursionLimit = 20
= 20
#> a = a + a
: Recursion depth of 20 exceeded.
= $Aborted

#> $RecursionLimit = 200
= 200

#> ClearAll[f];
#> f[x_, 0] := x; f[x_, n_] := f[x + 1, n - 1];
#> Block[{$RecursionLimit = 20}, f[0, 100]]
= 100
#> ClearAll[f];

#> ClearAll[f];
#> f[x_, 0] := x; f[x_, n_] := Module[{y = x + 1}, f[y, n - 1]];
#> Block[{$RecursionLimit = 20}, f[0, 100]]
: Recursion depth of 20 exceeded.
= $Aborted
#> ClearAll[f];
"""

name = "$RecursionLimit"
Expand Down Expand Up @@ -105,28 +83,6 @@ class IterationLimit(Predefined):

> $IterationLimit
= 1000
#> ClearAll[f]; f[x_] := f[x + 1];
#> f[x]
: Iteration limit of 1000 exceeded.
= $Aborted
#> ClearAll[f];

#> $IterationLimit = x;
: Cannot set $IterationLimit to x; value must be an integer between 20 and Infinity.

#> ClearAll[f];
#> f[x_, 0] := x; f[x_, n_] := f[x + 1, n - 1];
#> Block[{$IterationLimit = 20}, f[0, 100]]
: Iteration limit of 20 exceeded.
= $Aborted
#> ClearAll[f];

# FIX Later
# #> ClearAll[f];
# #> f[x_, 0] := x; f[x_, n_] := Module[{y = x + 1}, f[y, n - 1]];
# #> Block[{$IterationLimit = 20}, f[0, 100]]
# = 100
# #> ClearAll[f];
"""

name = "$IterationLimit"
Expand Down Expand Up @@ -280,10 +236,6 @@ class Unevaluated(Builtin):
>> g[Unevaluated[Sequence[a, b, c]]]
= g[Unevaluated[Sequence[a, b, c]]]

#> Attributes[h] = Flat;
#> h[items___] := Plus[items]
#> h[1, Unevaluated[Sequence[Unevaluated[2], 3]], Sequence[4, Unevaluated[5]]]
= 15
"""

attributes = A_HOLD_ALL_COMPLETE | A_PROTECTED
Expand Down
67 changes: 0 additions & 67 deletions mathics/builtin/procedural.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,39 +165,6 @@ class CompoundExpression(BinaryOperator):
= d
If the last argument is omitted, 'Null' is taken:
>> a;

## Parser Tests
#> FullForm[Hold[; a]]
: "FullForm[Hold[" cannot be followed by "; a]]" (line 1 of "<test>").
#> FullForm[Hold[; a ;]]
: "FullForm[Hold[" cannot be followed by "; a ;]]" (line 1 of "<test>").

## Issue331
#> CompoundExpression[x, y, z]
= z
#> %
= z

#> CompoundExpression[x, y, Null]
#> %
= y

#> CompoundExpression[CompoundExpression[x, y, Null], Null]
#> %
= y

#> CompoundExpression[x, Null, Null]
#> %
= x

#> CompoundExpression[]
#> %

## Issue 531
#> z = Max[1, 1 + x]; x = 2; z
= 3

#> Clear[x]; Clear[z]
"""

attributes = A_HOLD_ALL | A_PROTECTED | A_READ_PROTECTED
Expand Down Expand Up @@ -294,10 +261,6 @@ class Do(IterationFunction):
| 5
| 7
| 9

#> Do[Print["hi"],{1+1}]
| hi
| hi
"""

allow_loopcontrol = True
Expand Down Expand Up @@ -330,12 +293,6 @@ class For(Builtin):
= 3628800
>> n == 10!
= True

#> n := 1
#> For[i=1, i<=10, i=i+1, If[i > 5, Return[i]]; n = n * i]
= 6
#> n
= 120
"""

attributes = A_HOLD_REST | A_PROTECTED
Expand Down Expand Up @@ -473,17 +430,6 @@ class Return(Builtin):
>> g[x_] := (Do[If[x < 0, Return[0]], {i, {2, 1, 0, -1}}]; x)
>> g[-1]
= -1

#> h[x_] := (If[x < 0, Return[]]; x)
#> h[1]
= 1
#> h[-1]

## Issue 513
#> f[x_] := Return[x];
#> g[y_] := Module[{}, z = f[y]; 2]
#> g[1]
= 2
"""

rules = {
Expand Down Expand Up @@ -518,16 +464,6 @@ class Switch(Builtin):
>> Switch[2, 1]
: Switch called with 2 arguments. Switch must be called with an odd number of arguments.
= Switch[2, 1]

#> a; Switch[b, b]
: Switch called with 2 arguments. Switch must be called with an odd number of arguments.
= Switch[b, b]

## Issue 531
#> z = Switch[b, b];
: Switch called with 2 arguments. Switch must be called with an odd number of arguments.
#> z
= Switch[b, b]
"""

summary_text = "switch based on a value, with patterns allowed"
Expand Down Expand Up @@ -636,9 +572,6 @@ class While(Builtin):
>> While[b != 0, {a, b} = {b, Mod[a, b]}];
>> a
= 3

#> i = 1; While[True, If[i^2 > 100, Return[i + 1], i++]]
= 12
"""

summary_text = "evaluate an expression while a criterion is true"
Expand Down
10 changes: 0 additions & 10 deletions mathics/builtin/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ class Packages(Predefined):

X> $Packages
= {ImportExport`,XML`,Internal`,System`,Global`}
#> MemberQ[$Packages, "System`"]
= True
"""

summary_text = "list the packages loaded in the current session"
Expand All @@ -197,8 +195,6 @@ class ParentProcessID(Predefined):
>> $ParentProcessID
= ...

#> Head[$ParentProcessID] == Integer
= True
"""
summary_text = "id of the process that invoked Mathics"
name = "$ParentProcessID"
Expand All @@ -218,9 +214,6 @@ class ProcessID(Predefined):

>> $ProcessID
= ...

#> Head[$ProcessID] == Integer
= True
"""
summary_text = "id of the Mathics process"
name = "$ProcessID"
Expand Down Expand Up @@ -348,9 +341,6 @@ class SystemWordLength(Predefined):
</dl>
X> $SystemWordLength
= 64

#> Head[$SystemWordLength] == Integer
= True
"""
summary_text = "word length of computer system"
name = "$SystemWordLength"
Expand Down
93 changes: 93 additions & 0 deletions test/builtin/test_evalution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
"""
Unit tests from mathics.builtin.evaluation.
"""


from test.helper import check_evaluation, session

import pytest


@pytest.mark.parametrize(
("str_expr", "msgs", "str_expected", "fail_msg"),
[
("ClearAll[a];$RecursionLimit = 20", None, "20", None),
("a = a + a", ("Recursion depth of 20 exceeded.",), "$Aborted", None),
("$RecursionLimit = 200", None, "200", None),
(
"ClearAll[f];f[x_, 0] := x; f[x_, n_] := f[x + 1, n - 1];Block[{$RecursionLimit = 20}, f[0, 100]]",
None,
"100",
None,
),
(
"ClearAll[f];f[x_, 0] := x; f[x_, n_] := Module[{y = x + 1}, f[y, n - 1]];Block[{$RecursionLimit = 20}, f[0, 100]]",
("Recursion depth of 20 exceeded.",),
"$Aborted",
None,
),
(
"ClearAll[f]; f[x_] := f[x + 1];f[x]",
("Iteration limit of 1000 exceeded.",),
"$Aborted",
None,
),
(
"$IterationLimit = x;",
(
"Cannot set $IterationLimit to x; value must be an integer between 20 and Infinity.",
),
None,
None,
),
(
"ClearAll[f];f[x_, 0] := x; f[x_, n_] := f[x + 1, n - 1];Block[{$IterationLimit = 20}, f[0, 100]]",
("Iteration limit of 20 exceeded.",),
"$Aborted",
None,
),
("ClearAll[f];", None, None, None),
(
"Attributes[h] = Flat;h[items___] := Plus[items];h[1, Unevaluated[Sequence[Unevaluated[2], 3]], Sequence[4, Unevaluated[5]]]",
None,
"15",
None,
),
# FIX Later
(
"ClearAll[f];f[x_, 0] := x; f[x_, n_] := Module[{y = x + 1}, f[y, n - 1]];Block[{$IterationLimit = 20}, f[0, 100]]",
None,
"100",
"Fix me!",
),
("ClearAll[f];", None, None, None),
],
)
def test_private_doctests_evaluation(str_expr, msgs, str_expected, fail_msg):
"""These tests check the behavior of $RecursionLimit and $IterationLimit"""

# Here we do not use the session object to check the messages
# produced by the exceptions. If $RecursionLimit / $IterationLimit
# are reached during the evaluation using a MathicsSession object,
# an exception is raised. On the other hand, using the `Evaluation.evaluate`
# method, the exception is handled.
#
# TODO: Maybe it makes sense to clone this exception handling in
# the check_evaluation function.
#
def eval_expr(expr_str):
query = session.evaluation.parse(expr_str)
res = session.evaluation.evaluate(query)
session.evaluation.stopped = False
return res

res = eval_expr(str_expr)
if msgs is None:
assert len(res.out) == 0
else:
assert len(res.out) == len(msgs)
for li1, li2 in zip(res.out, msgs):
assert li1.text == li2

assert res.result == str_expected
3 changes: 3 additions & 0 deletions test/builtin/test_forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
"""
Unit tests from mathics.builtin.forms.
"""

from test.helper import check_evaluation, session

Expand Down
Loading