aboutsummaryrefslogtreecommitdiff
path: root/vendor/gmp-6.3.0/tests/cxx/t-iostream.cc
blob: 76e280b5981f25971ee3acc3f363dacab1f38103 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* Test stream formatted input and output on mp*_class

Copyright 2011 Free Software Foundation, Inc.

This file is part of the GNU MP Library test suite.

The GNU MP Library test suite is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.

The GNU MP Library test suite is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
Public License for more details.

You should have received a copy of the GNU General Public License along with
the GNU MP Library test suite.  If not, see https://www.gnu.org/licenses/.  */

#include <sstream>

#include "gmpxx.h"
#include "gmp-impl.h"
#include "tests.h"

using namespace std;

// The tests are extremely basic. These functions just forward to the
// ones tested in t-istream.cc and t-ostream.cc; we rely on those for
// advanced tests and only check the syntax here.

void
checki ()
{
  {
    istringstream i("123");
    mpz_class x;
    i >> x;
    ASSERT_ALWAYS (x == 123);
  }
  {
    istringstream i("3/4");
    mpq_class x;
    i >> x;
    ASSERT_ALWAYS (x == .75);
  }
  {
    istringstream i("1.5");
    mpf_class x;
    i >> x;
    ASSERT_ALWAYS (x == 1.5);
  }
}

void
checko ()
{
  {
    ostringstream o;
    mpz_class x=123;
    o << x;
    ASSERT_ALWAYS (o.str() == "123");
  }
  {
    ostringstream o;
    mpz_class x=123;
    o << (x+1);
    ASSERT_ALWAYS (o.str() == "124");
  }
  {
    ostringstream o;
    mpq_class x(3,4);
    o << x;
    ASSERT_ALWAYS (o.str() == "3/4");
  }
  {
    ostringstream o;
    mpq_class x(3,4);
    o << (x+1);
    ASSERT_ALWAYS (o.str() == "7/4");
  }
  {
    ostringstream o;
    mpf_class x=1.5;
    o << x;
    ASSERT_ALWAYS (o.str() == "1.5");
  }
  {
    ostringstream o;
    mpf_class x=1.5;
    o << (x+1);
    ASSERT_ALWAYS (o.str() == "2.5");
  }
}

int
main (int argc, char *argv[])
{
  tests_start ();

  checki ();
  checko ();

  tests_end ();
  return 0;
}