test-bin/test-sparray-main.cxx

00001 // This program is free software; you can redistribute it and/or modify
00002 // it under the terms of the GNU General Public License as published by
00003 // the Free Software Foundation; either version 2 of the License, or
00004 // (at your option) any later version.
00005 // 
00006 // This program is distributed in the hope that it will be useful,
00007 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00008 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00009 // GNU Library General Public License for more details.
00010 // 
00011 // You should have received a copy of the GNU General Public License
00012 // along with this program; if not, write to the Free Software
00013 // Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
00014 #include <stdlib.h>
00015 #include <stdio.h>
00016 #include "sparse-array.hpp"
00017 #include "sparse-array-node.hpp"
00018 #include "dice.hpp"
00019 
00020 typedef struct coords {
00021         int row;
00022         int column;
00023 } coords;
00024 
00025  int main(int argc,char** argv){
00026         coords  testCoordinates[25];
00027         sparseArray* testArray = new sparseArray();
00028          
00029         int     ix;
00030         FILE *f1 = fopen("result1.txt","w");
00031         FILE *f2 = fopen("result2.txt","w");
00032         FILE *f3 = fopen("result3.txt","w");
00033         for(ix=0;ix<25;ix++){
00034                 testCoordinates[ix].row = randxInRange(1,100);
00035                 testCoordinates[ix].column = randxInRange(1,100);
00036                 fprintf (f1,"Coordinate %d: [%d,%d]\n",ix+1,testCoordinates[ix].row,testCoordinates[ix].column);
00037         }
00038         fclose(f1);
00039          
00040          fprintf(f2,"****************** Insert testing ********************\n");
00041          for (ix=0;ix<25;ix++){
00042                  fprintf(f2,"Coordinate %d: [%d,%d]\n",ix+1,testCoordinates[ix].row,testCoordinates[ix].column);
00043                  testArray->addAt(testCoordinates[ix].row,testCoordinates[ix].column,new sparseArrayNode());
00044          }
00045          fclose(f2);
00046 #ifdef DEBUG_ON 
00047          testArray->dump();
00048 #endif
00049          
00050          printf("************** retrieval testing ************************\n");
00051          for(ix=0;ix<25;ix++){
00052                  fprintf (f3,"Attempting to retrieve [%d,%d]",testCoordinates[ix].row,
00053                                                                                                 testCoordinates[ix].column);
00054                  sparseArrayNode *p = testArray->findAt(testCoordinates[ix].row,
00055                                                                                                 testCoordinates[ix].column);
00056                  
00057                 if ( p == 0 ) 
00058                          fprintf(f3,"\t\tFAILED!!! FAILED!!!\n");
00059                  
00060                 else 
00061                          fprintf(f3,"success\n");
00062          }
00063          fclose(f3);
00064  }

Generated on Fri Mar 7 16:40:53 2008 for frpuniverse by  doxygen 1.4.7