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

     1  /* Test legality of conversion between the different mp*_class
     2  
     3  Copyright 2011 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 "gmp.h"
    23  #include "gmpxx.h"
    24  #include "gmp-impl.h"
    25  #include "tests.h"
    26  
    27  int f_z  (mpz_class){return 0;}
    28  int f_q  (mpq_class){return 1;}
    29  int f_f  (mpf_class){return 2;}
    30  int f_zq (mpz_class){return 0;}
    31  int f_zq (mpq_class){return 1;}
    32  int f_zf (mpz_class){return 0;}
    33  int f_zf (mpf_class){return 2;}
    34  int f_qf (mpq_class){return 1;}
    35  int f_qf (mpf_class){return 2;}
    36  int f_zqf(mpz_class){return 0;}
    37  int f_zqf(mpq_class){return 1;}
    38  int f_zqf(mpf_class){return 2;}
    39  
    40  void
    41  check (void)
    42  {
    43    mpz_class z=42;
    44    mpq_class q=33;
    45    mpf_class f=18;
    46  
    47    ASSERT_ALWAYS(f_z  (z)==0); ASSERT_ALWAYS(f_z  (-z)==0);
    48    ASSERT_ALWAYS(f_q  (z)==1); ASSERT_ALWAYS(f_q  (-z)==1);
    49    ASSERT_ALWAYS(f_q  (q)==1); ASSERT_ALWAYS(f_q  (-q)==1);
    50    ASSERT_ALWAYS(f_f  (z)==2); ASSERT_ALWAYS(f_f  (-z)==2);
    51    ASSERT_ALWAYS(f_f  (q)==2); ASSERT_ALWAYS(f_f  (-q)==2);
    52    ASSERT_ALWAYS(f_f  (f)==2); ASSERT_ALWAYS(f_f  (-f)==2);
    53    ASSERT_ALWAYS(f_zq (z)==0);
    54    ASSERT_ALWAYS(f_zq (q)==1); ASSERT_ALWAYS(f_zq (-q)==1);
    55    ASSERT_ALWAYS(f_zf (z)==0);
    56    ASSERT_ALWAYS(f_zf (f)==2); ASSERT_ALWAYS(f_zf (-f)==2);
    57    ASSERT_ALWAYS(f_qf (q)==1);
    58    ASSERT_ALWAYS(f_qf (f)==2); ASSERT_ALWAYS(f_qf (-f)==2);
    59    ASSERT_ALWAYS(f_zqf(z)==0);
    60    ASSERT_ALWAYS(f_zqf(q)==1);
    61    ASSERT_ALWAYS(f_zqf(f)==2); ASSERT_ALWAYS(f_zqf(-f)==2);
    62  
    63    ASSERT_ALWAYS(f_zqf(mpz_class(z))==0); ASSERT_ALWAYS(f_zqf(mpz_class(-z))==0);
    64    ASSERT_ALWAYS(f_zqf(mpz_class(q))==0); ASSERT_ALWAYS(f_zqf(mpz_class(-q))==0);
    65    ASSERT_ALWAYS(f_zqf(mpz_class(f))==0); ASSERT_ALWAYS(f_zqf(mpz_class(-f))==0);
    66    ASSERT_ALWAYS(f_zqf(mpq_class(z))==1); ASSERT_ALWAYS(f_zqf(mpq_class(-z))==1);
    67    ASSERT_ALWAYS(f_zqf(mpq_class(q))==1); ASSERT_ALWAYS(f_zqf(mpq_class(-q))==1);
    68    ASSERT_ALWAYS(f_zqf(mpq_class(f))==1); ASSERT_ALWAYS(f_zqf(mpq_class(-f))==1);
    69    ASSERT_ALWAYS(f_zqf(mpf_class(z))==2); ASSERT_ALWAYS(f_zqf(mpf_class(-z))==2);
    70    ASSERT_ALWAYS(f_zqf(mpf_class(q))==2); ASSERT_ALWAYS(f_zqf(mpf_class(-q))==2);
    71    ASSERT_ALWAYS(f_zqf(mpf_class(f))==2); ASSERT_ALWAYS(f_zqf(mpf_class(-f))==2);
    72  }
    73  
    74  int
    75  main (void)
    76  {
    77    tests_start();
    78  
    79    check();
    80  
    81    tests_end();
    82    return 0;
    83  }