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