github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/tests/mpz/t-oddeven.c (about)

     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.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  }