source: git/Singular/LIB/tst.lib @ 7c5f9d2

fieker-DuValspielwiese
Last change on this file since 7c5f9d2 was 9ebfb1b, checked in by Olaf Bachmann <obachman@…>, 26 years ago
* changed version to 1.2.0 git-svn-id: file:///usr/local/Singular/svn/trunk@1959 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 8.0 KB
Line 
1// $Id: tst.lib,v 1.7 1998-05-24 09:04:13 obachman Exp $
2//(obachman, last modified 2/13/98)
3/////////////////////////////////////////////////////////////////////////////
4
5version="$Id: tst.lib,v 1.7 1998-05-24 09:04:13 obachman Exp $";
6info="
7LIBRARY:  tst.lib      PROCEDURES FOR RUNNING AUTOMATIC TST TESTS
8
9
10 tst_system(s)          returns string which is stdout of system(\"sh\", s)
11 tst_ignore(any,[keyword], [link]) writes string(any) to link (or stdout),
12                                   prepending prefix \"// ignore:\"
13 tst_init()             writes some identification data to stdout
14                        with tst_ignore
15 tst_groebnerTest(ideal i) 
16                        tests groebner command
17 tst_stdEqual(ideal i1, ideal i2)
18                        test whether two std's are \"equal\"
19";
20
21/////////////////////////////////////////////////////////////////////////////
22
23proc tst_system(string s)
24"USAGE:    tst_system(s); s string
25RETURN:   string which is stdout and stderr of system(\"sh\", s)
26EXAMPLE:  example tst_system; shows examples"
27{
28  string tmpfile = "/tmp/tst_" + string(system("pid"));
29  int errno;
30
31  s = s + " 1>" + tmpfile + " 2>&1";
32  errno = system("sh", s);
33  s = read(tmpfile);
34  errno = system("sh", "rm " + tmpfile);
35  return (s);
36}
37example
38{
39  "EXAMPLE"; echo = 2;
40  string s = tst_system("echo This is is an example of tst_system");
41  "The following is what the system call wrote to stdout: " + s;
42}
43
44
45proc tst_ignore
46"USAGE:    tst_ignore(any,[keyword], [link])
47            any     -- valid argument to string()
48            keyword -- one of \"time\" or \"memory\"
49            link    -- a link which can be written to
50RETURN:   none; writes string(any) to link (or stdout, if no link given),
51          prepending prefix \"// ignore:\", or \"// ignore: time:\",
52          \"//ignore: memory:\"  if called with the respective keywords;
53          should be used in tst files to output system dependent data
54          (like date, pathnames) { and timings With the keyword \"time\",
55          resp. memory usage with the keyword \"memory\"
56EXAMPLE:  example tst_ignore; shows examples
57"
58{
59  string s;
60  string keyword = "";
61  link outlink = "";
62
63  // Check # of args
64  if (size(#) < 1 || size(#) > 3)
65  {
66    "Error tst_ignore: Wrong number of arguments";
67    "Usage: tst_ignore (any,[keyword], [link]);";
68    return();
69  }
70
71  // Get Args
72  s = string(#[1]);
73  if (size(#) == 3)
74  {
75    keyword = #[2];
76    outlink = #[3];
77  }
78  if (size(#) == 2)
79  {
80    if (typeof(#[2]) == "string")
81    {
82      keyword = #[2];
83    }
84    else
85    {
86      outlink = #[2];
87    }
88  }
89
90  // check args
91  if (typeof(keyword) != "string")
92  {
93    "Error tst_ignore: Keyword must be a string";
94    "Usage: tst_ignore (any,[keyword], [link]);";
95    return();
96  }
97  if (keyword == "time" || keyword == "memory")
98  {
99    keyword = keyword + ": ";
100  }
101  else
102  {
103    if (keyword != "")
104    {
105      "Warning tst_ignore: keyword should be \"time\" or \"memory\"";
106    }
107  }
108
109  if (status(outlink, "open", "no"))
110  {
111    open(outlink);
112  }
113  if (status(outlink, "write", "not ready"))
114  {
115    "Error tst_ignore: Can not write to link";
116    outlink;
117    "Usage: tst_ignore (any,[keyword], [link]);";
118    return();
119  }
120
121  // ready -- do the actual work
122  write(outlink, "// ignore: " + keyword + s);
123}
124example
125{
126  "EXAMPLE";
127  "System independent data can safely be output in tst files;";
128  "However, system dependent data like dates, or pathnames, should be output";
129  "using the command tst_ignore(...), like";
130  echo = 2;
131  tst_ignore(tst_system("date"));
132  int t1 = timer;
133  tst_ignore(t1, "time");
134  tst_ignore(memory(1), "memory");
135}
136
137proc tst_init
138"USAGE:   tst_init()
139RETURN:  none; writes some identification data to stdout;
140         should be called as first routine in a tst file
141EXAMPLE: example tst_init; shows example
142"
143{
144  tst_ignore("USER    : " + system("getenv", "USER"));
145  tst_ignore("HOSTNAME: " + system("getenv", "HOST"));
146  tst_ignore("uname -a: " + tst_system("uname -a"));
147  tst_ignore("date    : " + tst_system("date"));
148  tst_ignore("version : " + string(system("version")));
149}
150example
151{
152  "EXAMPLE";  echo = 2;
153  tst_init();
154}
155
156///////////////////////////////////////////////////////////////////////
157
158proc tst_groebnerTest(ideal i, list #)
159"USAGE: tst_groebnerTesti,[v]) : ideal i, [int v]
160RETURN: 1, if groebner command produced \"equal\" std as std command
161        0, otherwise
162        Two std's are \"equal\" here, if their redSB's are element-wise equal,
163        and if they reduce each other to zero, and if their leading ideals
164        are equal
165        On success, times of std - groebner is written with tst_ignore, and
166        times are added to global variables tst_std_time and
167        tst_groebner_time. If v given, and <= 0, short ideal
168        characteristic is print, if v > 0, ideals are printed.
169        On failure, Error message and ideals are printed.
170EXAMPLE: example tst_groebner; shows an example
171"
172{
173  int st = timer;
174  ideal si = std(i);
175  st = timer - st;
176 
177  int gt = timer;
178  ideal gi = groebner(i);
179  gt = timer - gt;
180
181  if (tst_stdEqual(si, gi))
182  {
183    tst_ignore(string(st) + " - " + string(gt) + " == " + string(st - gt));
184    if (! defined(tst_groebner_time))
185    {
186      int tst_groebner_time;
187      int tst_std_time;
188      export tst_groebner_time, tst_std_time;
189    }
190    tst_std_time = tst_std_time + st;
191    tst_groebner_time = tst_groebner_time + gt;
192    if (size(#))
193    {
194      if (typeof(#[1] == "int"))
195      {
196        if (#[1] <= 0)
197        {
198          idPrintShort(si, "si");
199          idPrintShort(gi, "gi");
200        }
201        else
202        {
203          si;
204          gi;
205        }
206      }
207    }
208    return (1);
209  }
210  return (0);
211}
212example
213{
214  "EXAMPLE: "; echo = 2;
215  ring r = 0, (a,b,c,d), lp;
216  ideal i = a+b+c+d, ab+ad+bc+cd, abc+abd+acd+bcd, abcd-1; // cyclic 4
217  tst_groebnerTest(i);
218  tst_groebnerTest(i, 0);
219  tst_groebnerTest(i, 1);
220}
221
222 
223//
224// A routine which test for equality of "std-bases"
225//
226proc tst_stdEqual(ideal i1, ideal i2)
227"USAGE: tst_stdEqual(i1, i2)  ideal i1, i2
228RETURN 1, if i1 \"equald\" i2 as a std bases
229       0, otherwise
230       Two std's are \"equal\" here, if their redSB's are element-wise equal,
231       and if they reduce each other to zero, and if their leading ideals
232       are equal
233       On failure, error message is printed.
234EXAMPLE: example tst_stdEqual; shows an example
235"
236{
237  int i;
238  int back;
239  intvec opts = option(get);
240  option(redSB);
241 
242  ideal ri1 = simplify(interred(i1), 1);
243  ideal ri2 = simplify(interred(i2), 1);
244 
245  option(set, opts);
246
247  if (size(ri1) != size(ri2))
248  {
249    "Error in tst_stdEqual: Reduced sizes differ";
250    size(ri1);
251    size(ri2);
252    return(0);
253  }
254
255  for (i=1; i<=size(ri1); i++)
256  {
257    if (ri1[i] != ri2[i])
258    {
259      "Error in tst_stdEqual: " + string(i) + " th poly differ";
260      ri1[i];
261      ri2[i];
262      return(0);
263    }
264  }
265
266  // reduced SB are now equal
267  if (size(reduce(i1, i2, 1)) == 0)
268  {
269    if (size(reduce(i2, i1, 1)) == 0)
270    {
271      poly p1, p2;
272     
273      ideal si1 = simplify(i1, 7);
274      ideal si2 = simplify(i2, 7);
275     
276      if (size(si1) == size(si2))
277      {
278        for (i=1; i<=size(si1); i++)
279        {
280          p1 = p1 + lead(si1[i]);
281          p2 = p2 + lead(si2[i]);
282        }
283        if (p1 != p2)
284        {
285          "Error in tst_stdEqual: Lead monoms differ:";
286          p1;
287          p2;
288          return(0);
289        }
290      }
291      else
292      {
293        "Error in tst_stdEqual: size differs:";
294        size(si1);
295        size(si2);
296        return(0);
297      }
298    }
299    else
300    {
301      "Error in tst_stdEqual: reduce(i2, i1) != 0";
302      return(0);
303    }
304  }
305  else
306  {
307    back = 1; "Error in tst_stdEqual: reduce(i1, i2) != 0";
308    return(0);
309  }
310
311  return (1);
312}
313example
314{
315  "EXAMPLE: "; echo = 2;
316  ring r = 0, (a,b,c,d), lp;
317  ideal i = a+b+c+d, ab+ad+bc+cd, abc+abd+acd+bcd, abcd-1; // cyclic 4
318  tst_stdEqual(groebner(i), std(i));
319  tst_stdEqual(std(i), i);
320}
321
322static proc idPrintShort(ideal id, string name)
323{
324  "Summary of " + name + " (leading monoms and size of polys):";
325  int i;
326  for (i = 1; i<=size(id); i++)
327  {
328    "[" + string(i) + "]: #" + string(size(id[i])) + ":" + string(lead(id[i]));
329  }
330}
331
332 
333
334
Note: See TracBrowser for help on using the repository browser.