Skip to content

Commit

Permalink
Sketch unified tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albinahlback committed Apr 4, 2023
1 parent 791470f commit 499e10d
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 183 deletions.
59 changes: 59 additions & 0 deletions src/test/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
Copyright (C) 2023 Albin Ahlbäck
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 2.1 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

/* Include functions *********************************************************/

#include "t-add_ssaaaa.c"
#include "t-add_sssaaaaaa.c"
#include "t-add_ssssaaaaaaaa.c"
#include "t-byte_swap.c"
#include "t-flint_clz.c"
#include "t-flint_ctz.c"
#include "t-invert_limb.c"
#include "t-sdiv_qrnnd.c"
#include "t-smul_ppmm.c"
#include "t-sub_dddmmmsss.c"
#include "t-sub_ddmmss.c"
#include "t-udiv_qrnnd.c"
#include "t-udiv_qrnnd_preinv.c"
#include "t-umul_ppmm.c"

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

int (*test_functions[])(void) =
{
TEST_FUNCTION(add_ssaaaa),
TEST_FUNCTION(add_sssaaaaaa),
TEST_FUNCTION(add_ssssaaaaaaaa),
TEST_FUNCTION(byte_swap),
TEST_FUNCTION(flint_clz),
TEST_FUNCTION(flint_ctz),
TEST_FUNCTION(invert_limb),
TEST_FUNCTION(sdiv_qrnnd),
TEST_FUNCTION(smul_ppmm),
TEST_FUNCTION(sub_dddmmmsss),
TEST_FUNCTION(sub_ddmmss),
TEST_FUNCTION(udiv_qrnnd),
TEST_FUNCTION(udiv_qrnnd_preinv),
TEST_FUNCTION(umul_ppmm)
};

/* main function *************************************************************/

int
main()
{
slong ix;

for (ix = 0; ix < sizeof(test_functions) / sizeof(int (*)(void)); ix++)
if (test_functions[ix]())
flint_abort();
}
78 changes: 35 additions & 43 deletions src/test/t-add_ssaaaa.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,42 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "flint.h"
#include "ulong_extras.h"
#include "test_helpers.h"

int main(void)
TEST_FUNCTION_START(add_ssaaaa)
{
int i, result;
FLINT_TEST_INIT(state);


flint_printf("add_ssaaaa....");
fflush(stdout);

for (i = 0; i < 1000000; i++)
{
mp_limb_t sh1, sl1, sh2, sl2, ah1, al1, ah2, al2;

ah1 = n_randtest(state);
al1 = n_randtest(state);
ah2 = n_randtest(state);
al2 = n_randtest(state);

if (n_randint(state, 10) == 0)
add_ssaaaa(sh1, sl1, (slong) ah1, (slong) al1, (slong) ah2, (slong) al2);
else
add_ssaaaa(sh1, sl1, ah1, al1, ah2, al2);

sl2 = al1 + al2;
sh2 = (sl1 < al1);
sh2 += ah1;
sh2 += ah2;

result = ((sh2 == sh1) && (sl2 == sl1));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("ah1 = %wu, al1 = %wu, ah2 = %wu, al1 = %wu\n", ah1, al1, ah2, al1);
flint_printf("sh2 = %wu, sh1 = %wu, sl2 = %wu, sl1 = %wu\n", sh2, sh1, sl2, sl1);
fflush(stdout);
flint_abort();
}
}

FLINT_TEST_CLEANUP(state);

flint_printf("PASS\n");
return 0;
int i, result;

for (i = 0; i < 1000000; i++)
{
mp_limb_t sh1, sl1, sh2, sl2, ah1, al1, ah2, al2;

ah1 = n_randtest(state);
al1 = n_randtest(state);
ah2 = n_randtest(state);
al2 = n_randtest(state);

if (n_randint(state, 10) == 0)
add_ssaaaa(sh1, sl1, (slong) ah1, (slong) al1, (slong) ah2, (slong) al2);
else
add_ssaaaa(sh1, sl1, ah1, al1, ah2, al2);

sl2 = al1 + al2;
sh2 = (sl1 < al1);
sh2 += ah1;
sh2 += ah2;

result = ((sh2 == sh1) && (sl2 == sl1));
if (!result)
{
flint_printf("FAIL:\n");
flint_printf("ah1 = %wu, al1 = %wu, ah2 = %wu, al1 = %wu\n", ah1, al1, ah2, al1);
flint_printf("sh2 = %wu, sh1 = %wu, sl2 = %wu, sl1 = %wu\n", sh2, sh1, sl2, sl1);
fflush(stdout);
flint_abort();
}
}

TEST_FUNCTION_END;
}
14 changes: 3 additions & 11 deletions src/test/t-add_sssaaaaaa.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "flint.h"
#include "ulong_extras.h"
#include "test_helpers.h"

int main(void)
TEST_FUNCTION_START(add_sssaaaaaa)
{
int i, j, result;
FLINT_TEST_INIT(state);


flint_printf("add_sssaaaaaa....");
fflush(stdout);

for (i = 0; i < 1000000; i++)
{
Expand Down Expand Up @@ -51,8 +46,5 @@ int main(void)
}
}

FLINT_TEST_CLEANUP(state);

flint_printf("PASS\n");
return 0;
TEST_FUNCTION_END;
}
15 changes: 5 additions & 10 deletions src/test/t-add_ssssaaaaaaaa.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
/*
Copyright (C) 2019 Daniel Schultz
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 2.1 of the License, or
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "flint.h"
#include "ulong_extras.h"
#include "test_helpers.h"

int main(void)
TEST_FUNCTION_START(add_ssssaaaaaaaa)
{
int i, j, result;
FLINT_TEST_INIT(state);

flint_printf("add_ssssaaaaaaaa....");
fflush(stdout);

for (i = 0; i < 1000000; i++)
{
Expand Down Expand Up @@ -73,8 +71,5 @@ int main(void)
}
}

FLINT_TEST_CLEANUP(state);

flint_printf("PASS\n");
return 0;
TEST_FUNCTION_END;
}
14 changes: 4 additions & 10 deletions src/test/t-byte_swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "flint.h"
#include "ulong_extras.h"
#include "test_helpers.h"

ulong byte_swap_naive(ulong n)
{
Expand All @@ -27,13 +27,10 @@ ulong byte_swap_naive(ulong n)
return r;
}

int main(void)

TEST_FUNCTION_START(byte_swap)
{
int i, result;
FLINT_TEST_INIT(state);

flint_printf("byte_swap....");
fflush(stdout);

/* byte_swap(byte_swap(n)) == n */
for (i = 0; i < 10000 * flint_test_multiplier(); i++)
Expand Down Expand Up @@ -82,8 +79,5 @@ int main(void)
}
}

FLINT_TEST_CLEANUP(state);

flint_printf("PASS\n");
return 0;
TEST_FUNCTION_END;
}
14 changes: 3 additions & 11 deletions src/test/t-flint_clz.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "flint.h"
#include "ulong_extras.h"
#include "test_helpers.h"

int main(void)
TEST_FUNCTION_START(flint_clz)
{
int i, result;
FLINT_TEST_INIT(state);


flint_printf("flint_clz....");
fflush(stdout);

for (i = 0; i < 1000000; i++)
{
Expand All @@ -41,8 +36,5 @@ int main(void)
}
}

FLINT_TEST_CLEANUP(state);

flint_printf("PASS\n");
return 0;
TEST_FUNCTION_END;
}
14 changes: 3 additions & 11 deletions src/test/t-flint_ctz.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "flint.h"
#include "ulong_extras.h"
#include "test_helpers.h"

int main(void)
TEST_FUNCTION_START(flint_ctz)
{
int i, result;
FLINT_TEST_INIT(state);


flint_printf("flint_ctz....");
fflush(stdout);

for (i = 0; i < 1000000; i++)
{
Expand All @@ -41,8 +36,5 @@ int main(void)
}
}

FLINT_TEST_CLEANUP(state);

flint_printf("PASS\n");
return 0;
TEST_FUNCTION_END;
}
13 changes: 3 additions & 10 deletions src/test/t-invert_limb.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,18 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include "flint.h"
#include "ulong_extras.h"
#include "test_helpers.h"

#define invert_limb_naive(ninv, n) \
do { \
mp_limb_t dummy; \
udiv_qrnnd (ninv, dummy, ~(n), ~(WORD(0)), n); \
} while (0)

int main(void)
TEST_FUNCTION_START(invert_limb)
{
int i, result;
FLINT_TEST_INIT(state);

flint_printf("invert_limb....");
fflush(stdout);

for (i = 0; i < 100000 * flint_test_multiplier(); i++)
{
Expand All @@ -46,8 +42,5 @@ int main(void)
}
}

FLINT_TEST_CLEANUP(state);

flint_printf("PASS\n");
return 0;
TEST_FUNCTION_END
}
14 changes: 3 additions & 11 deletions src/test/t-sdiv_qrnnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@
(at your option) any later version. See <https://www.gnu.org/licenses/>.
*/

#include <limits.h>
#include "flint.h"
#include "ulong_extras.h"
#include "test_helpers.h"

int main(void)
TEST_FUNCTION_START(sdiv_qrnnd)
{
slong i;
FLINT_TEST_INIT(state);

flint_printf("sdiv_qrnnd....");
fflush(stdout);

for (i = 0; i < 1000000*flint_test_multiplier(); i++)
{
Expand Down Expand Up @@ -75,8 +70,5 @@ int main(void)
}
}

FLINT_TEST_CLEANUP(state);

flint_printf("PASS\n");
return 0;
TEST_FUNCTION_END;
}
Loading

0 comments on commit 499e10d

Please sign in to comment.