github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/tests/t-sub.c (about) 1 /* Test sub_ddmmss. 2 3 Copyright 2004 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 23 #include "gmp.h" 24 #include "gmp-impl.h" 25 #include "longlong.h" 26 #include "tests.h" 27 28 29 void 30 check_data (void) 31 { 32 #define M MP_LIMB_T_MAX 33 34 static const struct { 35 mp_limb_t want_dh,want_dl, mh,ml, sh,sl; 36 } data[] = { 37 { 0,0, 0,0, 0,0 }, 38 { 0,0, 0,1, 0,1 }, 39 { 0,0, 1,2, 1,2 }, 40 41 { 0,1, 0,2, 0,1 }, 42 { 0,M, 1,0, 0,1 }, 43 { M,M, 0,0, 0,1 }, 44 45 { M,M, 0,M-1, 0,M }, 46 { 0,0, 0,M-1, 0,M-1 }, 47 { 0,1, 0,M-1, 0,M-2 }, 48 }; 49 int i; 50 mp_limb_t got_dh, got_dl; 51 52 for (i = 0; i < numberof (data); i++) 53 { 54 sub_ddmmss (got_dh,got_dl, data[i].mh,data[i].ml, data[i].sh,data[i].sl); 55 if (got_dh != data[i].want_dh || got_dl != data[i].want_dl) 56 { 57 printf ("check_data wrong at data[%d]\n", i); 58 mp_limb_trace (" mh", data[i].mh); 59 mp_limb_trace (" ml", data[i].ml); 60 mp_limb_trace (" sh", data[i].sh); 61 mp_limb_trace (" sl", data[i].sl); 62 mp_limb_trace (" want dh", data[i].want_dh); 63 mp_limb_trace (" want dl", data[i].want_dl); 64 mp_limb_trace (" got dh ", got_dh); 65 mp_limb_trace (" got dl ", got_dl); 66 abort (); 67 } 68 } 69 } 70 71 void 72 check_random (void) 73 { 74 mp_limb_t want_dh,want_dl, got_dh,got_dl, mh,ml, sh,sl; 75 int i; 76 77 for (i = 0; i < 20; i++) 78 { 79 mh = urandom (); 80 ml = urandom (); 81 sh = urandom (); 82 sl = urandom (); 83 84 refmpn_sub_ddmmss (&want_dh,&want_dl, mh,ml, sh,sl); 85 86 sub_ddmmss (got_dh,got_dl, mh,ml, sh,sl); 87 88 if (got_dh != want_dh || got_dl != want_dl) 89 { 90 printf ("check_data wrong at data[%d]\n", i); 91 mp_limb_trace (" mh", mh); 92 mp_limb_trace (" ml", ml); 93 mp_limb_trace (" sh", sh); 94 mp_limb_trace (" sl", sl); 95 mp_limb_trace (" want dh", want_dh); 96 mp_limb_trace (" want dl", want_dl); 97 mp_limb_trace (" got dh ", got_dh); 98 mp_limb_trace (" got dl ", got_dl); 99 abort (); 100 } 101 } 102 } 103 104 int 105 main (void) 106 { 107 tests_start (); 108 mp_trace_base = -16; 109 110 check_data (); 111 check_random (); 112 113 tests_end (); 114 exit (0); 115 }