1 /*
2     Copyright (C) 2019 Daniel Schultz
3 
4     This file is part of FLINT.
5 
6     FLINT is free software: you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 2.1 of the License, or
9     (at your option) any later version.  See <https://www.gnu.org/licenses/>.
10 */
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include "fq_nmod_mpoly.h"
15 
16 int
main(void)17 main(void)
18 {
19     int i, j;
20     FLINT_TEST_INIT(state);
21 
22     flint_printf("get_term....");
23     fflush(stdout);
24 
25     /* Check a polynomial is the sum of its terms */
26     for (i = 0; i < 100 * flint_test_multiplier(); i++)
27     {
28         fq_nmod_mpoly_ctx_t ctx;
29         fq_nmod_mpoly_t f, g, h;
30         flint_bitcnt_t exp_bits1, exp_bits2, exp_bits3;
31         slong len1, len2, len3;
32 
33         fq_nmod_mpoly_ctx_init_rand(ctx, state, 20, FLINT_BITS, 10);
34         fq_nmod_mpoly_init(f, ctx);
35         fq_nmod_mpoly_init(g, ctx);
36         fq_nmod_mpoly_init(h, ctx);
37 
38         len1 = n_randint(state, 100);
39         len2 = n_randint(state, 100);
40         len3 = n_randint(state, 100);
41 
42         exp_bits1 = n_randint(state, 200) + 2;
43         exp_bits2 = n_randint(state, 200) + 2;
44         exp_bits3 = n_randint(state, 200) + 2;
45 
46         fq_nmod_mpoly_randtest_bits(f, state, len1, exp_bits1, ctx);
47         fq_nmod_mpoly_randtest_bits(g, state, len2, exp_bits2, ctx);
48         fq_nmod_mpoly_randtest_bits(h, state, len3, exp_bits3, ctx);
49 
50         fq_nmod_mpoly_zero(h, ctx);
51         for (j = fq_nmod_mpoly_length(f, ctx) - 1; j >= 0; j--)
52         {
53             fq_nmod_mpoly_get_term(g, f, j, ctx);
54             fq_nmod_mpoly_add(h, h, g, ctx);
55         }
56 
57         if (!fq_nmod_mpoly_equal(f, h, ctx))
58         {
59             flint_printf("FAIL\nCheck a polynomial is the sum of its terms\ni = %wd\n", i);
60             flint_abort();
61         }
62 
63         fq_nmod_mpoly_clear(f, ctx);
64         fq_nmod_mpoly_clear(g, ctx);
65         fq_nmod_mpoly_clear(h, ctx);
66         fq_nmod_mpoly_ctx_clear(ctx);
67     }
68 
69     FLINT_TEST_CLEANUP(state);
70 
71     flint_printf("PASS\n");
72     return 0;
73 }
74