/* survey3d-test.c - Test the survey3d package. * (C) Copyright 1999 by John Halleck * All Rights Reserved */ /* Version of May 10th, 2000 */ #include /* We print messages. */ #include "errors.h" /* We deal with standard error codes. */ #include "vec.h" /* We will do vector operations. */ #include "vecdebug.h" /* and printing. */ #include "mat.h" /* We will test against the matrix reference library */ #include "matdebug.h" /* And use it's matrix print routines. */ #include "reportframe.h" /* Standard error test reporting. */ #include "survey3d.h" /* And we need the package we are testing. */ #include "survey3debug.h" /* And defines of printing and support routines. */ error problem; /* Return problem from package */ double temp; covariance example, teste; weight examplew, testw; coordinate testcoord; double testmat[3][3]; coordinate a, b, result; weight wa, wb, wc; covariance ca, cb, cc; int main () { int i; /* Loop index */ int good; /* status */ inittests ("Survey 3d"); /* ------------------ Load tests ----------------------------------------- */ newsection ("Load tests"); example[0] = 11.0; example [1] = 12.0; example[2] = 13.0; example [3] = 22.0; example[4] = 23.0; example[5] = 33.0; newtest ("loadcovr"); if (ERRnil != (problem = loadcvr(0, 11.0, 12.0, 13.0, 22.0, 23.0, 33.0)) ) goterrorstat ("nil matrix accepted", problem); if ((problem = loadcvr (teste, 11.0, 12.0, 13.0, 22.0, 23.0, 33.0))) goterrorstat ("valid call rejected?", problem); if ((problem = veciseq (6, example, teste))) { if (ERRfalse == problem) problem = NoError; goterrorstat ("wrong result?", problem); vecprint ("Canned:", 6, example); vecprint ("computed:", 6, teste); } endtest (); examplew[0] = 11.0; examplew [1] = 12.0; examplew[2] = 13.0; examplew [3] = 22.0; examplew[4] = 23.0; examplew[5] = 33.0; newtest ("loadwht"); if (ERRnil != (problem = loadwht (0, 11.0, 12.0, 13.0, 22.0, 23.0, 33.0)) ) goterrorstat ("nil matrix accepted", problem); if ((problem = loadwht (testw, 11.0, 12.0, 13.0, 22.0, 23.0, 33.0))) goterrorstat ("valid call rejected?", problem); if ((problem = veciseq (6, examplew, testw))) { if (ERRfalse == problem) problem = NoError; goterrorstat ("wrong result?", problem); vecprint ("Canned:", 6, examplew); vecprint ("computed:", 6, testw); } endtest (); endsection(); /* ---------- Zero tests ---------------------------------------------------- */ newtest ("zerocoord"); if (ERRnil != (problem = zerocoord (0)) ) goterrorstat ("Nil matrix accepted", problem); for (i=0;i<3;i++) testcoord[i] = 99.0; if ((problem = zerocoord(testcoord))) goterrorstat ("Valid call rejected", problem); if ( testcoord[0] != 0.0 || testcoord[1] != 0.0 || testcoord[2] != 0.0 ) { goterror ("Wrong answer"); vecprint ("Got: ", 3, testcoord); } endtest (); /* ---------- identity tests ------------------------------------------------ */ newsection ("Identity"); newtest("cvrident"); if (ERRnil != (problem = cvrident(0)) ) goterrorstat ("Nil vector accepted?", problem); if ((problem = cvrident (teste))) goterrorstat ("Valid call rejected", problem); if ( teste[0] != 1.0 || teste[1] != 0.0 || teste[2] != 0.0 || teste[3] != 1.0 || teste[4] != 0.0 || teste[5] != 1.0 ) { goterror ("Wrong answer"); vecprint ("got:", 6, teste); } endtest(); newtest("whtident"); if (ERRnil != (problem = whtident(0)) ) goterrorstat ("Nil vector accepted?", problem); if ((problem = whtident (teste))) goterrorstat ("Valid call rejected", problem); if ( teste[0] != 1.0 || teste[1] != 0.0 || teste[2] != 0.0 || teste[3] != 1.0 || teste[4] != 0.0 || teste[5] != 1.0 ) { goterror ("Wrong answer"); vecprint ("got:", 6, teste); } endtest(); endsection(); /* -------------------------------------------------------------------------- */ newsection ("Conversions to regular matrices"); newtest("matfmwht"); if ((problem = loadwht (teste, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0))) goterrorstat ("loadwht failed?", problem); if ( ERRnil != (problem = matfmwht(testmat, 0)) || ERRnil != (problem = matfmwht( 0, teste)) ) goterrorstat ("Accepted nil argument", problem); if ((problem = matfmwht(testmat, teste))) goterrorstat ("Failed valid call", problem); if ( testmat[0][0] != 1.0 || testmat[0][1] != 2.0 || testmat[0][2] != 3.0 || testmat[1][0] != 2.0 || testmat[1][1] != 4.0 || testmat[1][2] != 5.0 || testmat[2][0] != 3.0 || testmat[2][1] != 5.0 || testmat[2][2] != 6.0 ) { goterror ("Wrong answer"); matprint ("got:",3,3,testmat); remark ("Should be 1 2 3"); remark (" 2 4 5"); remark (" 3 5 6"); } endtest(); newtest("matfmcvr"); if ((problem = loadcvr (teste, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0))) goterrorstat ("loadwht failed?", problem); if ( ERRnil != (problem = matfmcvr(testmat, 0)) || ERRnil != (problem = matfmcvr( 0, teste)) ) goterrorstat ("Accepted nil argument", problem); if ((problem = matfmcvr(testmat, teste))) goterrorstat ("Failed valid call", problem); if ( testmat[0][0] != 1.0 || testmat[0][1] != 2.0 || testmat[0][2] != 3.0 || testmat[1][0] != 2.0 || testmat[1][1] != 4.0 || testmat[1][2] != 5.0 || testmat[2][0] != 3.0 || testmat[2][1] != 5.0 || testmat[2][2] != 6.0 ) { goterror ("Wrong answer"); matprint ("got:",3,3,testmat); remark ("Should be 1 2 3"); remark (" 2 4 5"); remark (" 3 5 6"); } endtest(); endsection(); newsection ("addition"); newtest("addcoord"); if ( ERRnil != (problem = addcoord ( 0, a, b)) || ERRnil != (problem = addcoord (result, 0, b)) || ERRnil != (problem = addcoord (result, a, 0)) ) goterrorstat ("Accepted nil argument", problem); if ((problem = zerocoord (result))) goterrorstat ("Couldn't zero result", problem); a[0] = 10.0; a[1] = 11.0; a[2] = 12.0; b[0] = 100.0; b[1] = 200.0; b[2] = 300.0; if ((problem = addcoord(result, a, b))) goterrorstat ("Failed valid call", problem); if (result[0] != 110.0 || result[1] != 211.0 || result[2] != 312.0) { goterror ("Wrong answer"); vecprint ("Got", 3, result); remark ("Should have been: [ 110.0 211.0 312.0 ]"); } endtest(); newtest("subcoord"); if ( ERRnil != (problem = subcoord ( 0, b, a)) || ERRnil != (problem = subcoord (result, 0, a)) || ERRnil != (problem = subcoord (result, b, 0)) ) goterrorstat ("Accepted nil argument", problem); if ((problem = zerocoord (result))) goterrorstat ("Couldn't zero result", problem); a[0] = 10.0; a[1] = 11.0; a[2] = 12.0; b[0] = 110.0; b[1] = 211.0; b[2] = 312.0; if ((problem = subcoord(result, b, a))) goterrorstat ("Failed valid call", problem); if (result[0] != 100.0 || result[1] != 200.0 || result[2] != 300.0) { goterror ("Wrong answer"); vecprint ("Got", 3, result); remark ("Should have been: [ 100.0 200.0 300.0 ]"); } endtest(); newtest("addwht"); if ( ERRnil != (problem = addwht ( 0, wa, wb)) || ERRnil != (problem = addwht (wc, 0, wb)) || ERRnil != (problem = addwht (wc, wa, 0)) ) goterrorstat ("Accepted nil argument", problem); if ((problem = zerocoord (result))) goterrorstat ("Couldn't zero result", problem); wa[0] = 3.0; wa[1] = 2.0; wa[2] = 1.0; wa[3] = 5.0; wa[4] = 4.0; wa[5] = 6.0; wb[0] = 30.0; wb[1] = 20.0; wb[2] = 10.0; wb[3] = 50.0; wb[4] = 40.0; wb[5] = 60.0; if ((problem = addwht(wc, wa, wb))) goterrorstat ("Failed valid call", problem); if (wc[0] != 33.0 || wc[1] != 22.0 || wc[2] != 11.0 || wc[3] != 55.0 || wc[4] != 44.0 || wc[5] != 66.0 ) { goterror ("Wrong answer"); vecprint ("Got", 3, wc); remark ("Should have been: [ 33 22 11 55 44 66 ]"); } endtest(); newtest("addcvr"); if ( ERRnil != (problem = addcvr ( 0, ca, cb)) || ERRnil != (problem = addcvr (cc, 0, cb)) || ERRnil != (problem = addcvr (cc, ca, 0)) ) goterrorstat ("Accepted nil argument", problem); if ((problem = zerocoord (result))) goterrorstat ("Couldn't zero result", problem); ca[0] = 3.0; ca[1] = 2.0; ca[2] = 1.0; ca[3] = 5.0; ca[4] = 4.0; ca[5] = 6.0; cb[0] = 30.0; cb[1] = 20.0; cb[2] = 10.0; cb[3] = 50.0; cb[4] = 40.0; cb[5] = 60.0; if ((problem = addcvr(cc, ca, cb))) goterrorstat ("Failed valid call", problem); if (cc[0] != 33.0 || cc[1] != 22.0 || cc[2] != 11.0 || cc[3] != 55.0 || cc[4] != 44.0 || cc[5] != 66.0 ) { goterror ("Wrong answer"); vecprint ("Got", 3, cc); remark ("Should have been: [ 33 22 11 55 44 66 ]"); } endtest(); endsection (); newsection ("multiplication"); newtest("wxcmult"); b[0] = 1.0; b[1] = 2.0; b[2] = 3.0; wa[0] = 1.0; wa[1] = 2.0; wa[2] = 3.0; wa[3] = 4.0; wa[4] = 5.0; wa[6] = 6.0; if ( ERRnil != (problem = wxcmult ( 0, wa, b)) || ERRnil != (problem = wxcmult (result, 0, b)) || ERRnil != (problem = wxcmult (result, wa, 0)) ) goterrorstat ("Accepted nil argument", problem); if ((problem = wxcmult(result, wa, b))) goterrorstat ("rejected valid call", problem); if (result[0] != 14.0 || result[1] != 25.0 || result[2] != 31.0 ) { goterror ("Wrong answer"); coordprint ("Got", result); remark ("Should have been: [ 14 25 31 ]"); } endtest(); endsection(); newsection ("inverses"); newtest("cvrinv"); /* This is not the best of tests... but at least it is something. */ if ( ERRnil != (problem = cvrinv (0, ca)) || ERRnil != (problem = cvrinv (ca, 0)) ) goterrorstat ("Accepted nil argument.", problem); for (i=0; i<6; i++) ca[i] = 0.0; if (ERRnumeric != (problem = cvrinv(cb, ca))) goterrorstat ("Accepted singular matrix", problem); /* This matrix is not that good a test, since the underlying * routine could confuse some of the off diagonal elements * without it being noticed. But I haven't come up with an * example that would have all elements different, with a * known solution, that computer arithmetic would get exact, * (I.E. that has a determinant that is a power of two.) * and that was positive definite. I'm open for suggestions. */ ca[0] = 3.0; ca[1] = -1.0; ca[2] = -1.0; ca[3] = 3.0; ca[4] = -1.0; ca[5] = 3.0; cc[0] = 2.0/4.0; cc[1] = 1.0/4.0; cc[2] = 1.0/4.0; cc[3] = 2.0/4.0; cc[4] = 1.0/4.0; cc[5] = 2.0/4.0; if ((problem = cvrinv (cb, ca))) goterrorstat ("Rejected valid call", problem); good = 1; for (i=0; i<6; i++) if (cb[i] != cc[i]) good = 0; if (!good) { goterror ("Wrong answer"); covarprint ("Got", cb); covarprint ("Should have been", cc); } endtest(); newtest("whtinv"); if ( ERRnil != (problem = whtinv (0, wa)) || ERRnil != (problem = whtinv (wa, 0)) ) goterrorstat ("Accepted nil argument.", problem); for (i=0; i<6; i++) wa[i] = 0.0; if (ERRnumeric != (problem = whtinv(wb, wa))) goterrorstat ("Accepted singular matrix", problem); wa[0] = 3.0; wa[1] = -1.0; wa[2] = -1.0; wa[3] = 3.0; wa[4] = -1.0; wa[5] = 3.0; wc[0] = 2.0/4.0; wc[1] = 1.0/4.0; wc[2] = 1.0/4.0; wc[3] = 2.0/4.0; wc[4] = 1.0/4.0; wc[5] = 2.0/4.0; if ((problem = whtinv (wb, wa))) goterrorstat ("Rejected valid call", problem); good = 1; for (i=0; i<6; i++) if (wb[i] != wc[i]) good = 0; if (!good) { goterror ("Wrong answer"); weightprint ("Got", wb); weightprint ("Should have been", wc); } endtest(); endsection (); newsection ("weight and covariance conversion"); newtest("wht2cvr"); if ( ERRnil != (problem = wht2cvr (0, wa)) || ERRnil != (problem = wht2cvr (wa, 0)) ) goterrorstat ("Accepted nil argument.", problem); for (i=0; i<6; i++) wa[i] = 0.0; if (ERRnumeric != (problem = wht2cvr(cb, wa))) goterrorstat ("Accepted singular matrix", problem); wa[0] = 3.0; wa[1] = -1.0; wa[2] = -1.0; wa[3] = 3.0; wa[4] = -1.0; wa[5] = 3.0; cc[0] = 2.0/4.0; cc[1] = 1.0/4.0; cc[2] = 1.0/4.0; cc[3] = 2.0/4.0; cc[4] = 1.0/4.0; cc[5] = 2.0/4.0; if ((problem = wht2cvr (wb, wa))) goterrorstat ("Rejected valid call", problem); good = 1; for (i=0; i<6; i++) if (cb[i] != cc[i]) good = 0; if (!good) { goterror ("Wrong answer"); covarprint ("Got", cb); covarprint ("Should have been", cc); } endtest(); newtest("cvr2wht"); if ( ERRnil != (problem = cvr2wht (0, ca)) || ERRnil != (problem = cvr2wht (wb, 0)) ) goterrorstat ("Accepted nil argument.", problem); for (i=0; i<6; i++) ca[i] = 0.0; if (ERRnumeric != (problem = cvr2wht(wb, ca))) goterrorstat ("Accepted singular matrix", problem); ca[0] = 3.0; ca[1] = -1.0; ca[2] = -1.0; ca[3] = 3.0; ca[4] = -1.0; ca[5] = 3.0; wc[0] = 2.0/4.0; wc[1] = 1.0/4.0; wc[2] = 1.0/4.0; wc[3] = 2.0/4.0; wc[4] = 1.0/4.0; wc[5] = 2.0/4.0; if ((problem = cvr2wht (wb, wa))) goterrorstat ("Rejected valid call", problem); good = 1; for (i=0; i<6; i++) if (wb[i] != wc[i]) good = 0; if (!good) { goterror ("Wrong answer"); weightprint ("Got", wb); weightprint ("Should have been", wc); } endtest(); endsection(); newsection ("scaling"); newtest("sclcvr"); ca[0] = 11.0; ca[1] = 12.0; ca[2] = 13.0; ca[3] = 22.0; ca[4] = 23.0; ca[5] = 33.0; cb[0] = 22.; cb[1] = 24.0; cb[2] = 26.0; cb[3] = 44.0; cb[4] = 46.0; cb[5] = 66.0; if ( ERRnil != (problem = sclcvr( 0, ca, 2.0)) || ERRnil != (problem = sclcvr(cc, 0, 2.0)) ) goterrorstat ("Accepted nil argument", problem); if (ERRmeaning != (problem = sclcvr(cc, ca, 0.0))) goterrorstat ("Accepted unreasonable scaling factor", problem); if ((problem = sclcvr (cc, ca, 2.0))) goterrorstat ("rejected valid call", problem); good = 1; for (i=0; i<6; i++) if (cc[i] != cb[i]) good = 0; if (!good) { goterror ("Wrong answer"); covarprint ("Got", cc); covarprint ("Should have been", cb); } endtest(); newtest("sclwht"); wa[0] = 11.0; wa[1] = 12.0; wa[2] = 13.0; wa[3] = 22.0; wa[4] = 23.0; wa[5] = 33.0; wb[0] = 22.; wb[1] = 24.0; wb[2] = 26.0; wb[3] = 44.0; wb[4] = 46.0; wb[5] = 66.0; if ( ERRnil != (problem = sclwht( 0, wa, 2.0)) || ERRnil != (problem = sclwht(wc, 0, 2.0)) ) goterrorstat ("Accepted nil argument", problem); if (ERRmeaning != (problem = sclwht(wc, wa, 0.0))) goterrorstat ("Accepted unreasonable scaling factor", problem); if ((problem = sclwht (wc, wa, 2.0))) goterrorstat ("rejected valid call", problem); good = 1; for (i=0; i<6; i++) if (wc[i] != wb[i]) good = 0; if (!good) { goterror ("Wrong answer"); weightprint ("Got", cc); weightprint ("Should have been", cb); } endtest(); endsection(); newsection ("Magnitudes"); newtest("detcvr"); loadcvr (ca, 1.0, 0.0, 0.0, 2.0, 0.0, 3.0); if (ERRnil != (problem = detcvr (0, ca))) goterrorstat ("Failed to notice nil result pointer", problem); if (ERRnil != (problem = detcvr (&temp, 0))) goterrorstat ("Failed to notice nil variance pointer", problem); if ((problem = detcvr (&temp, ca))) goterrorstat ("Rejected valid call", problem); if (temp != 6.0) { goterrorstat ("Got wrong answer", problem); printf ("Should have been 6.0, was %f\n", temp); } endtest(); newtest("detwht"); loadwht (wa, 1.0, 0.0, 0.0, 2.0, 0.0, 3.0); if (ERRnil != (problem = detwht (0, wa))) goterrorstat ("Failed to notice nil result pointer", problem); if (ERRnil != (problem = detwht (&temp, 0))) goterrorstat ("Failed to notice nil variance pointer", problem); if ((problem = detwht (&temp, wa))) goterrorstat ("Rejected valid call", problem); if (temp != 6.0) { goterrorstat ("Got wrong answer", problem); printf ("Should have been 6.0, was %f\n", temp); } endtest(); endsection(); finalizetests(); return progerrors; }