1/* 2 * test3300 - 3300 series of the regress.cal test suite 3 * 4 * Copyright (C) 1999 Ernest Bowen and Landon Curt Noll 5 * 6 * Primary author: Ernest Bowen 7 * 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. 11 * 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. 16 * 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. 21 * 22 * Under source code control: 1995/12/02 04:27:41 23 * File existed as early as: 1995 24 * 25 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/ 26 */ 27 28 29defaultverbose = 1; /* default verbose value */ 30 31define testi(str, n, N, verbose) 32{ 33 local A, t, i, j, d1, d2; 34 local m; 35 36 if (isnull(verbose)) verbose = defaultverbose; 37 if (verbose > 0) { 38 print str:":",:; 39 } 40 if (isnull(N)) 41 N = 1e6; 42 mat A[n,n]; 43 for (i = 0; i < n; i++) 44 for (j = 0; j < n; j++) 45 A[i,j] = rand(-N, N); 46 t = runtime(); 47 d1 = det(A); 48 t = runtime() - t; 49 d2 = det(A^2); 50 if (d2 != d1^2) { 51 if (verbose > 0) { 52 printf("*** Failure for n=%d, N=%d, d1=%d\n", n, N, d1); 53 } 54 return 1; /* error */ 55 } else { 56 if (verbose > 0) { 57 printf("no errors\n"); 58 } 59 if (verbose > 1) { 60 printf("ok: n=%d, N=%d, d1=%d, t=%d\n", n, N, d1, t); 61 } 62 } 63 return 0; /* ok */ 64} 65 66define testr(str, n, N, verbose) 67{ 68 local A, t, i, j, d1, d2; 69 70 if (isnull(verbose)) verbose = defaultverbose; 71 if (verbose > 0) { 72 print str:":",:; 73 } 74 if (isnull(N)) 75 N = 1e6; 76 mat A[n,n]; 77 for (i = 0; i < n; i++) 78 for (j = 0; j < n; j++) 79 A[i,j] = rand(-(N^2), N^2)/rand(1, N); 80 t = usertime(); 81 d1 = det(A); 82 t = usertime() - t; 83 d2 = det(A^2); 84 if (d2 != d1^2) { 85 if (verbose > 0) { 86 printf("*** Failure for n=%d, N=%d, d1=%d\n", n, N, d1); 87 } 88 return 1; /* error */ 89 } else { 90 if (verbose > 0) { 91 printf("no errors\n"); 92 } 93 if (verbose > 1) { 94 printf("ok: n=%d, N=%d, d1=%d, t=%d\n", n, N, d1, t); 95 } 96 } 97 return 0; /* ok */ 98} 99 100/* 101 * test3300 - perform all of the above tests a bunch of times 102 */ 103define test3300(verbose, tnum) 104{ 105 local N; /* test parameter */ 106 local i; 107 108 /* 109 * set test parameters 110 */ 111 if (isnull(verbose)) { 112 verbose = defaultverbose; 113 } 114 N = 1e6; 115 srand(3300e3300); 116 117 /* 118 * test a lot of stuff 119 */ 120 for (i=0; i < 19; ++i) { 121 err += testi(strcat(str(tnum++), ": testi(", str(i), ")"), \ 122 i, N, verbose); 123 } 124 for (i=0; i < 9; ++i) { 125 err += testr(strcat(str(tnum++), ": testr(", str(i), ")"), \ 126 i, N, verbose); 127 } 128 129 /* 130 * test results 131 */ 132 if (verbose > 1) { 133 if (err) { 134 print "***", err, "error(s) found in testall"; 135 } else { 136 print "no errors in testall"; 137 } 138 } 139 return tnum; 140} 141