Annotation of OpenXM_contrib/gmp/tests/mpq/t-equal.c, Revision 1.1
1.1 ! ohara 1: /* Test mpq_equal.
! 2:
! 3: Copyright 2001 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 2.1 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; see the file COPYING.LIB. If not, write to
! 19: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
! 20: MA 02111-1307, USA. */
! 21:
! 22: #include <stdio.h>
! 23: #include <stdlib.h>
! 24: #include "gmp.h"
! 25: #include "gmp-impl.h"
! 26: #include "tests.h"
! 27:
! 28:
! 29: void
! 30: check_one (mpq_srcptr x, mpq_srcptr y, int want)
! 31: {
! 32: int got;
! 33:
! 34: MPQ_CHECK_FORMAT (x);
! 35: MPQ_CHECK_FORMAT (y);
! 36:
! 37: got = mpq_equal (x, y);
! 38: if ((got != 0) != (want != 0))
! 39: {
! 40: printf ("mpq_equal got %d want %d\n", got, want);
! 41: mpq_trace ("x", x);
! 42: mpq_trace ("y", y);
! 43: abort ();
! 44: }
! 45: }
! 46:
! 47:
! 48: void
! 49: check_all (mpq_ptr x, mpq_ptr y, int want)
! 50: {
! 51: check_one (x, y, want);
! 52: check_one (y, x, want);
! 53:
! 54: mpq_neg (x, x);
! 55: mpq_neg (y, y);
! 56:
! 57: check_one (x, y, want);
! 58: check_one (y, x, want);
! 59: }
! 60:
! 61:
! 62: #define SET4Z(z, size,l3,l2,l1,l0) \
! 63: SIZ(z) = size; PTR(z)[3] = l3; PTR(z)[2] = l2; PTR(z)[1] = l1; PTR(z)[0] = l0
! 64:
! 65: #define SET4(q, nsize,n3,n2,n1,n0, dsize,d3,d2,d1,d0) \
! 66: SET4Z (mpq_numref(q), nsize,n3,n2,n1,n0); \
! 67: SET4Z (mpq_denref(q), dsize,d3,d2,d1,d0)
! 68:
! 69:
! 70: /* Exercise various combinations of same and slightly different values. */
! 71:
! 72: void
! 73: check_various (void)
! 74: {
! 75: mpq_t x, y;
! 76:
! 77: mpq_init (x);
! 78: mpq_init (y);
! 79:
! 80: mpz_realloc (mpq_numref(x), (mp_size_t) 20);
! 81: mpz_realloc (mpq_denref(x), (mp_size_t) 20);
! 82: mpz_realloc (mpq_numref(y), (mp_size_t) 20);
! 83: mpz_realloc (mpq_denref(y), (mp_size_t) 20);
! 84:
! 85: /* 0 == 0 */
! 86: SET4 (x, 0,13,12,11,10, 1,23,22,21,1);
! 87: SET4 (y, 0,33,32,31,30, 1,43,42,41,1);
! 88: check_all (x, y, 1);
! 89:
! 90: /* 83/99 == 83/99 */
! 91: SET4 (x, 1,13,12,11,83, 1,23,22,21,99);
! 92: SET4 (y, 1,33,32,31,83, 1,43,42,41,99);
! 93: check_all (x, y, 1);
! 94:
! 95: /* 1:2:3:4/5:6:7 == 1:2:3:4/5:6:7 */
! 96: SET4 (x, 4,1,2,3,4, 3,88,5,6,7);
! 97: SET4 (y, 4,1,2,3,4, 3,99,5,6,7);
! 98: check_all (x, y, 1);
! 99:
! 100: /* various individual changes making != */
! 101: SET4 (x, 4,1,2,3,667, 3,88,5,6,7);
! 102: SET4 (y, 4,1,2,3,4, 3,99,5,6,7);
! 103: check_all (x, y, 0);
! 104: SET4 (x, 4,1,2,666,4, 3,88,5,6,7);
! 105: SET4 (y, 4,1,2,3,4, 3,99,5,6,7);
! 106: check_all (x, y, 0);
! 107: SET4 (x, 4,1,666,3,4, 3,88,5,6,7);
! 108: SET4 (y, 4,1,2,3,4, 3,99,5,6,7);
! 109: check_all (x, y, 0);
! 110: SET4 (x, 4,667,2,3,4, 3,88,5,6,7);
! 111: SET4 (y, 4,1,2,3,4, 3,99,5,6,7);
! 112: check_all (x, y, 0);
! 113: SET4 (x, 4,1,2,3,4, 3,88,5,6,667);
! 114: SET4 (y, 4,1,2,3,4, 3,99,5,6,7);
! 115: check_all (x, y, 0);
! 116: SET4 (x, 4,1,2,3,4, 3,88,5,667,7);
! 117: SET4 (y, 4,1,2,3,4, 3,99,5,6,7);
! 118: check_all (x, y, 0);
! 119: SET4 (x, 4,1,2,3,4, 3,88,666,6,7);
! 120: SET4 (y, 4,1,2,3,4, 3,99,5,6,7);
! 121: check_all (x, y, 0);
! 122: SET4 (x, -4,1,2,3,4, 3,88,5,6,7);
! 123: SET4 (y, 4,1,2,3,4, 3,99,5,6,7);
! 124: check_all (x, y, 0);
! 125: SET4 (x, 1,1,2,3,4, 3,88,5,6,7);
! 126: SET4 (y, 4,1,2,3,4, 3,99,5,6,7);
! 127: check_all (x, y, 0);
! 128:
! 129: mpq_clear (x);
! 130: mpq_clear (y);
! 131: }
! 132:
! 133:
! 134: int
! 135: main (void)
! 136: {
! 137: tests_start ();
! 138: mp_trace_base = -16;
! 139:
! 140: check_various ();
! 141:
! 142: tests_end ();
! 143: exit (0);
! 144: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>