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