1 /*
2     Copyright (C) 2011 Fredrik Johansson
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 <https://www.gnu.org/licenses/>.
11 */
12 
13 #ifdef T
14 
15 #include "templates.h"
16 
17 int
main(void)18 main(void)
19 {
20     int iter;
21     FLINT_TEST_INIT(state);
22 
23     flint_printf("deflate....");
24     fflush(stdout);
25 
26     for (iter = 0; iter < 100 * flint_test_multiplier(); iter++)
27     {
28         TEMPLATE(T, poly_t) poly1, poly2, poly3;
29         TEMPLATE(T, ctx_t) ctx;
30         ulong infl1, infl, deflation;
31 
32         TEMPLATE(T, ctx_randtest) (ctx, state);
33 
34         TEMPLATE(T, poly_init) (poly1, ctx);
35         TEMPLATE(T, poly_init) (poly2, ctx);
36         TEMPLATE(T, poly_init) (poly3, ctx);
37 
38         TEMPLATE(T, poly_randtest) (poly1, state, n_randint(state, 15), ctx);
39 
40         if (TEMPLATE(T, poly_length) (poly1, ctx) <= 1)
41         {
42             if (TEMPLATE(T, poly_deflation) (poly1, ctx) !=
43                 TEMPLATE(T, poly_length) (poly1, ctx))
44             {
45                 flint_printf
46                     ("FAIL: wrong deflation for constant polynomial\n");
47                 abort();
48             }
49 
50             TEMPLATE(T, poly_deflate) (poly2, poly1, n_randint(state, 5) + 1,
51                                        ctx);
52             if (!TEMPLATE(T, poly_equal) (poly2, poly1, ctx))
53             {
54                 flint_printf
55                     ("FAIL: constant polynomial changed on deflation\n");
56                 abort();
57             }
58         }
59         else
60         {
61 
62             infl = n_randint(state, 13) + 1;
63             infl1 = TEMPLATE(T, poly_deflation) (poly1, ctx);
64 
65             TEMPLATE(T, poly_inflate) (poly2, poly1, infl, ctx);
66 
67             deflation = TEMPLATE(T, poly_deflation) (poly2, ctx);
68 
69             if (deflation != infl * infl1)
70             {
71                 flint_printf("FAIL: deflation = %wu, inflation: %wu, %wu\n",
72                              deflation, infl, infl1);
73                 flint_printf("poly1:\n");
74                 TEMPLATE(T, poly_print) (poly1, ctx);
75                 flint_printf("\n\n");
76                 flint_printf("poly2:\n");
77                 TEMPLATE(T, poly_print) (poly2, ctx);
78                 flint_printf("\n\n");
79                 abort();
80             }
81 
82             TEMPLATE(T, poly_deflate) (poly3, poly2, infl, ctx);
83             if (!TEMPLATE(T, poly_equal) (poly3, poly1, ctx))
84             {
85                 flint_printf("FAIL: deflation = %wu, inflation: %wu, %wu\n",
86                              deflation, infl, infl1);
87                 flint_printf("Deflated polynomial not equal to input:\n");
88                 flint_printf("poly1:\n");
89                 TEMPLATE(T, poly_print) (poly1, ctx);
90                 flint_printf("\n\n");
91                 flint_printf("poly2:\n");
92                 TEMPLATE(T, poly_print) (poly2, ctx);
93                 flint_printf("\n\n");
94                 flint_printf("poly3:\n");
95                 TEMPLATE(T, poly_print) (poly3, ctx);
96                 flint_printf("\n\n");
97                 abort();
98             }
99 
100             TEMPLATE(T, poly_deflate) (poly2, poly2, infl, ctx);
101             if (!TEMPLATE(T, poly_equal) (poly3, poly2, ctx))
102             {
103                 flint_printf("FAIL: aliasing\n");
104                 abort();
105             }
106         }
107 
108         TEMPLATE(T, poly_clear) (poly1, ctx);
109         TEMPLATE(T, poly_clear) (poly2, ctx);
110         TEMPLATE(T, poly_clear) (poly3, ctx);
111         TEMPLATE(T, ctx_clear) (ctx);
112     }
113 
114     FLINT_TEST_CLEANUP(state);
115     flint_printf("PASS\n");
116     return 0;
117 }
118 
119 
120 #endif
121