Skip to content

Commit

Permalink
moving private doctests to pytests for physchemdata, tensor, statisti…
Browse files Browse the repository at this point in the history
…cs and vector (#926)

Another round
  • Loading branch information
mmatera authored Oct 16, 2023
1 parent ada9d82 commit 62b8c5e
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 33 deletions.
3 changes: 0 additions & 3 deletions mathics/builtin/physchemdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ class ElementData(Builtin):
>> ListPlot[Table[ElementData[z, "AtomicWeight"], {z, 118}]]
= -Graphics-
## Ensure all data parses #664
#> Outer[ElementData, Range[118], ElementData["Properties"]];
"""

messages = {
Expand Down
3 changes: 0 additions & 3 deletions mathics/builtin/statistics/orderstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,6 @@ class Sort(Builtin):
= {2 + c_, 1 + b__}
>> Sort[{x_ + n_*y_, x_ + y_}, PatternsOrderedQ]
= {x_ + n_ y_, x_ + y_}
#> Sort[{x_, y_}, PatternsOrderedQ]
= {x_, y_}
"""

summary_text = "sort lexicographically or with any comparison function"
Expand Down
16 changes: 0 additions & 16 deletions mathics/builtin/tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ class Dimensions(Builtin):
The expression can have any head:
>> Dimensions[f[f[a, b, c]]]
= {1, 3}
#> Dimensions[{}]
= {0}
#> Dimensions[{{}}]
= {1, 0}
"""

summary_text = "the dimensions of a tensor"
Expand Down Expand Up @@ -202,15 +197,6 @@ class Inner(Builtin):
Inner works with tensors of any depth:
>> Inner[f, {{{a, b}}, {{c, d}}}, {{1}, {2}}, g]
= {{{g[f[a, 1], f[b, 2]]}}, {{g[f[c, 1], f[d, 2]]}}}
## Issue #670
#> A = {{ b ^ ( -1 / 2), 0}, {a * b ^ ( -1 / 2 ), b ^ ( 1 / 2 )}}
= {{1 / Sqrt[b], 0}, {a / Sqrt[b], Sqrt[b]}}
#> A . Inverse[A]
= {{1, 0}, {0, 1}}
#> A
= {{1 / Sqrt[b], 0}, {a / Sqrt[b], Sqrt[b]}}
"""

messages = {
Expand Down Expand Up @@ -489,8 +475,6 @@ class Transpose(Builtin):
= True
#> Clear[matrix, square]
#> Transpose[x]
= Transpose[x]
"""

summary_text = "transpose to rearrange indices in any way"
Expand Down
11 changes: 0 additions & 11 deletions mathics/builtin/vectors/vector_space_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@ class Normalize(Builtin):
>> Normalize[1 + I]
= (1 / 2 + I / 2) Sqrt[2]
#> Normalize[0]
= 0
#> Normalize[{0}]
= {0}
#> Normalize[{}]
= {}
"""

rules = {"Normalize[v_]": "Module[{norm = Norm[v]}, If[norm == 0, v, v / norm, v]]"}
Expand Down Expand Up @@ -228,9 +220,6 @@ class VectorAngle(Builtin):
>> VectorAngle[{1, 1, 0}, {1, 0, 1}]
= Pi / 3
#> VectorAngle[{0, 1}, {0, 1}]
= 0
"""

rules = {"VectorAngle[u_, v_]": "ArcCos[u.v / (Norm[u] Norm[v])]"}
Expand Down
32 changes: 32 additions & 0 deletions test/builtin/test_physchemdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
"""
Unit tests for mathics.builtins.physchemdata
"""

from test.helper import check_evaluation

import pytest


@pytest.mark.parametrize(
("str_expr", "msgs", "str_expected", "fail_msg"),
[
(
'Outer[ElementData, Range[118], ElementData["Properties"]];',
None,
"Null",
"Ensure all data parses #664",
),
],
)
def test_private_doctests_physchemdata(str_expr, msgs, str_expected, fail_msg):
""" """
check_evaluation(
str_expr,
str_expected,
to_string_expr=True,
to_string_expected=True,
hold_expected=False,
failure_message=fail_msg,
expected_messages=msgs,
)
31 changes: 31 additions & 0 deletions test/builtin/test_statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
"""
Unit tests from mathics.builtin.statistics.
"""

import sys
import time
from test.helper import check_evaluation, evaluate

import pytest


@pytest.mark.parametrize(
("str_expr", "msgs", "str_expected", "fail_msg"),
[
("Sort[{x_, y_}, PatternsOrderedQ]", None, "{x_, y_}", None),
],
)
def test_private_doctests_statistics_orderstatistics(
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,
)
41 changes: 41 additions & 0 deletions test/builtin/test_tensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
"""
Unit tests from mathics.builtin.tensor.
"""

import sys
import time
from test.helper import check_evaluation, evaluate

import pytest


@pytest.mark.parametrize(
("str_expr", "msgs", "str_expected", "fail_msg"),
[
("Dimensions[{}]", None, "{0}", None),
("Dimensions[{{}}]", None, "{1, 0}", None),
## Issue #670
(
"A = {{ b ^ ( -1 / 2), 0}, {a * b ^ ( -1 / 2 ), b ^ ( 1 / 2 )}}",
None,
"{{1 / Sqrt[b], 0}, {a / Sqrt[b], Sqrt[b]}}",
None,
),
("A . Inverse[A]", None, "{{1, 0}, {0, 1}}", None),
("A", None, "{{1 / Sqrt[b], 0}, {a / Sqrt[b], Sqrt[b]}}", None),
# Transpose
("Transpose[x]", None, "Transpose[x]", None),
],
)
def test_private_doctests_tensor(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,
)
34 changes: 34 additions & 0 deletions test/builtin/vectors/test_vector_space_operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
"""
Unit tests from mathics.builtin.vectors.vector_space_operations.
"""

import sys
import time
from test.helper import check_evaluation, evaluate

import pytest


@pytest.mark.parametrize(
("str_expr", "msgs", "str_expected", "fail_msg"),
[
("Normalize[0]", None, "0", None),
("Normalize[{0}]", None, "{0}", None),
("Normalize[{}]", None, "{}", None),
("VectorAngle[{0, 1}, {0, 1}]", None, "0", None),
],
)
def test_private_doctests_vector_space_operations(
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,
)

0 comments on commit 62b8c5e

Please sign in to comment.