aboutsummaryrefslogtreecommitdiff
path: root/gmp-6.3.0/tests/cxx/t-iostream.cc
diff options
context:
space:
mode:
authorDuncan Wilkie <antigravityd@gmail.com>2023-11-18 06:11:09 -0600
committerDuncan Wilkie <antigravityd@gmail.com>2023-11-18 06:11:09 -0600
commit11da511c784eca003deb90c23570f0873954e0de (patch)
treee14fdd3d5d6345956d67e79ae771d0633d28362b /gmp-6.3.0/tests/cxx/t-iostream.cc
Initial commit.
Diffstat (limited to 'gmp-6.3.0/tests/cxx/t-iostream.cc')
-rw-r--r--gmp-6.3.0/tests/cxx/t-iostream.cc106
1 files changed, 106 insertions, 0 deletions
diff --git a/gmp-6.3.0/tests/cxx/t-iostream.cc b/gmp-6.3.0/tests/cxx/t-iostream.cc
new file mode 100644
index 0000000..76e280b
--- /dev/null
+++ b/gmp-6.3.0/tests/cxx/t-iostream.cc
@@ -0,0 +1,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;
+}