-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathSetReplaceList.wlt
114 lines (89 loc) · 3.12 KB
/
SetReplaceList.wlt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<|
"SetReplaceList" -> <|
"init" -> (
Attributes[Global`testUnevaluated] = Attributes[Global`testSymbolLeak] = {HoldAll};
Global`testUnevaluated[args___] := SetReplace`PackageScope`testUnevaluated[VerificationTest, args];
Global`testSymbolLeak[args___] := SetReplace`PackageScope`testSymbolLeak[VerificationTest, args];
),
"tests" -> {
(* Symbol Leak *)
testSymbolLeak[
SetReplaceList[Range[100], {a_, b_} :> {a + b}, 5]
],
(* Argument Checks *)
(** Argument count **)
testUnevaluated[
SetReplaceList[{1}],
{SetReplaceList::argtu}
],
testUnevaluated[
SetReplaceList[{1}, {2 -> 5, 3 :> 6}, 10, 10],
{SetReplaceList::argt}
],
(** Set is a list **)
testUnevaluated[
SetReplaceList[1, 1 -> 2, 2],
{SetReplaceList::setNotList}
],
(** Rules are valid **)
testUnevaluated[
SetReplaceList[{1}, {1}, 1],
{SetReplaceList::invalidRules}
],
(** Step count is valid **)
testUnevaluated[
SetReplaceList[{1}, {1 -> 2}, -1],
{SetReplaceList::nonIntegerIterations}
],
(** Options are valid **)
testUnevaluated[
SetReplaceList[{1, 2, 3}, {2 -> 5, 3 :> 6, 5 :> 9}, # -> 123],
{SetReplaceList::optx}
] & /@ {"$$$InvalidOption###", "EventSelectionFunction"},
(* Implementation *)
VerificationTest[
SetReplaceList[{1, 2, 3}, {2 -> 5, 3 :> 6, 5 :> 9}, 10],
{{1, 2, 3}, {1, 3, 5}, {1, 5, 6}, {1, 6, 9}}
],
VerificationTest[
SetReplaceList[{1, 2, 3}, {2 -> 5, 3 :> 6, 5 :> 9}, Infinity],
{{1, 2, 3}, {1, 3, 5}, {1, 5, 6}, {1, 6, 9}}
],
VerificationTest[
SetReplaceList[{1, 2, 3}, {2 -> 5, 3 :> 6, 5 :> 9}, 1],
{{1, 2, 3}, {1, 3, 5}}
],
VerificationTest[
SetReplaceList[{{1}, {2}, {3}}, {{{2}} -> {{5}}, {{3}} :> {{6}}, {{5}} :> {{9}}}, 2, Method -> "LowLevel"],
{{{1}, {2}, {3}}, {{1}, {3}, {5}}, {{1}, {5}, {6}}}
],
VerificationTest[
SetReplaceList[{{1}, {2}, {3}}, {{{2}} -> {{5}}, {{3}} :> {{6}}, {{5}} :> {{9}}}, 2, Method -> "Symbolic"],
{{{1}, {2}, {3}}, {{1}, {3}, {5}}, {{1}, {5}, {6}}}
],
VerificationTest[
SetReplaceList[{{1, 2}, {2, 3}, {3, 1}}, {{a_, b_}, {b_, c_}} :> {{a, c}}, 2],
{{{1, 2}, {2, 3}, {3, 1}}, {{3, 1}, {1, 3}}, {{3, 3}}}
],
VerificationTest[
SetReplaceList[{}, {} :> {{1, 2}}, 2],
{{}, {{1, 2}}, {{1, 2}, {1, 2}}}
],
VerificationTest[
SetReplaceList[{{1, 2}}, {{1, 2}} :> {{1, 2}}, 2],
{{{1, 2}}, {{1, 2}}, {{1, 2}}}
],
(* TimeConstraint *)
VerificationTest[
SetReplaceList[
{{0, 0}}, ToPatternRules[{{1, 2}} -> {{1, 3}, {3, 2}}], 100000, Method -> #, TimeConstraint -> 0.1],
$Aborted
] & /@ $SetReplaceMethods,
VerificationTest[
TimeConstrained[
SetReplaceList[{{0, 0}}, ToPatternRules[{{1, 2}} -> {{1, 3}, {3, 2}}], 100000, Method -> #], 0.1],
$Aborted
] & /@ $SetReplaceMethods
}
|>
|>