00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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 }