t-sub.c revision 1.1.1.1
1/* Test sub_ddmmss. 2 3Copyright 2004 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 3 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. If not, see http://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 29void 30check_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 71void 72check_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 104int 105main (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} 116