partition-test.c:


/* partition-test.c test routines for the matrix partitioning package.
 * © Copyright 1999 by John Halleck
 * All rights reserved.
 */
/* Version of September 6th, 1999 */

#include <stdio.h>
  /* Standard IO */

#include "errors.h"
  /* Common error codes */
#include "mat.h"
  /* Matrix specific stuff */

#include "matdebug.h"
  /* Standard matrix debugging routines. */

#include "partition.h"
  /* The routines we'll test */

#include "reportframe.h"
  /* Standard test reports */


double tembed[6][7], textract[3][2];
double rembed[6][7], rextract[3][2];

/* ========================== MAIN ========================================== */

int main (argc, argv)
  int argc; char argv[];
{
  error problem   = NoError;

  int i,j; /* Loop indices */

  inittests("partition");

/* ======================== Routines to load constants ====================== */

newsection ("Copy routines");

/* ===================== Copy routines ====================================== */

/* --- matrix embed ---- */
/* Matrix embedding test */
   newtest ("matembed");
   if ( ERRsize != (problem = matembed (0, 7, tembed, 3, 2, textract, 0, 0))
     || ERRsize != (problem = matembed (6, 0, tembed, 3, 2, textract, 0, 0))
     || ERRsize != (problem = matembed (6, 7, tembed, 0, 2, textract, 0, 0))
     || ERRsize != (problem = matembed (6, 7, tembed, 3, 0, textract, 0, 0))
      ) goterrorstat ("Bad size accepted?", problem);
   if ( ERRnil != (problem = matembed (6, 7,      0, 3, 2, textract, 0, 0))
     || ERRnil != (problem = matembed (6, 7, tembed, 3, 2,        0, 0, 0))
      ) goterrorstat ("Nil pointer accepted?", problem);
   if ( ERRsame != (problem = matembed (6, 7, tembed, 3, 2,   tembed, 0, 0)))
       goterrorstat ("Aliased arrays accepted.", problem);
   if ( ERRrange != (problem = matembed (6, 7, tembed, 3, 2, textract, -1,  0))
     || ERRrange != (problem = matembed (6, 7, tembed, 3, 2, textract,  0, -1))
     || ERRrange != (problem = matembed (6, 7, tembed, 3, 2, textract,  6,  0))
     || ERRrange != (problem = matembed (6, 7, tembed, 3, 2, textract,  0,  7))
      ) goterrorstat ("Out of array placement accepted", problem);
   if ( ERRrange !=
         (problem = matembed (6, 7, tembed, 3, 2, textract,  6-3+1,      0))
     || ERRrange != 
         (problem = matembed (6, 7, tembed, 3, 2, textract,      0,  7-2+1))
      ) goterrorstat ("Out of range placement accepted", problem);


   for (i=0;i<6;i++) for (j=0;j<7;j++) {
     rembed[i][j] = 100 + 10*i + j;
     tembed[i][j] = 100 + 10*i + j;
   }
   for (i=0;i<3;i++) for (j=0;j<2;j++) {
     textract[i][j] = 200+10*i+j;
     rembed  [i+2][j+1] = 200+10*i+j; 
   }
   if ((problem = matembed (6, 7, tembed, 3, 2, textract, 2, 1)))
      goterrorstat ("Rejected valid call", problem);

   if ((problem = matiseq (6,7, tembed, rembed))) {
      if (ERRfalse == problem) problem = NoError;
      goterrorstat ("Wrong result?", problem);
      matprint ("Got", 6, 7, tembed);
      matprint ("should have been", 6, 7, rembed);
      matprint ("Extracting from", 3, 2, textract);
   }

   for (i=0;i<6;i++) for (j=0;j<7;j++) {
     rembed[i][j] = 100 + 10*i + j;
     tembed[i][j] = 200 + 10*i + j;
   }

   if ((problem = matembed (6, 7, tembed, 6, 7, rembed, 0, 0)))
      goterrorstat ("Rejected valid identity call", problem);

   if ((problem = matiseq (6,7, tembed, rembed))) {
      if (ERRfalse == problem) problem = NoError;
      goterrorstat ("Wrong result in identity embed?", problem);
      matprint ("Got", 6, 7, tembed);
      matprint ("should have been", 6, 7, rembed);
   }

   endtest();

/* --- matrix extract -- */
/* Matrix extraction test */
   newtest ("matextract");
   if ( ERRsize != (problem = matextract (0, 2, tembed, 6, 7, textract, 0, 0))
     || ERRsize != (problem = matextract (3, 0, tembed, 6, 7, textract, 0, 0))
     || ERRsize != (problem = matextract (3, 2, tembed, 0, 7, textract, 0, 0))
     || ERRsize != (problem = matextract (3, 2, tembed, 6, 0, textract, 0, 0))
      ) goterrorstat ("Bad size accepted?", problem);
   if ( ERRnil != (problem = matextract (3, 2,      0, 6, 7, textract, 0, 0))
     || ERRnil != (problem = matextract (3, 2, tembed, 6, 7,        0, 0, 0))
      ) goterrorstat ("Nil pointer accepted?", problem);
   if ( ERRsame != (problem = matextract (3, 2, tembed, 6, 7,   tembed, 0, 0)))
       goterrorstat ("Aliased arrays accepted.", problem);
   if ( ERRrange !=
                   (problem = matextract (3, 2, tembed, 6, 7, textract, -1,  0))
     || ERRrange !=
                   (problem = matextract (3, 2, tembed, 6, 7, textract,  0, -1))
     || ERRrange !=
                   (problem = matextract (3, 2, tembed, 6, 7, textract,  6,  0))
     || ERRrange !=
                   (problem = matextract (3, 2, tembed, 6, 7, textract,  0,  7))
       ) goterrorstat ("Out of array placement accepted", problem);
   if ( ERRrange !=
             (problem = matextract (3, 2, tembed, 6, 7, textract, 6-3+1,     0))
     || ERRrange !=
             (problem = matextract (3, 2, tembed, 6, 7, textract,     0, 7-2+1))
       ) goterrorstat ("Out of range placement accepted", problem);


   for (i=0;i<6;i++) for (j=0;j<7;j++) {
     tembed[i][j] = 100 + 10*i + j;
   }
   for (i=0;i<3;i++) for (j=0;j<2;j++) {
     textract[i][j] = 900 + 10*i     +j;
     rextract[i][j] = 100 + 10*(i+2) +j+1;
   }

   if ((problem = matextract (3, 2, textract, 6, 7, tembed, 2, 1)))
      goterrorstat ("Rejected valid call", problem);

   if ((problem = matiseq (3,2, textract, rextract))) {
      if (ERRfalse == problem) problem = NoError;
      goterrorstat ("Wrong result?", problem);
      matprint ("Got", 3, 2, textract);
      matprint ("should have been", 3, 2, rextract);
      printf ("Extracting from  2, 1 of matrix:\n"); 
      matprint ("From the embedding matrix:", 6, 7, tembed);
   }

   for (i=0;i<3;i++) for (j=0;j<2;j++) {
     rextract[i][j] = 100 + 10*i + j;
     textract[i][j] = 200 + 10*i + j;
   }
   if ((problem = matembed (3, 2, textract, 3, 2, rextract, 0, 0)))
      goterrorstat ("Rejected valid identity call", problem);

   if ((problem = matiseq (3,2, textract, rextract))) {
      if (ERRfalse == problem) problem = NoError;
      goterrorstat ("Wrong result in identity extract?", problem);
      matprint ("Got", 3, 2, textract);
      matprint ("should have been", 3, 2, rextract);
   }

   endtest();

/* ===================== End of copy tests ================================== */

endsection();

newsection ("Addition");
newtest("partadd");
   if ( ERRsize != (problem = partadd (0, 7, tembed, 3, 2, textract, 0, 0))
     || ERRsize != (problem = partadd (6, 0, tembed, 3, 2, textract, 0, 0))
     || ERRsize != (problem = partadd (6, 7, tembed, 0, 2, textract, 0, 0))
     || ERRsize != (problem = partadd (6, 7, tembed, 3, 0, textract, 0, 0))
      ) goterrorstat ("Bad size accepted?", problem);
   if ( ERRnil != (problem = partadd (6, 7,      0, 3, 2, textract, 0, 0))
     || ERRnil != (problem = partadd (6, 7, tembed, 3, 2,        0, 0, 0))
      ) goterrorstat ("Nil pointer accepted?", problem);
   if ( ERRsame != (problem = partadd (6, 7, tembed, 3, 2,   tembed, 0, 0)))
       goterrorstat ("Aliased arrays accepted.", problem);
   if ( ERRrange != (problem = partadd (6, 7, tembed, 3, 2, textract, -1,  0))
     || ERRrange != (problem = partadd (6, 7, tembed, 3, 2, textract,  0, -1))
     || ERRrange != (problem = partadd (6, 7, tembed, 3, 2, textract,  6,  0))
     || ERRrange != (problem = partadd (6, 7, tembed, 3, 2, textract,  0,  7))
      ) goterrorstat ("Out of array placement accepted", problem);
   if ( ERRrange !=
         (problem = partadd (6, 7, tembed, 3, 2, textract,  6-3+1,      0))
     || ERRrange !=
         (problem = partadd (6, 7, tembed, 3, 2, textract,      0,  7-2+1))
      ) goterrorstat ("Out of range placement accepted", problem);


   for (i=0;i<6;i++) for (j=0;j<7;j++) {
     rembed[i][j] = 100 + 10*i + j;
     tembed[i][j] = 100 + 10*i + j;
   }
   for (i=0;i<3;i++) for (j=0;j<2;j++) {
     textract[i][j] = 200+10*i+j;
     rembed  [i+2][j+1] += 200+10*i+j;
   }
   if ((problem = partadd (6, 7, tembed, 3, 2, textract, 2, 1)))
      goterrorstat ("Rejected valid call", problem);

   if ((problem = matiseq (6,7, tembed, rembed))) {
      if (ERRfalse == problem) problem = NoError;
      goterrorstat ("Wrong result?", problem);
      matprint ("Got", 6, 7, tembed);
      matprint ("should have been", 6, 7, rembed);
      matprint ("Extracting from", 3, 2, textract);
   }

endtest();
newtest("partsub");
   if ( ERRsize != (problem = partsub (0, 7, tembed, 3, 2, textract, 0, 0))
     || ERRsize != (problem = partsub (6, 0, tembed, 3, 2, textract, 0, 0))
     || ERRsize != (problem = partsub (6, 7, tembed, 0, 2, textract, 0, 0))
     || ERRsize != (problem = partsub (6, 7, tembed, 3, 0, textract, 0, 0))
      ) goterrorstat ("Bad size accepted?", problem);
   if ( ERRnil != (problem = partsub (6, 7,      0, 3, 2, textract, 0, 0))
     || ERRnil != (problem = partsub (6, 7, tembed, 3, 2,        0, 0, 0))
      ) goterrorstat ("Nil pointer accepted?", problem);
   if ( ERRsame != (problem = partsub (6, 7, tembed, 3, 2,   tembed, 0, 0)))
       goterrorstat ("Aliased arrays accepted.", problem);
   if ( ERRrange != (problem = partsub (6, 7, tembed, 3, 2, textract, -1,  0))
     || ERRrange != (problem = partsub (6, 7, tembed, 3, 2, textract,  0, -1))
     || ERRrange != (problem = partsub (6, 7, tembed, 3, 2, textract,  6,  0))
     || ERRrange != (problem = partsub (6, 7, tembed, 3, 2, textract,  0,  7))
      ) goterrorstat ("Out of array placement accepted", problem);
   if ( ERRrange !=
         (problem = partsub (6, 7, tembed, 3, 2, textract,  6-3+1,      0))
     || ERRrange !=
         (problem = partsub (6, 7, tembed, 3, 2, textract,      0,  7-2+1))
      ) goterrorstat ("Out of range placement accepted", problem);


   for (i=0;i<6;i++) for (j=0;j<7;j++) {
     rembed[i][j] = 100 + 10*i + j;
     tembed[i][j] = 100 + 10*i + j;
   }
   for (i=0;i<3;i++) for (j=0;j<2;j++) {
     textract[i][j] = 200+10*i+j;
     rembed  [i+2][j+1] -= 200+10*i+j;
   }
   if ((problem = partsub (6, 7, tembed, 3, 2, textract, 2, 1)))
      goterrorstat ("Rejected valid call", problem);

   if ((problem = matiseq (6,7, tembed, rembed))) {
      if (ERRfalse == problem) problem = NoError;
      goterrorstat ("Wrong result?", problem);
      matprint ("Got", 6, 7, tembed);
      matprint ("should have been", 6, 7, rembed);
      matprint ("Extracting from", 3, 2, textract);
   }

endtest();
endsection ();

finalizetests();
return progerrors;
}

Go to ...


This page is http://www.cc.utah.edu/~nahaj/cave/survey/code/c/partition-test.c.html
© Copyright 2000 by John Halleck, All Rights Reserved.
This snapshot was last modified on August 23rd, 2000
And the underlying file was last modified on May 11th, 2000