Skip to content

Commit fd299ff

Browse files
authored
Merge pull request #1408 from mathics/more-unit-tests
More doctests moved to unit tests
2 parents f0abdef + 5236ee8 commit fd299ff

4 files changed

Lines changed: 68 additions & 62 deletions

File tree

mathics/builtin/strings.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -477,23 +477,6 @@ class NumberString(Builtin):
477477
478478
>> StringMatchQ["1.2`20", NumberString]
479479
= False
480-
481-
#> StringMatchQ[".12", NumberString]
482-
= True
483-
#> StringMatchQ["12.", NumberString]
484-
= True
485-
#> StringMatchQ["12.31.31", NumberString]
486-
= False
487-
#> StringMatchQ[".", NumberString]
488-
= False
489-
#> StringMatchQ["-1.23", NumberString]
490-
= True
491-
#> StringMatchQ["+12.3", NumberString]
492-
= True
493-
#> StringMatchQ["+.2", NumberString]
494-
= True
495-
#> StringMatchQ["1.2e4", NumberString]
496-
= False
497480
"""
498481

499482

@@ -867,17 +850,6 @@ class DigitQ(Builtin):
867850
>> DigitQ["-123456789"]
868851
= False
869852
870-
#> DigitQ[""]
871-
= True
872-
873-
#> DigitQ["."]
874-
= False
875-
876-
#> DigitQ[1==2]
877-
= False
878-
879-
#> DigitQ[a=1]
880-
= False
881853
"""
882854

883855
rules = {

mathics/builtin/structure.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -947,18 +947,6 @@ class Flatten(Builtin):
947947
>> Flatten[{{1, 2, 3}, {4}, {6, 7}, {8, 9, 10}}, {{2}, {1}}]
948948
= {{1, 4, 6, 8}, {2, 7, 9}, {3, 10}}
949949
950-
#> Flatten[{{{111, 112, 113}, {121, 122}}, {{211, 212}, {221, 222, 223}}}, {{3}, {1}, {2}}]
951-
= {{{111, 121}, {211, 221}}, {{112, 122}, {212, 222}}, {{113}, {223}}}
952-
953-
#> Flatten[{{{1, 2, 3}, {4, 5}}, {{6, 7}, {8, 9, 10}}}, {{3}, {1}, {2}}]
954-
= {{{1, 4}, {6, 8}}, {{2, 5}, {7, 9}}, {{3}, {10}}}
955-
956-
#> Flatten[{{{1, 2, 3}, {4, 5}}, {{6, 7}, {8, 9, 10}}}, {{2}, {1, 3}}]
957-
= {{1, 2, 3, 6, 7}, {4, 5, 8, 9, 10}}
958-
959-
#> Flatten[{{1, 2}, {3,4}}, {1, 2}]
960-
= {1, 2, 3, 4}
961-
962950
#> Flatten[{{1, 2}, {3, 4}}, {{-1, 2}}]
963951
: Levels to be flattened together in {{-1, 2}} should be lists of positive integers.
964952
= Flatten[{{1, 2}, {3, 4}}, {{-1, 2}}, List]
@@ -969,29 +957,15 @@ class Flatten(Builtin):
969957
970958
## Check `n` completion
971959
#> m = {{{1, 2}, {3}}, {{4}, {5, 6}}};
972-
#> Flatten[m, {2}]
973-
= {{{1, 2}, {4}}, {{3}, {5, 6}}}
974-
#> Flatten[m, {{2}}]
975-
= {{{1, 2}, {4}}, {{3}, {5, 6}}}
976-
#> Flatten[m, {{2}, {1}}]
977-
= {{{1, 2}, {4}}, {{3}, {5, 6}}}
978-
#> Flatten[m, {{2}, {1}, {3}}]
979-
= {{{1, 2}, {4}}, {{3}, {5, 6}}}
980960
#> Flatten[m, {{2}, {1}, {3}, {4}}]
981961
: Level 4 specified in {{2}, {1}, {3}, {4}} exceeds the levels, 3, which can be flattened together in {{{1, 2}, {3}}, {{4}, {5, 6}}}.
982962
= Flatten[{{{1, 2}, {3}}, {{4}, {5, 6}}}, {{2}, {1}, {3}, {4}}, List]
983963
984-
## #251 tests
964+
## Test from issue #251
985965
#> m = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
986-
#> Flatten[m, {1}]
987-
= {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
988-
#> Flatten[m, {2}]
989-
= {{1, 4, 7}, {2, 5, 8}, {3, 6, 9}}
990966
#> Flatten[m, {3}]
991967
: Level 3 specified in {3} exceeds the levels, 2, which can be flattened together in {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}.
992968
= Flatten[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, {3}, List]
993-
#> Flatten[m, {2, 1}]
994-
= {1, 4, 7, 2, 5, 8, 3, 6, 9}
995969
996970
## Reproduce strange head behaviour
997971
#> Flatten[{{1}, 2}, {1, 2}]
@@ -1001,16 +975,9 @@ class Flatten(Builtin):
1001975
: Level 1 specified in {1, 2} exceeds the levels, 0, which can be flattened together in a[b[1, 2], b[3]].
1002976
= Flatten[a[b[1, 2], b[3]], {1, 2}, b]
1003977
1004-
#> Flatten[{{1, 2}, {3, {4}}}, {{1, 2}}]
1005-
= {1, 2, 3, {4}}
1006978
#> Flatten[{{1, 2}, {3, {4}}}, {{1, 2, 3}}]
1007979
: Level 3 specified in {{1, 2, 3}} exceeds the levels, 2, which can be flattened together in {{1, 2}, {3, {4}}}.
1008980
= Flatten[{{1, 2}, {3, {4}}}, {{1, 2, 3}}, List]
1009-
1010-
#> Flatten[p[1, p[2], p[3]]]
1011-
= p[1, 2, 3]
1012-
#> Flatten[p[1, p[2], p[3]], 2]
1013-
= p[1, 2, 3]
1014981
"""
1015982

1016983
rules = {

test/test_strings.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# -*- coding: utf-8 -*-
2+
from .helper import check_evaluation
3+
4+
5+
def test_string_matchq():
6+
for str_expr, str_expected in (
7+
('StringMatchQ[".12", NumberString]', "True"),
8+
('StringMatchQ["12.", NumberString]', "True"),
9+
('StringMatchQ["12.31.31", NumberString]', "False"),
10+
('StringMatchQ[".", NumberString]', "False"),
11+
('StringMatchQ["-1.23", NumberString]', "True"),
12+
('StringMatchQ["+.2", NumberString]', "True"),
13+
('StringMatchQ["1.2e4", NumberString]', "False"),
14+
('StringMatchQ["abc", "ABC"]', "False"),
15+
('StringMatchQ["abc", "ABC", IgnoreCase -> True]', "True"),
16+
# ('StringMatchQ["abc1", LetterCharacter]', "False"),
17+
):
18+
check_evaluation(str_expr, str_expected)
19+
20+
21+
def test_digitq():
22+
for str_expr, str_expected in (
23+
('DigitQ[""]', "True"),
24+
('DigitQ["."]', "False"),
25+
("DigitQ[1==2]", "False"),
26+
("DigitQ[a=1]", "False"),
27+
):
28+
check_evaluation(str_expr, str_expected)

test/test_structure.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
from .helper import check_evaluation
3+
4+
5+
def test_flatten():
6+
for str_expr, str_expected in (
7+
(
8+
"Flatten[{{{111, 112, 113}, {121, 122}}, {{211, 212}, {221, 222, 223}}}, {{3}, {1}, {2}}]",
9+
"{{{111, 121}, {211, 221}}, {{112, 122}, {212, 222}}, {{113}, {223}}}",
10+
),
11+
(
12+
"Flatten[{{{1, 2, 3}, {4, 5}}, {{6, 7}, {8, 9, 10}}}, {{3}, {1}, {2}}]",
13+
"{{{1, 4}, {6, 8}}, {{2, 5}, {7, 9}}, {{3}, {10}}}",
14+
),
15+
(
16+
"Flatten[{{{1, 2, 3}, {4, 5}}, {{6, 7}, {8, 9, 10}}}, {{2}, {1, 3}}]",
17+
"{{1, 2, 3, 6, 7}, {4, 5, 8, 9, 10}}",
18+
),
19+
("Flatten[{{1, 2}, {3,4}}, {1, 2}]", "{1, 2, 3, 4}"),
20+
(
21+
"m = {{{1, 2}, {3}}, {{4}, {5, 6}}}; Flatten[m, {2}]",
22+
"{{{1, 2}, {4}}, {{3}, {5, 6}}}",
23+
),
24+
("Flatten[m, {{2}}]", "{{{1, 2}, {4}}, {{3}, {5, 6}}}"),
25+
("Flatten[m, {{2}, {1}}]", "{{{1, 2}, {4}}, {{3}, {5, 6}}}"),
26+
("Flatten[m, {{2}, {1}, {3}}]", "{{{1, 2}, {4}}, {{3}, {5, 6}}}"),
27+
# Tests from Issue #251
28+
(
29+
"m = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; Flatten[m, {1}]",
30+
"{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}",
31+
),
32+
("Flatten[m, {2}]", "{{1, 4, 7}, {2, 5, 8}, {3, 6, 9}}"),
33+
("Flatten[m, {2, 1}]", "{1, 4, 7, 2, 5, 8, 3, 6, 9}"),
34+
#
35+
("Flatten[{{1, 2}, {3, {4}}}, {{1, 2}}]", "{1, 2, 3, {4}}"),
36+
("Flatten[p[1, p[2], p[3]]]", "p[1, 2, 3]"),
37+
("Flatten[p[1, p[2], p[3]], 2]", "p[1, 2, 3]"),
38+
):
39+
check_evaluation(str_expr, str_expected)

0 commit comments

Comments
 (0)