t-mix.cc revision 1.1.1.3
1/* Test legality of conversion between the different mp*_class 2 3Copyright 2011 Free Software Foundation, Inc. 4 5This file is part of the GNU MP Library test suite. 6 7The GNU MP Library test suite is free software; you can redistribute it 8and/or modify it under the terms of the GNU General Public License as 9published by the Free Software Foundation; either version 3 of the License, 10or (at your option) any later version. 11 12The GNU MP Library test suite is distributed in the hope that it will be 13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 15Public License for more details. 16 17You should have received a copy of the GNU General Public License along with 18the GNU MP Library test suite. If not, see https://www.gnu.org/licenses/. */ 19 20#include "config.h" 21 22#include "gmpxx.h" 23#include "gmp-impl.h" 24#include "tests.h" 25 26int f_z (mpz_class){return 0;} 27int f_q (mpq_class){return 1;} 28int f_f (mpf_class){return 2;} 29int f_zq (mpz_class){return 0;} 30int f_zq (mpq_class){return 1;} 31int f_zf (mpz_class){return 0;} 32int f_zf (mpf_class){return 2;} 33int f_qf (mpq_class){return 1;} 34int f_qf (mpf_class){return 2;} 35int f_zqf(mpz_class){return 0;} 36int f_zqf(mpq_class){return 1;} 37int f_zqf(mpf_class){return 2;} 38 39void 40check (void) 41{ 42 mpz_class z=42; 43 mpq_class q=33; 44 mpf_class f=18; 45 46 ASSERT_ALWAYS(f_z (z)==0); ASSERT_ALWAYS(f_z (-z)==0); 47 ASSERT_ALWAYS(f_q (z)==1); ASSERT_ALWAYS(f_q (-z)==1); 48 ASSERT_ALWAYS(f_q (q)==1); ASSERT_ALWAYS(f_q (-q)==1); 49 ASSERT_ALWAYS(f_f (z)==2); ASSERT_ALWAYS(f_f (-z)==2); 50 ASSERT_ALWAYS(f_f (q)==2); ASSERT_ALWAYS(f_f (-q)==2); 51 ASSERT_ALWAYS(f_f (f)==2); ASSERT_ALWAYS(f_f (-f)==2); 52 ASSERT_ALWAYS(f_zq (z)==0); 53 ASSERT_ALWAYS(f_zq (q)==1); ASSERT_ALWAYS(f_zq (-q)==1); 54 ASSERT_ALWAYS(f_zf (z)==0); 55 ASSERT_ALWAYS(f_zf (f)==2); ASSERT_ALWAYS(f_zf (-f)==2); 56 ASSERT_ALWAYS(f_qf (q)==1); 57 ASSERT_ALWAYS(f_qf (f)==2); ASSERT_ALWAYS(f_qf (-f)==2); 58 ASSERT_ALWAYS(f_zqf(z)==0); 59 ASSERT_ALWAYS(f_zqf(q)==1); 60 ASSERT_ALWAYS(f_zqf(f)==2); ASSERT_ALWAYS(f_zqf(-f)==2); 61 62 ASSERT_ALWAYS(f_zqf(mpz_class(z))==0); ASSERT_ALWAYS(f_zqf(mpz_class(-z))==0); 63 ASSERT_ALWAYS(f_zqf(mpz_class(q))==0); ASSERT_ALWAYS(f_zqf(mpz_class(-q))==0); 64 ASSERT_ALWAYS(f_zqf(mpz_class(f))==0); ASSERT_ALWAYS(f_zqf(mpz_class(-f))==0); 65 ASSERT_ALWAYS(f_zqf(mpq_class(z))==1); ASSERT_ALWAYS(f_zqf(mpq_class(-z))==1); 66 ASSERT_ALWAYS(f_zqf(mpq_class(q))==1); ASSERT_ALWAYS(f_zqf(mpq_class(-q))==1); 67 ASSERT_ALWAYS(f_zqf(mpq_class(f))==1); ASSERT_ALWAYS(f_zqf(mpq_class(-f))==1); 68 ASSERT_ALWAYS(f_zqf(mpf_class(z))==2); ASSERT_ALWAYS(f_zqf(mpf_class(-z))==2); 69 ASSERT_ALWAYS(f_zqf(mpf_class(q))==2); ASSERT_ALWAYS(f_zqf(mpf_class(-q))==2); 70 ASSERT_ALWAYS(f_zqf(mpf_class(f))==2); ASSERT_ALWAYS(f_zqf(mpf_class(-f))==2); 71} 72 73int 74main (void) 75{ 76 tests_start(); 77 78 check(); 79 80 tests_end(); 81 return 0; 82} 83