t-mix.cc revision 1.1.1.1
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 http://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
27int f_z  (mpz_class){return 0;}
28int f_q  (mpq_class){return 1;}
29int f_f  (mpf_class){return 2;}
30int f_zq (mpz_class){return 0;}
31int f_zq (mpq_class){return 1;}
32int f_zf (mpz_class){return 0;}
33int f_zf (mpf_class){return 2;}
34int f_qf (mpq_class){return 1;}
35int f_qf (mpf_class){return 2;}
36int f_zqf(mpz_class){return 0;}
37int f_zqf(mpq_class){return 1;}
38int f_zqf(mpf_class){return 2;}
39
40void
41check (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
74int
75main (void)
76{
77  tests_start();
78
79  check();
80
81  tests_end();
82  return 0;
83}
84