diff options
author | Marc Glisse <marc.glisse@inria.fr> | 2011-09-21 15:05:45 +0200 |
---|---|---|
committer | Marc Glisse <marc.glisse@inria.fr> | 2011-09-21 15:05:45 +0200 |
commit | a6250b15fb8880ba047624a16693285e5284825a (patch) | |
tree | 3fabc4506522a1cd0c79ebcf5ccbc0b32fcab7e7 /tests/cxx | |
parent | af14b70ec142e9ce184456a40ee322cc1370c155 (diff) | |
download | gmp-a6250b15fb8880ba047624a16693285e5284825a.tar.gz |
Add swap functions to gmpxx.
Diffstat (limited to 'tests/cxx')
-rw-r--r-- | tests/cxx/t-assign.cc | 90 |
1 files changed, 89 insertions, 1 deletions
diff --git a/tests/cxx/t-assign.cc b/tests/cxx/t-assign.cc index e68ac6d28..702606bec 100644 --- a/tests/cxx/t-assign.cc +++ b/tests/cxx/t-assign.cc @@ -27,7 +27,8 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ #include "gmp-impl.h" #include "tests.h" -using namespace std; +using std::string; +using std::invalid_argument; void @@ -185,6 +186,35 @@ check_mpz (void) } catch (invalid_argument) { } } + + // swap(mpz_class &) + { + mpz_class a(123); + mpz_class b(456); + a.swap(b); + a.swap(a); + ASSERT_ALWAYS(a == 456); + ASSERT_ALWAYS(b == 123); + } + + // swap(mpz_class &, mpz_class &) + { + mpz_class a(123); + mpz_class b(456); + ::swap(a, b); + ::swap(a, a); + ASSERT_ALWAYS(a == 456); + ASSERT_ALWAYS(b == 123); + } + { + using std::swap; + mpz_class a(123); + mpz_class b(456); + swap(a, b); + swap(a, a); + ASSERT_ALWAYS(a == 456); + ASSERT_ALWAYS(b == 123); + } } void @@ -342,6 +372,35 @@ check_mpq (void) } catch (invalid_argument) { } } + + // swap(mpq_class &) + { + mpq_class a(3, 2); + mpq_class b(-1, 4); + a.swap(b); + a.swap(a); + ASSERT_ALWAYS(a == -.25); + ASSERT_ALWAYS(b == 1.5); + } + + // swap(mpq_class &, mpq_class &) + { + mpq_class a(3, 2); + mpq_class b(-1, 4); + ::swap(a, b); + ::swap(a, a); + ASSERT_ALWAYS(a == -.25); + ASSERT_ALWAYS(b == 1.5); + } + { + using std::swap; + mpq_class a(3, 2); + mpq_class b(-1, 4); + swap(a, b); + swap(a, a); + ASSERT_ALWAYS(a == -.25); + ASSERT_ALWAYS(b == 1.5); + } } void @@ -499,6 +558,35 @@ check_mpf (void) } catch (invalid_argument) { } } + + // swap(mpf_class &) + { + mpf_class a(123); + mpf_class b(456); + a.swap(b); + a.swap(a); + ASSERT_ALWAYS(a == 456); + ASSERT_ALWAYS(b == 123); + } + + // swap(mpf_class &, mpf_class &) + { + mpf_class a(123); + mpf_class b(456); + ::swap(a, b); + ::swap(a, a); + ASSERT_ALWAYS(a == 456); + ASSERT_ALWAYS(b == 123); + } + { + using std::swap; + mpf_class a(123); + mpf_class b(456); + swap(a, b); + swap(a, a); + ASSERT_ALWAYS(a == 456); + ASSERT_ALWAYS(b == 123); + } } |