1 /*
2     Copyright (C) 2018 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 <http://www.gnu.org/licenses/>.
10 */
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include "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         nmod_mpoly_ctx_t ctx;
29         nmod_mpoly_t f, g, h;
30         flint_bitcnt_t exp_bits1, exp_bits2, exp_bits3;
31         slong len1, len2, len3;
32         mp_limb_t modulus;
33 
34         modulus = UWORD(2) + n_randint(state, -UWORD(2));
35         nmod_mpoly_ctx_init_rand(ctx, state, 20, modulus);
36         nmod_mpoly_init(f, ctx);
37         nmod_mpoly_init(g, ctx);
38         nmod_mpoly_init(h, ctx);
39 
40         len1 = n_randint(state, 100);
41         len2 = n_randint(state, 100);
42         len3 = n_randint(state, 100);
43 
44         exp_bits1 = n_randint(state, 200) + 2;
45         exp_bits2 = n_randint(state, 200) + 2;
46         exp_bits3 = n_randint(state, 200) + 2;
47 
48 
49         nmod_mpoly_randtest_bits(f, state, len1, exp_bits1, ctx);
50         nmod_mpoly_randtest_bits(g, state, len2, exp_bits2, ctx);
51         nmod_mpoly_randtest_bits(h, state, len3, exp_bits3, ctx);
52 
53         nmod_mpoly_zero(h, ctx);
54         for (j = nmod_mpoly_length(f, ctx) - 1; j >= 0; j--)
55         {
56             nmod_mpoly_get_term(g, f, j, ctx);
57             nmod_mpoly_add(h, h, g, ctx);
58         }
59 
60         if (!nmod_mpoly_equal(f, h, ctx))
61         {
62             flint_printf("FAIL\nCheck a polynomial is the sum of its terms\ni = %wd\n", i);
63             flint_abort();
64         }
65 
66         nmod_mpoly_clear(f, ctx);
67         nmod_mpoly_clear(g, ctx);
68         nmod_mpoly_clear(h, ctx);
69         nmod_mpoly_ctx_clear(ctx);
70     }
71 
72     FLINT_TEST_CLEANUP(state);
73 
74     flint_printf("PASS\n");
75     return 0;
76 }
77 
78