Windows installer: update wxMaxima.
[maxima/cygwin.git] / tests / rtestlabels.mac
blob09ec0250227df3b1cedc3ce48b9fc6f591257278
1 (load (stringproc),
2  kill (all),
3  nolabels: true,
4  0);
5 0;
7 (f(x) := x,
8  g(x) := x^2,
9  h(x) := x^3,
10  m(x) ::= x,
11  n(x) ::= x^2,
12  o(x) ::= x^3,
13  tellsimpafter (foo(x), bar(x)),
14  tellsimpafter (bar(x), baz(x)),
15  L2: dispfun (g, n),
16  L3: dispfun (all),
17  L4: disprule (barrule1),
18  L5: disprule (all),
19  0);
22 (ensure_string (x) := if stringp (x) then x else string (x),
23  my_every (p, L) := apply ("and", map (is, map (p, L))),
24  my_some (p, L) := apply ("or", map (is, map (p, L))),
25  my_none (p, L) := apply ("and", map ("not", map (is, map (p, L)))),
26  matchdeclare (aa, symbolp, [bb, cc], true),
27  defmatch (rulep, aa: ?marrow (bb, cc)),
28  defmatch (fundefp, bb := cc),
29  defmatch (macrodefp, bb ::= cc),
30  0);
33 ''L2;
34 [g(x) := x^2, n(x) ::= x^2];
36 ''L3;
37 [f(x) := x, g(x) := x^2, h(x) := x^3, m(x) ::= x, n(x) ::= x^2, o(x) ::= x^3];
39 ''L4;
40 '[barrule1 : ?marrow (bar(x), baz(x))];
42 (my_every (lambda ([x], substring (ensure_string (x), 1, 3) = ensure_string (linechar)), L5)
43  and my_every (lambda ([x], rulep(x)#false), ''L5));
44 true;
46 /* At this point, all labels are %t labels from rules, functions, and macros.
47  */
48 (map (lambda ([x], rulep(x)#false or fundefp(x)#false or macrodefp(x)#false), ''labels),
49  my_every (lambda ([x], substring (ensure_string (x), 1, 3) = ensure_string (linechar)), labels)
50  and my_every (identity, %%));
51 true;
53 [%i1, %o1, %i2, %o2, %i3, %o3, %i4, %o4, %i5, %o5];
54 '[%i1, %o1, %i2, %o2, %i3, %o3, %i4, %o4, %i5, %o5];
56 /* Some tests for solve and linsolve.
57  */
58 /* Test 1: nolabels = true, programmode = true, globalsolve = false
59  *  => solve & linsolve return lists of solutions
60  */
61 (globalsolve: false,
62  solve (asin (cos (3*x)), x));
63 [x = %pi/6];
65 linsolve ([x + 2*y = 5, 2*x - y = 5], [x, y]);
66 [x = 3, y = 1];
68 /* Test 2: nolabels = true, programmode = false, globalsolve = false
69  *  => solve & linsolve return lists of %t labels
70  *     and each %t label is on the labels infolist
71  *     and each %t label is bound to an equation
72  */
73 (programmode: false,
74  L: append (solve (asin (cos (3*x)), x), linsolve ([x + 2*y = 5, 2*x - y = 5], [x, y])),
75  my_every (lambda ([x], substring (ensure_string (x), 1, 3) = ensure_string (linechar)), L)
76   and my_every (lambda ([x], my_some (lambda ([y], buildq ([x, y], 'y = 'x)), labels)), L));
77 true;
79 ''L;
80 [x = %pi/6, x = 3, y = 1];
82 /* Test 3: nolabels = true, programmode = false, globalsolve = true
83  *  => solve & linsolve return lists of %t labels
84  *     and each %t labels is on the labels infolist
85  *     and the labels returned by solve are bound to equations
86  *     and the labels returned by linsolve are bound to assignments
87  */
88 (globalsolve: true,
89  L: append (solve (asin (cos (3*x)), x), linsolve ([x + 2*y = 5, 2*x - y = 5], [x, y])),
90  [my_every (lambda ([x], substring (ensure_string (x), 1, 3) = ensure_string (linechar)), L)
91    and my_every (lambda ([x], my_some (lambda ([y], buildq ([x, y], 'y = 'x)), labels)), L),
92   x, y]);
93 [true, 3, 1];
95 ''L;
96 '[x = %pi/6, x : 3, y : 1];
98 /* Test 4: nolabels = true, programmode = true, globalsolve = true
99  *  => solve returns equations
100  *     linsolve assigns values and returns assignments
101  *     no %t labels generated
102  */
103 (programmode: true,
104  kill (x, y),
105  save_labels: copylist (labels),
106  [linsolve ([x + 2*y = 5, 2*x - y = 5], [x, y]),
107  x, y,
108  is (equal (labels, save_labels))]);
109 ['[x : 3, y : 1], 3, 1, true];
111 /* Restore the status quo ante.
112  */
113 globalsolve: false;
114 false;
116 /* Now repeat all of the preceding tests,
117  * but this time with nolabels = false.
118  * %t labels should still be bound to rules, functions, and macros,
119  * but there should also be some input and output labels bound as well.
120  */
121 (kill (all),
122  nolabels: false,
123  0);
126 (f(x) := x,
127  g(x) := x^2,
128  h(x) := x^3,
129  m(x) ::= x,
130  n(x) ::= x^2,
131  o(x) ::= x^3,
132  tellsimpafter (foonew(x), bar(x)),
133  tellsimpafter (barnew(x), baz(x)),
134  L2: dispfun (g, n),
135  L3: dispfun (all),
136  L4: disprule (barnewrule1),
137  L5: disprule (all),
138  0);
141 (ensure_string (x) := if stringp (x) then x else string (x),
142  my_every (p, L) := apply ("and", map (is, map (p, L))),
143  my_some (p, L) := apply ("or", map (is, map (p, L))),
144  my_none (p, L) := apply ("and", map ("not", map (is, map (p, L)))),
145  matchdeclare (aa, symbolp, [bb, cc], true),
146  defmatch (rulep, aa: ?marrow (bb, cc)),
147  defmatch (fundefp, bb := cc),
148  defmatch (macrodefp, bb ::= cc),
149  0);
152 ''L2;
153 [g(x) := x^2, n(x) ::= x^2];
155 ''L3;
156 [f(x) := x, g(x) := x^2, h(x) := x^3, m(x) ::= x, n(x) ::= x^2, o(x) ::= x^3];
158 ''L4;
159 '[barnewrule1 : ?marrow (barnew(x), baz(x))];
161 (my_every (lambda ([x], substring (ensure_string (x), 1, 3) = ensure_string (linechar)), L5)
162  and my_every (lambda ([x], rulep(x)#false), ''L5));
163 true;
165 /* Now there should be some labels which are not %t labels.
166  * NOTE: the expected result (false) is observed only if this script is executed
167  * via batch("rtestlabels.mac"), because then Maxima creates input and output labels.
168  * When executed via batch(..., test), no input or output labels are created,
169  * so the test fails.
170  */
171 (map (lambda ([x], rulep(x)#false or fundefp(x)#false or macrodefp(x)#false), ''labels),
172  my_every (lambda ([x], substring (ensure_string (x), 1, 3) = ensure_string (linechar)), labels)
173  and my_every (identity, %%));
174 false;
176 /* See NOTE attached to preceding example
177  */
178 labels (inchar) # [] and my_every (?boundp, labels (inchar))
179  and labels (outchar) # [] and my_every (?boundp, labels (outchar));
180 true;
182 /* Repeat the tests for solve and linsolve.
183  * The outcomes should be the same as before.
184  */
185 /* Test 1: nolabels = true, programmode = true, globalsolve = false
186  *  => solve & linsolve return lists of solutions
187  */
188 (globalsolve: false,
189  solve (asin (cos (3*x)), x));
190 [x = %pi/6];
192 linsolve ([x + 2*y = 5, 2*x - y = 5], [x, y]);
193 [x = 3, y = 1];
195 /* Test 2: nolabels = true, programmode = false, globalsolve = false
196  *  => solve & linsolve return lists of %t labels
197  *     and each %t label is on the labels infolist
198  *     and each %t label is bound to an equation
199  */
200 (programmode: false,
201  L: append (solve (asin (cos (3*x)), x), linsolve ([x + 2*y = 5, 2*x - y = 5], [x, y])),
202  my_every (lambda ([x], substring (ensure_string (x), 1, 3) = ensure_string (linechar)), L)
203   and my_every (lambda ([x], my_some (lambda ([y], buildq ([x, y], 'y = 'x)), labels)), L));
204 true;
206 ''L;
207 [x = %pi/6, x = 3, y = 1];
209 /* Test 3: nolabels = true, programmode = false, globalsolve = true
210  *  => solve & linsolve return lists of %t labels
211  *     and each %t labels is on the labels infolist
212  *     and the labels returned by solve are bound to equations
213  *     and the labels returned by linsolve are bound to assignments
214  */
215 (globalsolve: true,
216  L: append (solve (asin (cos (3*x)), x), linsolve ([x + 2*y = 5, 2*x - y = 5], [x, y])),
217  [my_every (lambda ([x], substring (ensure_string (x), 1, 3) = ensure_string (linechar)), L)
218    and my_every (lambda ([x], my_some (lambda ([y], buildq ([x, y], 'y = 'x)), labels)), L),
219   x, y]);
220 [true, 3, 1];
222 ''L;
223 '[x = %pi/6, x : 3, y : 1];
225 /* Test 4: nolabels = true, programmode = true, globalsolve = true
226  *  => solve returns equations
227  *     linsolve assigns values and returns assignments
228  *     no %t labels generated
229  */
230 (programmode: true,
231  kill (x, y),
232  save_labels: copylist (labels),
233  [linsolve ([x + 2*y = 5, 2*x - y = 5], [x, y]),
234  x, y,
235  is (equal (labels, save_labels))]);
236 ['[x : 3, y : 1], 3, 1, true];
238 /* Restore the status quo ante.
239  */
240 globalsolve: false;
241 false;
243 my_every (?boundp, labels);
244 true;