1 /*
2     Copyright (C) 2012 Sebastian Pancratz
3     Copyright (C) 2012 Andres Goens
4     Copyright (C) 2013 Mike Hansen
5 
6     This file is part of FLINT.
7 
8     FLINT is free software: you can redistribute it and/or modify it under
9     the terms of the GNU Lesser General Public License (LGPL) as published
10     by the Free Software Foundation; either version 2.1 of the License, or
11     (at your option) any later version.  See <https://www.gnu.org/licenses/>.
12 */
13 
14 #ifdef T
15 
16 #include "templates.h"
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 
21 #include "ulong_extras.h"
22 #include "long_extras.h"
23 
24 int
main(void)25 main(void)
26 {
27     int i, result;
28     FLINT_TEST_INIT(state);
29 
30     flint_printf("shift_left/right... ");
31     fflush(stdout);
32 
33     /* Check aliasing for left shift */
34     for (i = 0; i < 200 * flint_test_multiplier(); i++)
35     {
36         slong len = n_randint(state, 100);
37         TEMPLATE(T, ctx_t) ctx;
38 
39         TEMPLATE(T, poly_t) a, b, c;
40         slong shift;
41 
42         TEMPLATE(T, ctx_randtest) (ctx, state);
43         TEMPLATE(T, poly_init) (a, ctx);
44         TEMPLATE(T, poly_init) (b, ctx);
45         TEMPLATE(T, poly_init) (c, ctx);
46 
47         TEMPLATE(T, poly_randtest) (a, state, len, ctx);
48         TEMPLATE(T, poly_set) (b, a, ctx);
49         shift = n_randint(state, 100);
50 
51         TEMPLATE(T, poly_shift_left) (c, b, shift, ctx);
52         TEMPLATE(T, poly_shift_left) (b, b, shift, ctx);
53 
54         result = (TEMPLATE(T, poly_equal) (b, c, ctx));
55         if (!result)
56         {
57             flint_printf("FAIL:\n\n");
58             flint_printf("a = "), TEMPLATE(T, poly_print_pretty) (a, "X", ctx),
59                 flint_printf("\n");
60             flint_printf("b = "), TEMPLATE(T, poly_print_pretty) (b, "X", ctx),
61                 flint_printf("\n");
62             flint_printf("c = "), TEMPLATE(T, poly_print_pretty) (c, "X", ctx),
63                 flint_printf("\n");
64             abort();
65         }
66 
67         TEMPLATE(T, poly_clear) (a, ctx);
68         TEMPLATE(T, poly_clear) (b, ctx);
69         TEMPLATE(T, poly_clear) (c, ctx);
70 
71         TEMPLATE(T, ctx_clear) (ctx);
72     }
73 
74     /* Check aliasing for right shift */
75     for (i = 0; i < 200 * flint_test_multiplier(); i++)
76     {
77         slong len = n_randint(state, 100);
78         TEMPLATE(T, ctx_t) ctx;
79 
80         TEMPLATE(T, poly_t) a, b, c;
81         slong shift;
82 
83         TEMPLATE(T, ctx_randtest) (ctx, state);
84 
85         TEMPLATE(T, poly_init) (a, ctx);
86         TEMPLATE(T, poly_init) (b, ctx);
87         TEMPLATE(T, poly_init) (c, ctx);
88 
89         TEMPLATE(T, poly_randtest) (a, state, len, ctx);
90         TEMPLATE(T, poly_set) (b, a, ctx);
91         shift = n_randint(state, 100);
92 
93         TEMPLATE(T, poly_shift_right) (c, b, shift, ctx);
94         TEMPLATE(T, poly_shift_right) (b, b, shift, ctx);
95 
96         result = (TEMPLATE(T, poly_equal) (b, c, ctx));
97         if (!result)
98         {
99             flint_printf("FAIL:\n\n");
100             flint_printf("a = "), TEMPLATE(T, poly_print_pretty) (a, "X", ctx),
101                 flint_printf("\n");
102             flint_printf("b = "), TEMPLATE(T, poly_print_pretty) (b, "X", ctx),
103                 flint_printf("\n");
104             flint_printf("c = "), TEMPLATE(T, poly_print_pretty) (c, "X", ctx),
105                 flint_printf("\n");
106             abort();
107         }
108 
109         TEMPLATE(T, poly_clear) (a, ctx);
110         TEMPLATE(T, poly_clear) (b, ctx);
111         TEMPLATE(T, poly_clear) (c, ctx);
112 
113         TEMPLATE(T, ctx_clear) (ctx);
114     }
115 
116     /* Check shift left then right does nothing */
117     for (i = 0; i < 200 * flint_test_multiplier(); i++)
118     {
119         slong len = n_randint(state, 100);
120         TEMPLATE(T, ctx_t) ctx;
121 
122         TEMPLATE(T, poly_t) a, b, c;
123         slong shift;
124 
125         TEMPLATE(T, ctx_randtest) (ctx, state);
126         TEMPLATE(T, poly_init) (a, ctx);
127         TEMPLATE(T, poly_init) (b, ctx);
128         TEMPLATE(T, poly_init) (c, ctx);
129 
130         TEMPLATE(T, poly_randtest) (a, state, len, ctx);
131         shift = n_randint(state, 100);
132 
133         TEMPLATE(T, poly_shift_left) (b, a, shift, ctx);
134         TEMPLATE(T, poly_shift_right) (c, b, shift, ctx);
135 
136         result = (TEMPLATE(T, poly_equal) (c, a, ctx));
137         if (!result)
138         {
139             flint_printf("FAIL:\n\n");
140             flint_printf("a = "), TEMPLATE(T, poly_print_pretty) (a, "X", ctx),
141                 flint_printf("\n");
142             flint_printf("b = "), TEMPLATE(T, poly_print_pretty) (b, "X", ctx),
143                 flint_printf("\n");
144             flint_printf("c = "), TEMPLATE(T, poly_print_pretty) (c, "X", ctx),
145                 flint_printf("\n");
146             abort();
147         }
148 
149         TEMPLATE(T, poly_clear) (a, ctx);
150         TEMPLATE(T, poly_clear) (b, ctx);
151         TEMPLATE(T, poly_clear) (c, ctx);
152 
153         TEMPLATE(T, ctx_clear) (ctx);
154     }
155 
156     FLINT_TEST_CLEANUP(state);
157     flint_printf("PASS\n");
158     return EXIT_SUCCESS;
159 }
160 
161 
162 
163 #endif
164