+/* -*-apcalc-*-
+ *
+ * $Id: gfx-test.cal,v 1.1 2000/10/08 16:01:37 mdw Exp $
+ *
+ * Generate test cases for %$\gf{2}[x]$% arithmetic
+ *
+ * (c) 2000 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------*
+ *
+ * This file is part of Catacomb.
+ *
+ * Catacomb is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * Catacomb is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with Catacomb; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------*
+ *
+ * $Log: gfx-test.cal,v $
+ * Revision 1.1 2000/10/08 16:01:37 mdw
+ * Prototypes of various bits of code.
+ *
+ */
+
+/*----- External units ----------------------------------------------------*/
+
+read gfx;
+
+/*----- Global variables --------------------------------------------------*/
+
+global op = "+", n = 40, bits = 128;
+
+/*----- Main code ---------------------------------------------------------*/
+
+dummy = config("lib_debug", -1);
+
+define gfx_test() {
+ local i, j, x;
+ local a, b, l;
+
+ for (i = 0; i < n; i++) {
+
+ /* --- Select the inputs and produce the outputs --- */
+
+ switch (op) {
+ case '+':
+ case '-':
+ a = gf(random(1 << bits));
+ b = gf(random(1 << bits));
+ l = list(a, b, a + b);
+ break;
+ case '*':
+ a = gf(random(1 << bits));
+ b = gf(random(1 << bits));
+ l = list(a, b, a * b);
+ break;
+ case '2':
+ a = gf(random(1 << bits));
+ l = list(a, a * a);
+ break;
+ case '/':
+ a = gf(random(1 << (bits + random(bits))));
+ b = gf(random(1 << bits));
+ l = list(a, b, a / b, a % b);
+ break;
+ default:
+ exit "unknown operator";
+ break;
+ }
+
+ /* --- Output the test vector --- *
+ *
+ * Be careful to ensure that it has an even number of hex digits in each
+ * number.
+ */
+
+ for (j = 0; j < size(l); j++) {
+ x = strprintf("%x", l[[j]].x);
+ if (strlen(x) > 1)
+ x = substr(x, 3, strlen(x) - 2);
+ if (strlen(x) % 2)
+ x = strcat("0", x);
+ x = strcat(" ", x);
+ if (j)
+ x = strcat(" ", x);
+ if (j == size(l) - 1)
+ x = strcat(x, ";");
+ printf("%s\n", x);
+ }
+ }
+}
+
+/*----- That's all, folks -------------------------------------------------*/