github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/tests/cxx/t-unary.cc (about)

     1  /* Test mp*_class unary expressions.
     2  
     3  Copyright 2001-2003 Free Software Foundation, Inc.
     4  
     5  This file is part of the GNU MP Library test suite.
     6  
     7  The GNU MP Library test suite is free software; you can redistribute it
     8  and/or modify it under the terms of the GNU General Public License as
     9  published by the Free Software Foundation; either version 3 of the License,
    10  or (at your option) any later version.
    11  
    12  The GNU MP Library test suite is distributed in the hope that it will be
    13  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
    15  Public License for more details.
    16  
    17  You should have received a copy of the GNU General Public License along with
    18  the GNU MP Library test suite.  If not, see https://www.gnu.org/licenses/.  */
    19  
    20  #include "config.h"
    21  
    22  #include <iostream>
    23  
    24  #include "gmp.h"
    25  #include "gmpxx.h"
    26  #include "gmp-impl.h"
    27  #include "tests.h"
    28  
    29  using namespace std;
    30  
    31  
    32  void
    33  check_mpz (void)
    34  {
    35    // template <class T, class Op>
    36    // __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, T>, Op> >
    37    {
    38      mpz_class a(1);
    39      mpz_class b(+a); ASSERT_ALWAYS(b == 1);
    40    }
    41    {
    42      mpz_class a(2);
    43      mpz_class b;
    44      b = -a; ASSERT_ALWAYS(b == -2);
    45    }
    46    {
    47      mpz_class a(3);
    48      mpz_class b;
    49      b = ~a; ASSERT_ALWAYS(b == -4);
    50    }
    51  
    52    // template <class T, class U, class Op>
    53    // __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, U>, Op> >
    54    {
    55      mpz_class a(1);
    56      mpz_class b(-(-a)); ASSERT_ALWAYS(b == 1);
    57    }
    58    {
    59      mpz_class a(2);
    60      mpz_class b;
    61      b = -(-(-a)); ASSERT_ALWAYS(b == -2);
    62    }
    63  }
    64  
    65  void
    66  check_mpq (void)
    67  {
    68    // template <class T, class Op>
    69    // __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, T>, Op> >
    70    {
    71      mpq_class a(1);
    72      mpq_class b(+a); ASSERT_ALWAYS(b == 1);
    73    }
    74    {
    75      mpq_class a(2);
    76      mpq_class b;
    77      b = -a; ASSERT_ALWAYS(b == -2);
    78    }
    79  
    80    // template <class T, class U, class Op>
    81    // __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, U>, Op> >
    82    {
    83      mpq_class a(1);
    84      mpq_class b(-(-a)); ASSERT_ALWAYS(b == 1);
    85    }
    86    {
    87      mpq_class a(2);
    88      mpq_class b;
    89      b = -(-(-a)); ASSERT_ALWAYS(b == -2);
    90    }
    91  }
    92  
    93  void
    94  check_mpf (void)
    95  {
    96    // template <class T, class Op>
    97    // __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, T>, Op> >
    98    {
    99      mpf_class a(1);
   100      mpf_class b(+a); ASSERT_ALWAYS(b == 1);
   101    }
   102    {
   103      mpf_class a(2);
   104      mpf_class b;
   105      b = -a; ASSERT_ALWAYS(b == -2);
   106    }
   107  
   108    // template <class T, class U, class Op>
   109    // __gmp_expr<T, __gmp_unary_expr<__gmp_expr<T, U>, Op> >
   110    {
   111      mpf_class a(1);
   112      mpf_class b(-(-a)); ASSERT_ALWAYS(b == 1);
   113    }
   114    {
   115      mpf_class a(2);
   116      mpf_class b;
   117      b = -(-(-a)); ASSERT_ALWAYS(b == -2);
   118    }
   119  }
   120  
   121  
   122  int
   123  main (void)
   124  {
   125    tests_start();
   126  
   127    check_mpz();
   128    check_mpq();
   129    check_mpf();
   130  
   131    tests_end();
   132    return 0;
   133  }