diff options
author | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2022-09-08 22:02:50 +0200 |
---|---|---|
committer | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2022-09-08 22:02:50 +0200 |
commit | dbcd5a39702fa91d757d412e422a945ed079ec35 (patch) | |
tree | c6632a848173673b78877309341048a90334749c /mini-gmp/tests | |
parent | 7c92275fe4133ce24c268078e1294f4fba4ecd43 (diff) | |
download | gmp-dbcd5a39702fa91d757d412e422a945ed079ec35.tar.gz |
mini-gmp/tests/t-powm.c: Test some corner cases
Diffstat (limited to 'mini-gmp/tests')
-rw-r--r-- | mini-gmp/tests/t-powm.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/mini-gmp/tests/t-powm.c b/mini-gmp/tests/t-powm.c index d6c108d47..1cce9b5fb 100644 --- a/mini-gmp/tests/t-powm.c +++ b/mini-gmp/tests/t-powm.c @@ -1,6 +1,6 @@ /* -Copyright 2012, Free Software Foundation, Inc. +Copyright 2012, 2022, Free Software Foundation, Inc. This file is part of the GNU MP Library test suite. @@ -53,6 +53,32 @@ testmain (int argc, char **argv) abort (); } } + + /* res >= 0, come from the random choices above, */ + if (mpz_cmp_ui (res, 1) <= 0) /* if too small, */ + mpz_add_ui (res, res, 9); /* add an arbitrary value. */ + + mpz_set_ui (e, 0); + /* Test the case m^0 (mod m), expect 1 (m is greater than 1). */ + mpz_powm (res, res, e, res); + if (mpz_cmp_ui (res, 1) != 0) + { + fprintf (stderr, "mpz_powm failed: b=m, e=0; 1 expected,\n"); + dump ("m", res); + dump ("r", res); + abort (); + } + + /* Now res is 1. */ + /* Test the case 1^0 (mod 1), expect 0. */ + mpz_powm (res, res, e, res); + if (mpz_size (res)) + { + fprintf (stderr, "mpz_powm failed: b=1, e=0, m=1; 0 expected,\n"); + dump ("r", res); + abort (); + } + mpz_clear (b); mpz_clear (e); mpz_clear (m); |