#include "test_helpers.h"
#include "fmpz_mod_mat.h"
TEST_FUNCTION_START(fmpz_mod_mat_pow, state)
{
slong i;
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fmpz_mod_mat_t A, B, C;
slong n, i;
ulong e;
fmpz_mod_ctx_t ctx;
n = n_randint(state, 10);
e = n_randint(state, 20);
fmpz_mod_ctx_init_rand_bits(ctx, state, 200);
fmpz_mod_mat_init(A, n, n, ctx);
fmpz_mod_mat_init(B, n, n, ctx);
fmpz_mod_mat_init(C, n, n, ctx);
fmpz_mod_mat_randtest(A, state, ctx);
fmpz_mod_mat_randtest(B, state, ctx);
fmpz_mod_mat_randtest(B, state, ctx);
fmpz_mod_mat_pow_ui(B, A, e, ctx);
fmpz_mod_mat_one(C, ctx);
for (i = 0; i < e; i++)
fmpz_mod_mat_mul(C, C, A, ctx);
if (!fmpz_mod_mat_equal(C, B, ctx))
{
flint_printf("FAIL: results not equal\n");
fflush(stdout);
flint_abort();
}
fmpz_mod_mat_pow_ui(A, A, e, ctx);
if (!fmpz_mod_mat_equal(A, B, ctx))
{
flint_printf("FAIL: aliasing failed\n");
fflush(stdout);
flint_abort();
}
fmpz_mod_mat_clear(A, ctx);
fmpz_mod_mat_clear(B, ctx);
fmpz_mod_mat_clear(C, ctx);
fmpz_mod_ctx_clear(ctx);
}
TEST_FUNCTION_END(state);
}