source: trunk/third/gmp/tests/mpz/t-oddeven.c @ 18191

Revision 18191, 2.4 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18190, which included commits to RCS files with non-trunk default branches.
Line 
1/* Test mpz_odd_p and mpz_even_p.
2
3Copyright 2000, 2001 Free Software Foundation, Inc.
4
5This file is part of the GNU MP Library.
6
7The GNU MP Library is free software; you can redistribute it and/or modify
8it under the terms of the GNU Lesser General Public License as published by
9the Free Software Foundation; either version 2.1 of the License, or (at your
10option) any later version.
11
12The GNU MP Library is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15License for more details.
16
17You should have received a copy of the GNU Lesser General Public License
18along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20MA 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
28void
29check_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
81int
82main (void)
83{
84  tests_start ();
85
86  check_data ();
87
88  tests_end ();
89  exit (0);
90}
Note: See TracBrowser for help on using the repository browser.