1 /*
2     Copyright (C) 2012 Sebastian Pancratz
3     Copyright (C) 2013 Mike Hansen
4 
5     This file is part of FLINT.
6 
7     FLINT is free software: you can redistribute it and/or modify it under
8     the terms of the GNU Lesser General Public License (LGPL) as published
9     by the Free Software Foundation; either version 2.1 of the License, or
10     (at your option) any later version.  See <http://www.gnu.org/licenses/>.
11 */
12 
13 #ifdef T
14 
15 #include "templates.h"
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 
20 #include "fmpz_mod_poly.h"
21 #include "ulong_extras.h"
22 #include "long_extras.h"
23 
24 int
main(void)25 main(void)
26 {
27     int i, k, result;
28     FLINT_TEST_INIT(state);
29 
30     flint_printf("ctx_init... ");
31     fflush(stdout);
32 
33     for (i = 0; i < 3 * flint_test_multiplier(); i++) {
34         fmpz_t p;
35         slong d;
36         TEMPLATE(T, ctx_t) ctx;
37 
38         fmpz_init(p);
39         fmpz_set_ui(p, n_randprime(state, 2 + n_randint(state,
40                                    FLINT_MIN(FLINT_BITS - 1, 50)), 1));
41         d = n_randint(state, 20) + 1;
42 
43         TEMPLATE(T, ctx_init)(ctx, p, d, "a");
44         TEMPLATE(T, ctx_clear)(ctx);
45     }
46 
47     for (i = 0; i < 3 * flint_test_multiplier(); i++) {
48         fmpz_t p;
49         slong d;
50         TEMPLATE(T, ctx_t) ctx_conway, ctx_mod;
51 
52         TEMPLATE(T, t) a, b, lhs, rhs;
53 
54         fmpz_init(p);
55         fmpz_set_ui(p, n_randprime(state, 2 + n_randint(state, 3), 1));
56         d = n_randint(state, 10) + 1;
57         TEMPLATE(T, ctx_init_conway)(ctx_conway, p, d, "a");
58 
59         TEMPLATE(T, ctx_init_modulus)(ctx_mod, ctx_conway->modulus, "a");
60 
61         TEMPLATE(T, init)(a, ctx_conway);
62         TEMPLATE(T, init)(b, ctx_mod);
63         TEMPLATE(T, init)(lhs, ctx_conway);
64         TEMPLATE(T, init)(rhs, ctx_mod);
65 
66         for (k = 0; k < 30; k++)
67         {
68 
69             TEMPLATE(T, randtest)(a, state, ctx_conway);
70             TEMPLATE(T, set)(b, a, ctx_mod);
71 
72             TEMPLATE(T, mul)(lhs, a, a, ctx_conway);
73             TEMPLATE(T, mul)(rhs, b, b, ctx_mod);
74 
75             result = (TEMPLATE(T, equal)(lhs, rhs, ctx_mod));
76             if (!result)
77             {
78                 flint_printf("FAIL:\n\n");
79                 flint_printf("a   = "), TEMPLATE(T, print_pretty)(a, ctx_conway), flint_printf("\n");
80                 flint_printf("b   = "), TEMPLATE(T, print_pretty)(b, ctx_mod), flint_printf("\n");
81                 flint_printf("lhs = "), TEMPLATE(T, print_pretty)(lhs, ctx_conway), flint_printf("\n");
82                 flint_printf("rhs = "), TEMPLATE(T, print_pretty)(rhs, ctx_mod), flint_printf("\n");
83                 abort();
84             }
85 
86         }
87 
88         TEMPLATE(T, clear)(a, ctx_conway);
89         TEMPLATE(T, clear)(b, ctx_mod);
90         TEMPLATE(T, clear)(lhs, ctx_conway);
91         TEMPLATE(T, clear)(rhs, ctx_mod);
92 
93         TEMPLATE(T, ctx_clear)(ctx_conway);
94         TEMPLATE(T, ctx_clear)(ctx_mod);
95 
96     }
97 
98     FLINT_TEST_CLEANUP(state);
99     flint_printf("PASS\n");
100 
101     return EXIT_SUCCESS;
102 }
103 
104 
105 #endif
106