4bdee421af3d9254f49f5b692cdbd2d1251f6a3b
[u/mdw/catacomb] / calc / gfx-test.cal
1 /* -*-apcalc-*-
2 *
3 * $Id: gfx-test.cal,v 1.1 2000/10/08 16:01:37 mdw Exp $
4 *
5 * Generate test cases for %$\gf{2}[x]$% arithmetic
6 *
7 * (c) 2000 Straylight/Edgeware
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Catacomb.
13 *
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
23 *
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 * MA 02111-1307, USA.
28 */
29
30 /*----- Revision history --------------------------------------------------*
31 *
32 * $Log: gfx-test.cal,v $
33 * Revision 1.1 2000/10/08 16:01:37 mdw
34 * Prototypes of various bits of code.
35 *
36 */
37
38 /*----- External units ----------------------------------------------------*/
39
40 read gfx;
41
42 /*----- Global variables --------------------------------------------------*/
43
44 global op = "+", n = 40, bits = 128;
45
46 /*----- Main code ---------------------------------------------------------*/
47
48 dummy = config("lib_debug", -1);
49
50 define gfx_test() {
51 local i, j, x;
52 local a, b, l;
53
54 for (i = 0; i < n; i++) {
55
56 /* --- Select the inputs and produce the outputs --- */
57
58 switch (op) {
59 case '+':
60 case '-':
61 a = gf(random(1 << bits));
62 b = gf(random(1 << bits));
63 l = list(a, b, a + b);
64 break;
65 case '*':
66 a = gf(random(1 << bits));
67 b = gf(random(1 << bits));
68 l = list(a, b, a * b);
69 break;
70 case '2':
71 a = gf(random(1 << bits));
72 l = list(a, a * a);
73 break;
74 case '/':
75 a = gf(random(1 << (bits + random(bits))));
76 b = gf(random(1 << bits));
77 l = list(a, b, a / b, a % b);
78 break;
79 default:
80 exit "unknown operator";
81 break;
82 }
83
84 /* --- Output the test vector --- *
85 *
86 * Be careful to ensure that it has an even number of hex digits in each
87 * number.
88 */
89
90 for (j = 0; j < size(l); j++) {
91 x = strprintf("%x", l[[j]].x);
92 if (strlen(x) > 1)
93 x = substr(x, 3, strlen(x) - 2);
94 if (strlen(x) % 2)
95 x = strcat("0", x);
96 x = strcat(" ", x);
97 if (j)
98 x = strcat(" ", x);
99 if (j == size(l) - 1)
100 x = strcat(x, ";");
101 printf("%s\n", x);
102 }
103 }
104 }
105
106 /*----- That's all, folks -------------------------------------------------*/