/* * test_2_arg - Test a function with two arguments */ static int test_2_arg(funct_t f, funct_t ft, int arg1, int arg2, char *name) { funct2_t f2 = (funct2_t) f; funct2_t f2t = (funct2_t) ft; int r = f2(arg1, arg2); int rt = f2t(arg1, arg2); int error = (r != rt); if (error && !grade) printf("ERROR: Test %s(%d[0x%x],%d[0x%x]) failed...\n...Gives %d[0x%x]. Should be %d[0x%x]\n", name, arg1, arg1, arg2, arg2, r, r, rt, rt); return error; }
int main(){ int a[20]; int b[20]; int i,j,n; for(i=0; i<10; i++){ n=rand()%20+1; for(j=0;j<n;j++){ a[j]=rand()%10; b[j]=rand()%10; } int stud = f2(n, a, b); int teac = f2t(n, a, b); if( stud != teac ){ printf("a[0]=%d, b[0]=%d\n", a[0], b[0]); printf("Hiba: stud=%d, teac=%d\n",stud,teac); }else{ printf("OK\n"); } } }