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