1 | /* Test mpz_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 (mpz_srcptr want, int base, const char *str) |
---|
31 | { |
---|
32 | mpz_t got; |
---|
33 | |
---|
34 | MPZ_CHECK_FORMAT (want); |
---|
35 | mp_trace_base = (base == 0 ? 16 : base); |
---|
36 | |
---|
37 | mpz_init (got); |
---|
38 | |
---|
39 | if (mpz_set_str (got, str, base) != 0) |
---|
40 | { |
---|
41 | printf ("mpz_set_str unexpectedly failed\n"); |
---|
42 | printf (" base %d\n", base); |
---|
43 | printf (" str \"%s\"\n", str); |
---|
44 | abort (); |
---|
45 | } |
---|
46 | MPZ_CHECK_FORMAT (got); |
---|
47 | |
---|
48 | if (mpz_cmp (got, want) != 0) |
---|
49 | { |
---|
50 | printf ("mpz_set_str wrong\n"); |
---|
51 | printf (" base %d\n", base); |
---|
52 | printf (" str \"%s\"\n", str); |
---|
53 | mpz_trace ("got ", got); |
---|
54 | mpz_trace ("want", want); |
---|
55 | abort (); |
---|
56 | } |
---|
57 | |
---|
58 | mpz_clear (got); |
---|
59 | } |
---|
60 | |
---|
61 | void |
---|
62 | check_samples (void) |
---|
63 | { |
---|
64 | mpz_t z; |
---|
65 | |
---|
66 | mpz_init (z); |
---|
67 | |
---|
68 | mpz_set_ui (z, 0L); |
---|
69 | check_one (z, 0, "0 "); |
---|
70 | check_one (z, 0, "0 "); |
---|
71 | check_one (z, 10, "0 "); |
---|
72 | check_one (z, 10, "0 "); |
---|
73 | check_one (z, 10, "0000000 "); |
---|
74 | |
---|
75 | mpz_set_ui (z, 123L); |
---|
76 | check_one (z, 0, "123 "); |
---|
77 | check_one (z, 0, "123 "); |
---|
78 | check_one (z, 10, "123 "); |
---|
79 | check_one (z, 10, "123 "); |
---|
80 | check_one (z, 0, " 123 "); |
---|
81 | check_one (z, 0, " 123 "); |
---|
82 | check_one (z, 10, " 0000123 "); |
---|
83 | check_one (z, 10, " 123 "); |
---|
84 | |
---|
85 | mpz_clear (z); |
---|
86 | } |
---|
87 | |
---|
88 | int |
---|
89 | main (void) |
---|
90 | { |
---|
91 | tests_start (); |
---|
92 | |
---|
93 | check_samples (); |
---|
94 | |
---|
95 | tests_end (); |
---|
96 | exit (0); |
---|
97 | } |
---|