Annotation of OpenXM_contrib/gmp/tests/mpq/t-cmp_si.c, Revision 1.1.1.1
1.1 ohara 1: /* Test mpq_cmp_si.
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 <limits.h>
25:
26: #include "gmp.h"
27: #include "gmp-impl.h"
28: #include "tests.h"
29:
30:
31: #define SGN(x) ((x)<0 ? -1 : (x) != 0)
32:
33: void
34: check_data (void)
35: {
36: static const struct {
37: const char *q;
38: long n;
39: unsigned long d;
40: int want;
41: } data[] = {
42: { "0", 0, 1, 0 },
43: { "0", 0, 123, 0 },
44: { "0", 0, ULONG_MAX, 0 },
45: { "1", 0, 1, 1 },
46: { "1", 0, 123, 1 },
47: { "1", 0, ULONG_MAX, 1 },
48: { "-1", 0, 1, -1 },
49: { "-1", 0, 123, -1 },
50: { "-1", 0, ULONG_MAX, -1 },
51:
52: { "123", 123, 1, 0 },
53: { "124", 123, 1, 1 },
54: { "122", 123, 1, -1 },
55:
56: { "-123", 123, 1, -1 },
57: { "-124", 123, 1, -1 },
58: { "-122", 123, 1, -1 },
59:
60: { "123", -123, 1, 1 },
61: { "124", -123, 1, 1 },
62: { "122", -123, 1, 1 },
63:
64: { "-123", -123, 1, 0 },
65: { "-124", -123, 1, -1 },
66: { "-122", -123, 1, 1 },
67:
68: { "5/7", 3,4, -1 },
69: { "5/7", -3,4, 1 },
70: { "-5/7", 3,4, -1 },
71: { "-5/7", -3,4, 1 },
72: };
73:
74: mpq_t q;
75: int i, got;
76:
77: mpq_init (q);
78:
79: for (i = 0; i < numberof (data); i++)
80: {
81: mpq_set_str_or_abort (q, data[i].q, 0);
82: MPQ_CHECK_FORMAT (q);
83:
84: got = mpq_cmp_si (q, data[i].n, data[i].d);
85: if (SGN(got) != data[i].want)
86: {
87: printf ("mpq_cmp_si wrong\n");
88: error:
89: mpq_trace (" q", q);
90: printf (" n=%ld\n", data[i].n);
91: printf (" d=%lu\n", data[i].d);
92: printf (" got=%d\n", got);
93: printf (" want=%d\n", data[i].want);
94: abort ();
95: }
96:
97: if (data[i].n == 0)
98: {
99: got = mpq_cmp_si (q, 0L, data[i].d);
100: if (SGN(got) != data[i].want)
101: {
102: printf ("mpq_cmp_si wrong\n");
103: goto error;
104: }
105: }
106: }
107:
108: mpq_clear (q);
109: }
110:
111: int
112: main (int argc, char **argv)
113: {
114: tests_start ();
115:
116: check_data ();
117:
118: tests_end ();
119: exit (0);
120: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>