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 2.1 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; see the file COPYING.LIB. If not, write to |
---|
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
---|
20 | MA 02111-1307, USA. */ |
---|
21 | |
---|
22 | #include <stdio.h> |
---|
23 | #include <stdlib.h> |
---|
24 | #include "gmp.h" |
---|
25 | #include "gmp-impl.h" |
---|
26 | #include "tests.h" |
---|
27 | |
---|
28 | void |
---|
29 | check_data (void) |
---|
30 | { |
---|
31 | static const struct { |
---|
32 | const char *n; |
---|
33 | int odd, even; |
---|
34 | } data[] = { |
---|
35 | { "0", 0, 1 }, |
---|
36 | { "1", 1, 0 }, |
---|
37 | { "2", 0, 1 }, |
---|
38 | { "3", 1, 0 }, |
---|
39 | { "4", 0, 1 }, |
---|
40 | |
---|
41 | { "-4", 0, 1 }, |
---|
42 | { "-3", 1, 0 }, |
---|
43 | { "-2", 0, 1 }, |
---|
44 | { "-1", 1, 0 }, |
---|
45 | |
---|
46 | { "0x1000000000000000000000000000000000000000000000000000", 0, 1 }, |
---|
47 | { "0x1000000000000000000000000000000000000000000000000001", 1, 0 }, |
---|
48 | { "0x1000000000000000000000000000000000000000000000000002", 0, 1 }, |
---|
49 | { "0x1000000000000000000000000000000000000000000000000003", 1, 0 }, |
---|
50 | |
---|
51 | { "-0x1000000000000000000000000000000000000000000000000004", 0, 1 }, |
---|
52 | { "-0x1000000000000000000000000000000000000000000000000003", 1, 0 }, |
---|
53 | { "-0x1000000000000000000000000000000000000000000000000002", 0, 1 }, |
---|
54 | { "-0x1000000000000000000000000000000000000000000000000001", 1, 0 }, |
---|
55 | }; |
---|
56 | |
---|
57 | mpz_t n; |
---|
58 | int i; |
---|
59 | |
---|
60 | mpz_init (n); |
---|
61 | for (i = 0; i < numberof (data); i++) |
---|
62 | { |
---|
63 | mpz_set_str_or_abort (n, data[i].n, 0); |
---|
64 | |
---|
65 | if ((mpz_odd_p (n) != 0) != data[i].odd) |
---|
66 | { |
---|
67 | printf ("mpz_odd_p wrong on data[%d]\n", i); |
---|
68 | abort(); |
---|
69 | } |
---|
70 | |
---|
71 | if ((mpz_even_p (n) != 0) != data[i].even) |
---|
72 | { |
---|
73 | printf ("mpz_even_p wrong on data[%d]\n", i); |
---|
74 | abort(); |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | mpz_clear (n); |
---|
79 | } |
---|
80 | |
---|
81 | int |
---|
82 | main (void) |
---|
83 | { |
---|
84 | tests_start (); |
---|
85 | |
---|
86 | check_data (); |
---|
87 | |
---|
88 | tests_end (); |
---|
89 | exit (0); |
---|
90 | } |
---|