#include "test_helpers.h"
#include "ulong_extras.h"
#include "fmpz.h"
#include "fmpq_poly.h"
TEST_FUNCTION_START(fmpq_poly_scalar_mul_ui, state)
{
int i, result;
ulong cflags = UWORD(0);
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b;
ulong n = n_randtest(state);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_randtest(a, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_scalar_mul_ui(b, a, n);
fmpq_poly_scalar_mul_ui(a, a, n);
cflags |= fmpq_poly_is_canonical(a) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(b) ? 0 : 2;
result = (fmpq_poly_equal(a, b) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
fflush(stdout);
flint_abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
}
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, lhs, rhs;
ulong n = n_randtest(state);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(lhs);
fmpq_poly_init(rhs);
fmpq_poly_randtest(a, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_randtest(b, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_scalar_mul_ui(lhs, a, n);
fmpq_poly_scalar_mul_ui(rhs, b, n);
fmpq_poly_add(rhs, lhs, rhs);
fmpq_poly_add(lhs, a, b);
fmpq_poly_scalar_mul_ui(lhs, lhs, n);
cflags |= fmpq_poly_is_canonical(lhs) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(rhs) ? 0 : 2;
result = (fmpq_poly_equal(lhs, rhs) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
flint_printf("%li\n\n", n);
fmpq_poly_debug(lhs), flint_printf("\n\n");
fmpq_poly_debug(rhs), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
fflush(stdout);
flint_abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(lhs);
fmpq_poly_clear(rhs);
}
for (i = 0; i < 1000 * flint_test_multiplier(); i++)
{
fmpq_poly_t a, b, c;
ulong n1 = n_randbits(state, FLINT_BITS / 2);
ulong n2 = n_randbits(state, FLINT_BITS / 2);
fmpq_poly_init(a);
fmpq_poly_init(b);
fmpq_poly_init(c);
fmpq_poly_randtest(a, state, n_randint(state, 100), n_randint(state, 200));
fmpq_poly_scalar_mul_ui(b, a, n1);
fmpq_poly_scalar_mul_ui(c, b, n2);
fmpq_poly_scalar_mul_ui(b, a, n1 * n2);
cflags |= fmpq_poly_is_canonical(b) ? 0 : 1;
cflags |= fmpq_poly_is_canonical(c) ? 0 : 2;
result = (fmpq_poly_equal(b, c) && !cflags);
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("n1 = %wu, n2 = %wu:\n\n", n1, n2);
fmpq_poly_debug(a), flint_printf("\n\n");
fmpq_poly_debug(b), flint_printf("\n\n");
fmpq_poly_debug(c), flint_printf("\n\n");
flint_printf("cflags = %wu\n\n", cflags);
fflush(stdout);
flint_abort();
}
fmpq_poly_clear(a);
fmpq_poly_clear(b);
fmpq_poly_clear(c);
}
TEST_FUNCTION_END(state);
}