source: trunk/third/gmp/tests/mpz/t-set_str.c @ 18191

Revision 18191, 2.2 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18190, which included commits to RCS files with non-trunk default branches.
Line 
1/* Test mpz_set_str.
2
3Copyright 2001 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library.
6
7The GNU MP Library is free software; you can redistribute it and/or modify
8it under the terms of the GNU Lesser General Public License as published by
9the Free Software Foundation; either version 2.1 of the License, or (at your
10option) any later version.
11
12The GNU MP Library is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15License for more details.
16
17You should have received a copy of the GNU Lesser General Public License
18along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20MA 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
29void
30check_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
61void
62check_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
88int
89main (void)
90{
91  tests_start ();
92
93  check_samples ();
94
95  tests_end ();
96  exit (0);
97}
Note: See TracBrowser for help on using the repository browser.