Upload Tizen:Base source
[external/gmp.git] / tests / mpz / t-oddeven.c
1 /* Test mpz_odd_p and mpz_even_p.
2
3 Copyright 2000, 2001 Free Software Foundation, Inc.
4
5 This file is part of the GNU MP Library.
6
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15 License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include "gmp.h"
23 #include "gmp-impl.h"
24 #include "tests.h"
25
26 void
27 check_data (void)
28 {
29   static const struct {
30     const char  *n;
31     int          odd, even;
32   } data[] = {
33     {   "0", 0, 1 },
34     {   "1", 1, 0 },
35     {   "2", 0, 1 },
36     {   "3", 1, 0 },
37     {   "4", 0, 1 },
38
39     {  "-4", 0, 1 },
40     {  "-3", 1, 0 },
41     {  "-2", 0, 1 },
42     {  "-1", 1, 0 },
43
44     {  "0x1000000000000000000000000000000000000000000000000000", 0, 1 },
45     {  "0x1000000000000000000000000000000000000000000000000001", 1, 0 },
46     {  "0x1000000000000000000000000000000000000000000000000002", 0, 1 },
47     {  "0x1000000000000000000000000000000000000000000000000003", 1, 0 },
48
49     { "-0x1000000000000000000000000000000000000000000000000004", 0, 1 },
50     { "-0x1000000000000000000000000000000000000000000000000003", 1, 0 },
51     { "-0x1000000000000000000000000000000000000000000000000002", 0, 1 },
52     { "-0x1000000000000000000000000000000000000000000000000001", 1, 0 },
53   };
54
55   mpz_t  n;
56   int    i;
57
58   mpz_init (n);
59   for (i = 0; i < numberof (data); i++)
60     {
61       mpz_set_str_or_abort (n, data[i].n, 0);
62
63       if ((mpz_odd_p (n) != 0) != data[i].odd)
64         {
65           printf ("mpz_odd_p wrong on data[%d]\n", i);
66           abort();
67         }
68
69       if ((mpz_even_p (n) != 0) != data[i].even)
70         {
71           printf ("mpz_even_p wrong on data[%d]\n", i);
72           abort();
73         }
74     }
75
76   mpz_clear (n);
77 }
78
79 int
80 main (void)
81 {
82   tests_start ();
83
84   check_data ();
85
86   tests_end ();
87   exit (0);
88 }