[Gmp-commit] /home/hgfiles/gmp: Some more generated tests for binomial.
mercurial at gmplib.org
mercurial at gmplib.org
Tue Mar 9 07:04:20 CET 2010
details: /home/hgfiles/gmp/rev/3d137583d554
changeset: 13473:3d137583d554
user: Marco Bodrato <bodrato at mail.dm.unipi.it>
date: Tue Mar 09 07:04:13 2010 +0100
description:
Some more generated tests for binomial.
diffstat:
ChangeLog | 4 +++
tests/mpz/t-bin.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 70 insertions(+), 5 deletions(-)
diffs (125 lines):
diff -r 419f6a4cc606 -r 3d137583d554 ChangeLog
--- a/ChangeLog Wed Mar 03 20:10:08 2010 +0100
+++ b/ChangeLog Tue Mar 09 07:04:13 2010 +0100
@@ -1,3 +1,7 @@
+2010-03-09 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+ * tests/mpz/t-bin.c (randomwalk): New test-generator function.
+
2010-03-03 Torbjorn Granlund <tege at gmplib.org>
* mpn/x86_64/core2/divrem_1.asm: New file.
diff -r 419f6a4cc606 -r 3d137583d554 tests/mpz/t-bin.c
--- a/tests/mpz/t-bin.c Wed Mar 03 20:10:08 2010 +0100
+++ b/tests/mpz/t-bin.c Tue Mar 09 07:04:13 2010 +0100
@@ -1,6 +1,6 @@
/* Exercise mpz_bin_ui and mpz_bin_uiui.
-Copyright 2000, 2001 Free Software Foundation, Inc.
+Copyright 2000, 2001, 2010 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
@@ -23,6 +23,8 @@
#include "gmp-impl.h"
#include "tests.h"
+/* Default number of generated tests. */
+#define COUNT 400
void
try_mpz_bin_ui (mpz_srcptr want, mpz_srcptr n, unsigned long k)
@@ -180,7 +182,7 @@
/* Test some bin(2k,k) cases. This produces some biggish numbers to
exercise the limb accumulating code. */
void
-twos (void)
+twos (int count)
{
mpz_t n, want;
unsigned long k;
@@ -189,7 +191,7 @@
mpz_init (want);
mpz_set_ui (want, (unsigned long) 2);
- for (k = 1; k < 200; k++)
+ for (k = 1; k < count; k++)
{
mpz_set_ui (n, 2*k);
try_mpz_bin_ui (want, n, k);
@@ -204,14 +206,73 @@
mpz_clear (want);
}
+/* Test some random bin(n,k) cases. This produces some biggish
+ numbers to exercise the limb accumulating code. */
+void
+randomwalk (int count)
+{
+ mpz_t n_z, want;
+ unsigned long n, k, i, r;
+ int tests;
+ gmp_randstate_ptr rands;
+
+ rands = RANDS;
+ mpz_init (n_z);
+ mpz_init (want);
+
+ k = 3;
+ n = 12;
+ mpz_set_ui (want, (unsigned long) 220); /* binomial(12,3) = 220 */
+
+ for (tests = 1; tests < count; tests++)
+ {
+ r = gmp_urandomm_ui (rands, 30) + 1;
+ for (i = r & 3; i > 0; i--)
+ {
+ n++; k++;
+ mpz_mul_ui (want, want, n);
+ mpz_fdiv_q_ui (want, want, k);
+ }
+ for (i = r >> 2; i > 0; i--)
+ {
+ n++;
+ mpz_mul_ui (want, want, n);
+ mpz_fdiv_q_ui (want, want, n - k);
+ }
+
+ mpz_set_ui (n_z, n);
+ try_mpz_bin_ui (want, n_z, k);
+
+ try_mpz_bin_uiui (want, n, k);
+ }
+
+ mpz_clear (n_z);
+ mpz_clear (want);
+}
int
-main (void)
+main (int argc, char **argv)
{
+ int count;
+
+ if (argc > 1)
+ {
+ char *end;
+ count = strtol (argv[1], &end, 0);
+ if (*end || count <= 0)
+ {
+ fprintf (stderr, "Invalid test count: %s.\n", argv[1]);
+ return 1;
+ }
+ }
+ else
+ count = COUNT;
+
tests_start ();
samples ();
- twos ();
+ twos (count >> 1);
+ randomwalk (count - (count >> 1));
tests_end ();
exit (0);
More information about the gmp-commit
mailing list