Annotation of OpenXM_contrib/gmp/tests/mpq/t-set_str.c, Revision 1.1.1.1
1.1 ohara 1: /* Test mpq_set_str.
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 want, int base, const char *str)
31: {
32: mpq_t got;
33:
34: MPQ_CHECK_FORMAT (want);
35: mp_trace_base = base;
36:
37: mpq_init (got);
38:
39: if (mpq_set_str (got, str, base) != 0)
40: {
41: printf ("mpq_set_str unexpectedly failed\n");
42: printf (" base %d\n", base);
43: printf (" str \"%s\"\n", str);
44: abort ();
45: }
46: MPQ_CHECK_FORMAT (got);
47:
48: if (! mpq_equal (got, want))
49: {
50: printf ("mpq_set_str wrong\n");
51: printf (" base %d\n", base);
52: printf (" str \"%s\"\n", str);
53: mpq_trace ("got ", got);
54: mpq_trace ("want", want);
55: abort ();
56: }
57:
58: mpq_clear (got);
59: }
60:
61: void
62: check_samples (void)
63: {
64: mpq_t q;
65:
66: mpq_init (q);
67:
68: mpq_set_ui (q, 0L, 1L);
69: check_one (q, 10, "0");
70: check_one (q, 10, "0/1");
71: check_one (q, 10, "0 / 1");
72: check_one (q, 0, "0x0/ 1");
73: check_one (q, 0, "0x0/ 0x1");
74: check_one (q, 0, "0 / 0x1");
75:
76: check_one (q, 10, "-0");
77: check_one (q, 10, "-0/1");
78: check_one (q, 10, "-0 / 1");
79: check_one (q, 0, "-0x0/ 1");
80: check_one (q, 0, "-0x0/ 0x1");
81: check_one (q, 0, "-0 / 0x1");
82:
83: mpq_set_ui (q, 255L, 256L);
84: check_one (q, 10, "255/256");
85: check_one (q, 0, "0xFF/0x100");
86: check_one (q, 16, "FF/100");
87:
88: mpq_neg (q, q);
89: check_one (q, 10, "-255/256");
90: check_one (q, 0, "-0xFF/0x100");
91: check_one (q, 16, "-FF/100");
92:
93: mpq_clear (q);
94: }
95:
96: int
97: main (void)
98: {
99: tests_start ();
100:
101: check_samples ();
102:
103: tests_end ();
104: exit (0);
105: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>