2 * test3500 - 3500 series of the regress.cal test suite
4 * Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
6 * Primary author: Ernest Bowen
8 * Calc is open software; you can redistribute it and/or modify it under
9 * the terms of the version 2.1 of the GNU Lesser General Public License
10 * as published by the Free Software Foundation.
12 * Calc is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15 * Public License for more details.
17 * A copy of version 2.1 of the GNU Lesser General Public License is
18 * distributed with calc under the filename COPYING-LGPL. You should have
19 * received a copy with calc; if not, write to Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * @(#) $Revision: 30.1 $
23 * @(#) $Id: test3500.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
24 * @(#) $Source: /usr/local/src/bin/calc/cal/RCS/test3500.cal,v $
26 * Under source code control: 1995/12/18 22:50:46
27 * File existed as early as: 1995
29 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
33 * Stringent tests of the functions frem, fcnt, gcdrem.
35 * testf(n) gives n tests of frem(x,y) and fcnt(x,y) with randomly
36 * integers x and y generated so that x = f * y^k where f, y and
37 * k are randomly generated.
39 * testg(n) gives n tests of gcdrem(x,y) with x and y generated as for
42 * testh(n,N) gives n tests of g = gcdrem(x,y) where x and y are products of
43 * powers of small primes some of which are common to both x and y.
44 * This test uses f = abs(x) and iteratively f = frem(f,p) where
45 * p varies over the prime divisors of y; the final value for f
46 * should equal g. For both x and y the primes are raised to the
47 * power rand(N); N defaults to 10.
49 * If verbose is > 1, the numbers x, y and values for some of the
50 * functions will be displayed. Numbers used in testf()
51 * and testg() occasionally have thousands of digits.
56 defaultverbose = 1; /* default verbose value */
58 define testfrem(x,y,verbose)
62 if (isnull(verbose)) verbose = defaultverbose;
67 printf("frem = %d, fcnt = %d\n\n", f, n);
68 if (abs(x) != f * abs(y)^n)
70 if (!ismult(x,y) || abs(y) <= 1) {
82 if (f < 0 || !isint(f) || n <= 0)
88 if (ismult(x, y^(n+1)))
93 define testgcdrem(x,y,verbose)
97 if (isnull(verbose)) verbose = defaultverbose;
101 printf("gcdrem = %d\n\n", d);
124 define testf(str,n,verbose)
126 local m, x, y, i, k, y1, f1, f, fail;
129 verbose = defaultverbose;
134 for (i = 0; i < n; i++) {
135 y1 = rand(2^rand(1,6));
136 y = rand(-(2^y1), 1 + 2^y1);
137 f1 = rand(2^rand(1,11));
138 f = rand(-(2^f1), 1+2^f1);
142 printf("x = %d\n", x);
143 printf("y = %d\n", y);
145 fail = testfrem(x,y,verbose);
147 printf("*** Failure %d on loop %d\n", fail, i);
149 printf(" x = %d\n", x);
150 printf(" y = %d\n", y);
158 printf("*** %d error(s)\n", m);
160 printf("no errors\n");
167 define testg(str,n,verbose)
169 local m, x, y, i, k, y1, f1, f, fail;
172 verbose = defaultverbose;
177 for (i = 0; i < n; i++) {
178 y1 = rand(2^rand(1,6));
179 y = rand(-(2^y1), 1 + 2^y1);
180 f1 = rand(2^rand(1,11));
181 f = rand(-(2^f1), 1+2^f1);
185 printf("x = %d\n", x);
186 printf("y = %d\n", y);
188 fail = testgcdrem(x,y,verbose);
190 printf("*** Failure %d on loop %d\n", fail, i);
192 printf(" x = %d\n", x);
193 printf(" y = %d\n", y);
201 printf("*** %d error(s)\n", m);
203 printf("no errors\n");
209 define testh(str,n,N,verbose)
211 local m, i, x, y, f, g;
214 verbose = defaultverbose;
221 for (i = 0; i < n; i ++) {
222 x = 2^rand(N)*3^rand(N) * 7^rand(N) * 11^rand(N) * 101^rand(N);
223 y = 2^rand(N) * 3^rand(N) * 5^rand(N) * 11^rand(N) * 53^rand(N);
228 printf("x = %d\n", x);
229 printf("y = %d\n", y);
233 if (ismult(y,2)) f = frem(f,2);
234 if (ismult(y,3)) f = frem(f,3);
235 if (ismult(y,5)) f = frem(f,5);
236 if (ismult(y,11)) f = frem(f,11);
237 if (ismult(y,53)) f = frem(f,53);
240 printf("*** Failure on loop %d\n", i);
242 printf(" x = %d\n", x);
243 printf(" y = %d\n", y);
244 printf(" f = %d\n", f);
245 printf(" g = %d\n", g);
253 printf("*** %d error(s)\n", m);
255 printf("no errors\n");
262 * test3500 - perform all of the above tests a bunch of times
264 define test3500(verbose, tnum, n, N)
266 /* set test parameters */
267 if (isnull(verbose)) {
268 verbose = defaultverbose;
271 tnum = 3501; /* default test number */
281 * test a lot of stuff
284 err += testf(strcat(str(tnum++), ": frem/fcnt"), n, verbose);
285 err += testg(strcat(str(tnum++), ": gcdrem"), n, verbose);
286 err += testh(strcat(str(tnum++),": gcdrem #2"), n, N, verbose);
289 print "***", err, "error(s) found in testall";
291 print "no errors in testall";