Skip to content

Commit

Permalink
improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrik-johansson committed Jan 12, 2025
1 parent 97359ec commit a541dad
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/gr_mpoly/ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ gr_method_tab_input _gr_mpoly_methods_input[] =
{GR_METHOD_ADD, (gr_funcptr) gr_mpoly_add},
{GR_METHOD_SUB, (gr_funcptr) gr_mpoly_sub},
{GR_METHOD_MUL, (gr_funcptr) gr_mpoly_mul},
{GR_METHOD_MUL_UI, (gr_funcptr) gr_mpoly_mul_ui},
{GR_METHOD_MUL_SI, (gr_funcptr) gr_mpoly_mul_si},
{GR_METHOD_MUL_FMPZ, (gr_funcptr) gr_mpoly_mul_fmpz},
{GR_METHOD_MUL_FMPQ, (gr_funcptr) gr_mpoly_mul_fmpq},
{0, (gr_funcptr) NULL},
};

Expand Down
85 changes: 80 additions & 5 deletions src/gr_mpoly/test/t-get_set_coeff.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (C) 2020 Daniel Schultz
Copyright (C) 2022 Fredrik Johansson
Copyright (C) 2022, 2025 Fredrik Johansson
This file is part of FLINT.
Expand All @@ -11,6 +11,8 @@
*/

#include "test_helpers.h"
#include "fmpz.h"
#include "fmpq.h"
#include "fmpz_vec.h"
#include "gr_mpoly.h"

Expand All @@ -28,6 +30,7 @@ TEST_FUNCTION_START(gr_mpoly_get_set_coeff, state)
flint_bitcnt_t exp_bits;
int status;
slong nvars;
int which;

gr_ctx_init_random(cctx, state);
gr_mpoly_ctx_init_rand(ctx, state, cctx, 20);
Expand All @@ -48,11 +51,47 @@ TEST_FUNCTION_START(gr_mpoly_get_set_coeff, state)

status = GR_SUCCESS;

GR_MUST_SUCCEED(gr_randtest(c, state, cctx));
for (k = 0; k < nvars; k++)
exp[k] = n_randtest(state);

status |= gr_mpoly_set_coeff_scalar_ui(f, c, exp, ctx);
which = n_randint(state, 5);

if (which == 0)
{
GR_MUST_SUCCEED(gr_randtest(c, state, cctx));
status |= gr_mpoly_set_coeff_scalar_ui(f, c, exp, ctx);
}
else if (which == 1)
{
ulong uc = n_randtest(state);
status |= gr_set_ui(c, uc, cctx);
status |= gr_mpoly_set_coeff_ui_ui(f, uc, exp, ctx);
}
else if (which == 2)
{
slong sc = n_randtest(state);
status |= gr_set_si(c, sc, cctx);
status |= gr_mpoly_set_coeff_si_ui(f, sc, exp, ctx);
}
else if (which == 3)
{
fmpz_t zc;
fmpz_init(zc);
fmpz_randtest(zc, state, 100);
status |= gr_set_fmpz(c, zc, cctx);
status |= gr_mpoly_set_coeff_fmpz_ui(f, zc, exp, ctx);
fmpz_clear(zc);
}
else if (which == 4)
{
fmpq_t qc;
fmpq_init(qc);
fmpq_randtest(qc, state, 100);
status |= gr_set_fmpq(c, qc, cctx);
status |= gr_mpoly_set_coeff_fmpq_ui(f, qc, exp, ctx);
fmpq_clear(qc);
}

gr_mpoly_assert_canonical(f, ctx);
status |= gr_mpoly_get_coeff_scalar_ui(d, f, exp, ctx);

Expand All @@ -79,10 +118,46 @@ TEST_FUNCTION_START(gr_mpoly_get_set_coeff, state)

status = GR_SUCCESS;

GR_MUST_SUCCEED(gr_randtest(c, state, cctx));
_fmpz_vec_randtest(exp, state, nvars, exp_bits);

status |= gr_mpoly_set_coeff_scalar_fmpz(f, c, exp, ctx);
which = n_randint(state, 5);

if (which == 0)
{
GR_MUST_SUCCEED(gr_randtest(c, state, cctx));
status |= gr_mpoly_set_coeff_scalar_fmpz(f, c, exp, ctx);
}
else if (which == 1)
{
ulong uc = n_randtest(state);
status |= gr_set_ui(c, uc, cctx);
status |= gr_mpoly_set_coeff_ui_fmpz(f, uc, exp, ctx);
}
else if (which == 2)
{
slong sc = n_randtest(state);
status |= gr_set_si(c, sc, cctx);
status |= gr_mpoly_set_coeff_si_fmpz(f, sc, exp, ctx);
}
else if (which == 3)
{
fmpz_t zc;
fmpz_init(zc);
fmpz_randtest(zc, state, 100);
status |= gr_set_fmpz(c, zc, cctx);
status |= gr_mpoly_set_coeff_fmpz_fmpz(f, zc, exp, ctx);
fmpz_clear(zc);
}
else if (which == 4)
{
fmpq_t qc;
fmpq_init(qc);
fmpq_randtest(qc, state, 100);
status |= gr_set_fmpq(c, qc, cctx);
status |= gr_mpoly_set_coeff_fmpq_fmpz(f, qc, exp, ctx);
fmpq_clear(qc);
}

gr_mpoly_assert_canonical(f, ctx);
status |= gr_mpoly_get_coeff_scalar_fmpz(d, f, exp, ctx);

Expand Down
3 changes: 3 additions & 0 deletions src/python/flint_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8083,6 +8083,9 @@ def test_mpoly():
assert str(FiniteField_fq_nmod(3, 2, "d").gen()) == "d"
assert str(FiniteField_fq_zech(3, 2, "e").gen()) == "e^1"

assert str(sum(PolynomialRing_gr_mpoly(ZZi, 20).gens())) == "x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + x19 + x20"


def test_mpoly_q():
assert str(FractionField_fmpz_mpoly_q(2).gens()) == '[x1, x2]'
assert str(FractionField_fmpz_mpoly_q(2, ["a", "b"]).gens()) == '[a, b]'
Expand Down

0 comments on commit a541dad

Please sign in to comment.