Skip to content

Commit

Permalink
attempt to write test, which fails for 3/5 types...
Browse files Browse the repository at this point in the history
  • Loading branch information
GiacomoPope committed Aug 14, 2024
1 parent 113d306 commit 1427162
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/fq_default_poly/test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
#include "t-init.c"
#include "t-inlines.c"
#include "t-set_fmpz_poly.c"
#include "t-evaluate_fq_default.c"

/* Array of test functions ***************************************************/

test_struct tests[] =
{
TEST_FUNCTION(fq_default_poly_init),
TEST_FUNCTION(fq_default_poly_inlines),
TEST_FUNCTION(fq_default_poly_set_fmpz_poly)
TEST_FUNCTION(fq_default_poly_set_fmpz_poly),
TEST_FUNCTION(fq_default_poly_evaluate)
};

/* main function *************************************************************/
Expand Down
98 changes: 98 additions & 0 deletions src/fq_default_poly/test/t-evaluate_fq_default.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Copyright (C) 2021 William Hart
This file is part of FLINT.
FLINT is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "test_helpers.h"
#include "fq_default_poly.h"

// Given a context, compute a random polynomial and evaluate it twice on a random fq_element
void
test_eval_with_ctx(fq_default_ctx_t ctx,
flint_rand_t state)
{
int i, result;
for (i = 0; i < 100 * flint_test_multiplier(); i++)
{
fq_default_t a, b;
fq_default_poly_t fq_poly;

// Random polynomial
fq_default_poly_init(fq_poly, ctx);
fq_default_poly_randtest(fq_poly, state, n_randint(state, 10), ctx);

// Evaluate the polynomial twice and ensure results match
fq_default_randtest(a, state, ctx);
fq_default_poly_evaluate_fq_default(b, fq_poly, a, ctx);
fq_default_poly_evaluate_fq_default(a, fq_poly, a, ctx);

result = (fq_default_equal(a, b, ctx));
if (!result)
{
flint_printf("FAIL:\n");
fq_default_poly_print(fq_poly, ctx), flint_printf("\n\n");
fq_default_print(a, ctx), flint_printf("\n\n");
fq_default_print(b, ctx), flint_printf("\n\n");
fflush(stdout);
flint_abort();
}

// Clear everything
fq_default_poly_clear(fq_poly, ctx);
fq_default_clear(a, ctx);
fq_default_clear(b, ctx);
}
}

TEST_FUNCTION_START(fq_default_poly_evaluate, state)
{
fmpz_t p;
fq_default_ctx_t ctx;

fmpz_init(p);

// Test FQ_ZECH type with GF(5^5)
fmpz_set_ui(p, 5);
fq_default_ctx_init_type(ctx, p, 5, "x", 1);
test_eval_with_ctx(ctx, state);
fq_default_ctx_clear(ctx);

// Test FQ_NMOD type with GF(163^3)
// TODO: crashes with segfault
// make: *** [build/fq_default_poly/test/main_TEST_RUN] Segmentation fault: 11
// fmpz_set_ui(p, 163);
// fq_default_ctx_init_type(ctx, p, 3, "x", 2);
// test_eval_with_ctx(ctx, state);
// fq_default_ctx_clear(ctx);

// Test FQ type with GF((2^127 - 1)^2)
// TODO: crashes with bus error
// make: *** [build/fq_default_poly/test/main_TEST_RUN] Bus error: 10
// fmpz_set_str(p, "170141183460469231731687303715884105727", 10);
// fq_default_ctx_init_type(ctx, p, 2, "x", 3);
// test_eval_with_ctx(ctx, state);
// fq_default_ctx_clear(ctx);

// Test FMPZ_MOD type with GF(65537)
fmpz_set_ui(p, 65537);
fq_default_ctx_init_type(ctx, p, 1, "x", 4);
test_eval_with_ctx(ctx, state);
fq_default_ctx_clear(ctx);

// Test FMPZ_MOD type with GF(2^127 - 1)
// TODO: fails
// fmpz_set_str(p, "170141183460469231731687303715884105727", 10);
// fq_default_ctx_init_type(ctx, p, 1, "x", 5);
// test_eval_with_ctx(ctx, state);
// fq_default_ctx_clear(ctx);

fmpz_clear(p);

TEST_FUNCTION_END(state);
}

0 comments on commit 1427162

Please sign in to comment.