1 /* Test gmp_randclass. 2 3 Copyright 2002, 2003 Free Software Foundation, Inc. 4 5 This file is part of the GNU MP Library. 6 7 The GNU MP Library is free software; you can redistribute it and/or modify 8 it under the terms of the GNU Lesser General Public License as published by 9 the Free Software Foundation; either version 3 of the License, or (at your 10 option) any later version. 11 12 The GNU MP Library is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 15 License for more details. 16 17 You should have received a copy of the GNU Lesser General Public License 18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ 19 20 #include "gmp.h" 21 #include "gmpxx.h" 22 #include "gmp-impl.h" 23 #include "tests.h" 24 25 using namespace std; 26 27 28 /* all flavours of initialization */ 29 void 30 check_randinit (void) 31 { 32 { 33 gmp_randclass r(gmp_randinit_default); 34 } 35 36 { 37 mpz_class a(0); 38 unsigned long c = 0, m2exp = 8; 39 gmp_randclass r(gmp_randinit_lc_2exp, a, c, m2exp); 40 } 41 42 { 43 unsigned long m2exp = 64; 44 gmp_randclass r(gmp_randinit_lc_2exp_size, m2exp); 45 } 46 47 /* gmp_randinit_lc_2exp_size, with excessive size */ 48 { 49 try { 50 unsigned long m2exp = ULONG_MAX; 51 gmp_randclass r(gmp_randinit_lc_2exp_size, m2exp); 52 ASSERT_ALWAYS (0); /* should not be reached */ 53 } catch (length_error) { 54 } 55 } 56 57 { 58 gmp_randclass r(gmp_randinit_mt); 59 } 60 61 /* obsolete, but still available */ 62 { 63 gmp_randalg_t alg = GMP_RAND_ALG_LC; 64 unsigned long m2exp = 64; 65 gmp_randclass r(alg, m2exp); 66 } 67 { 68 gmp_randalg_t alg = GMP_RAND_ALG_DEFAULT; 69 unsigned long m2exp = 64; 70 gmp_randclass r(alg, m2exp); 71 } 72 { 73 gmp_randalg_t alg = (gmp_randalg_t) 0; 74 unsigned long m2exp = 64; 75 gmp_randclass r(alg, m2exp); 76 } 77 } 78 79 void 80 check_mpz (void) 81 { 82 { 83 gmp_randclass r(gmp_randinit_default); 84 mpz_class a(123); 85 unsigned int b = 256; 86 mpz_class c; 87 r.seed(a); 88 c = r.get_z_bits(b); 89 } 90 { 91 gmp_randclass r(gmp_randinit_default); 92 mpz_class a(256); 93 unsigned long b = 123; 94 mpz_class c; 95 r.seed(b); 96 c = r.get_z_bits(a); 97 } 98 { 99 gmp_randclass r(gmp_randinit_default); 100 mpz_class a(123), b(256); 101 mpz_class c; 102 r.seed(a); 103 c = r.get_z_range(b); 104 } 105 } 106 107 void 108 check_mpf (void) 109 { 110 { 111 gmp_randclass r(gmp_randinit_default); 112 mpz_class a(123); 113 r.seed(a); 114 mpf_class b; 115 b = r.get_f(); 116 } 117 { 118 gmp_randclass r(gmp_randinit_default); 119 int a = 123, b = 128; 120 r.seed(a); 121 mpf_class c; 122 c = r.get_f(b); 123 } 124 } 125 126 127 int 128 main (void) 129 { 130 tests_start(); 131 132 check_randinit(); 133 check_mpz(); 134 check_mpf(); 135 136 tests_end(); 137 return 0; 138 } 139