1 1.1 mrg /* Test mpq_equal. 2 1.1 mrg 3 1.1 mrg Copyright 2001 Free Software Foundation, Inc. 4 1.1 mrg 5 1.1.1.2 mrg This file is part of the GNU MP Library test suite. 6 1.1 mrg 7 1.1.1.2 mrg The GNU MP Library test suite is free software; you can redistribute it 8 1.1.1.2 mrg and/or modify it under the terms of the GNU General Public License as 9 1.1.1.2 mrg published by the Free Software Foundation; either version 3 of the License, 10 1.1.1.2 mrg or (at your option) any later version. 11 1.1.1.2 mrg 12 1.1.1.2 mrg The GNU MP Library test suite is distributed in the hope that it will be 13 1.1.1.2 mrg useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1.1.2 mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 15 1.1.1.2 mrg Public License for more details. 16 1.1 mrg 17 1.1.1.2 mrg You should have received a copy of the GNU General Public License along with 18 1.1.1.3 mrg the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ 19 1.1 mrg 20 1.1 mrg #include <stdio.h> 21 1.1 mrg #include <stdlib.h> 22 1.1 mrg #include "gmp-impl.h" 23 1.1 mrg #include "tests.h" 24 1.1 mrg 25 1.1 mrg 26 1.1 mrg void 27 1.1 mrg check_one (mpq_srcptr x, mpq_srcptr y, int want) 28 1.1 mrg { 29 1.1 mrg int got; 30 1.1 mrg 31 1.1 mrg MPQ_CHECK_FORMAT (x); 32 1.1 mrg MPQ_CHECK_FORMAT (y); 33 1.1 mrg 34 1.1 mrg got = mpq_equal (x, y); 35 1.1 mrg if ((got != 0) != (want != 0)) 36 1.1 mrg { 37 1.1 mrg printf ("mpq_equal got %d want %d\n", got, want); 38 1.1 mrg mpq_trace ("x", x); 39 1.1 mrg mpq_trace ("y", y); 40 1.1 mrg abort (); 41 1.1 mrg } 42 1.1 mrg } 43 1.1 mrg 44 1.1 mrg 45 1.1 mrg void 46 1.1 mrg check_all (mpq_ptr x, mpq_ptr y, int want) 47 1.1 mrg { 48 1.1 mrg check_one (x, y, want); 49 1.1 mrg check_one (y, x, want); 50 1.1 mrg 51 1.1 mrg mpq_neg (x, x); 52 1.1 mrg mpq_neg (y, y); 53 1.1 mrg 54 1.1 mrg check_one (x, y, want); 55 1.1 mrg check_one (y, x, want); 56 1.1 mrg } 57 1.1 mrg 58 1.1 mrg 59 1.1 mrg #define SET4Z(z, size,l3,l2,l1,l0) \ 60 1.1 mrg SIZ(z) = size; PTR(z)[3] = l3; PTR(z)[2] = l2; PTR(z)[1] = l1; PTR(z)[0] = l0 61 1.1 mrg 62 1.1 mrg #define SET4(q, nsize,n3,n2,n1,n0, dsize,d3,d2,d1,d0) \ 63 1.1 mrg SET4Z (mpq_numref(q), nsize,n3,n2,n1,n0); \ 64 1.1 mrg SET4Z (mpq_denref(q), dsize,d3,d2,d1,d0) 65 1.1 mrg 66 1.1 mrg 67 1.1 mrg /* Exercise various combinations of same and slightly different values. */ 68 1.1 mrg 69 1.1 mrg void 70 1.1 mrg check_various (void) 71 1.1 mrg { 72 1.1 mrg mpq_t x, y; 73 1.1 mrg 74 1.1 mrg mpq_init (x); 75 1.1 mrg mpq_init (y); 76 1.1 mrg 77 1.1 mrg mpz_realloc (mpq_numref(x), (mp_size_t) 20); 78 1.1 mrg mpz_realloc (mpq_denref(x), (mp_size_t) 20); 79 1.1 mrg mpz_realloc (mpq_numref(y), (mp_size_t) 20); 80 1.1 mrg mpz_realloc (mpq_denref(y), (mp_size_t) 20); 81 1.1 mrg 82 1.1 mrg /* 0 == 0 */ 83 1.1 mrg SET4 (x, 0,13,12,11,10, 1,23,22,21,1); 84 1.1 mrg SET4 (y, 0,33,32,31,30, 1,43,42,41,1); 85 1.1 mrg check_all (x, y, 1); 86 1.1 mrg 87 1.1 mrg /* 83/99 == 83/99 */ 88 1.1 mrg SET4 (x, 1,13,12,11,83, 1,23,22,21,99); 89 1.1 mrg SET4 (y, 1,33,32,31,83, 1,43,42,41,99); 90 1.1 mrg check_all (x, y, 1); 91 1.1 mrg 92 1.1 mrg /* 1:2:3:4/5:6:7 == 1:2:3:4/5:6:7 */ 93 1.1 mrg SET4 (x, 4,1,2,3,4, 3,88,5,6,7); 94 1.1 mrg SET4 (y, 4,1,2,3,4, 3,99,5,6,7); 95 1.1 mrg check_all (x, y, 1); 96 1.1 mrg 97 1.1 mrg /* various individual changes making != */ 98 1.1 mrg SET4 (x, 4,1,2,3,667, 3,88,5,6,7); 99 1.1 mrg SET4 (y, 4,1,2,3,4, 3,99,5,6,7); 100 1.1 mrg check_all (x, y, 0); 101 1.1 mrg SET4 (x, 4,1,2,666,4, 3,88,5,6,7); 102 1.1 mrg SET4 (y, 4,1,2,3,4, 3,99,5,6,7); 103 1.1 mrg check_all (x, y, 0); 104 1.1 mrg SET4 (x, 4,1,666,3,4, 3,88,5,6,7); 105 1.1 mrg SET4 (y, 4,1,2,3,4, 3,99,5,6,7); 106 1.1 mrg check_all (x, y, 0); 107 1.1 mrg #if GMP_NUMB_BITS != 62 108 1.1 mrg SET4 (x, 4,667,2,3,4, 3,88,5,6,7); 109 1.1 mrg SET4 (y, 4,1,2,3,4, 3,99,5,6,7); 110 1.1 mrg check_all (x, y, 0); 111 1.1 mrg #endif 112 1.1 mrg SET4 (x, 4,1,2,3,4, 3,88,5,6,667); 113 1.1 mrg SET4 (y, 4,1,2,3,4, 3,99,5,6,7); 114 1.1 mrg check_all (x, y, 0); 115 1.1 mrg SET4 (x, 4,1,2,3,4, 3,88,5,667,7); 116 1.1 mrg SET4 (y, 4,1,2,3,4, 3,99,5,6,7); 117 1.1 mrg check_all (x, y, 0); 118 1.1 mrg SET4 (x, 4,1,2,3,4, 3,88,666,6,7); 119 1.1 mrg SET4 (y, 4,1,2,3,4, 3,99,5,6,7); 120 1.1 mrg check_all (x, y, 0); 121 1.1 mrg SET4 (x, -4,1,2,3,4, 3,88,5,6,7); 122 1.1 mrg SET4 (y, 4,1,2,3,4, 3,99,5,6,7); 123 1.1 mrg check_all (x, y, 0); 124 1.1 mrg SET4 (x, 1,1,2,3,4, 3,88,5,6,7); 125 1.1 mrg SET4 (y, 4,1,2,3,4, 3,99,5,6,7); 126 1.1 mrg check_all (x, y, 0); 127 1.1.1.2 mrg SET4 (x, 4,1,2,3,4, 3,88,5,6,7); 128 1.1.1.2 mrg SET4 (y, 4,1,2,3,4, 2,99,5,6,7); 129 1.1.1.2 mrg check_all (x, y, 0); 130 1.1 mrg 131 1.1 mrg mpq_clear (x); 132 1.1 mrg mpq_clear (y); 133 1.1 mrg } 134 1.1 mrg 135 1.1 mrg 136 1.1 mrg int 137 1.1 mrg main (void) 138 1.1 mrg { 139 1.1 mrg tests_start (); 140 1.1 mrg mp_trace_base = -16; 141 1.1 mrg 142 1.1 mrg check_various (); 143 1.1 mrg 144 1.1 mrg tests_end (); 145 1.1 mrg exit (0); 146 1.1 mrg } 147