/////////////////////////////////////////////////////////////// // Check Priority Queue. By Charles Galambos // $Id: TPriQ.cc,v 1.3 1998/08/24 13:58:45 ees1cg Exp $ #include "amma/PriQueueL.hh" #include #include void SeqTest(void); void InterTest(void); int main() { printf("Starting test. \n"); SeqTest(); InterTest(); return 0; } void SeqTest(void) { PriQueueLC Queue; int i; for(i = 2;i < 10000;i++) { Queue.Insert(rand(),i+1); //Queue.Dump(); } int Last = Queue.TopKey(); while(Queue.IsElm()) { Tuple2C &KP =Queue.GetTopPair(); const int Val = KP.Data2(); const int Key = KP.Data1(); if(Key < Last) { printf("\n ERROR !!! %d %d \n",KP.Data1(),Val); break; } Last = Key; //printf("(%d %d) ",KP.Data1(),Val); } printf("Sequence test passed. \n"); return ; } void InterTest(void) { PriQueueLC Queue; int i,Last; for(i = 1;i < 10000;i++) { Queue.Insert(rand(),i+1); } printf("Starting Interleave. \n"); for(int k = 0;k < 1000;k++) { // Remove Last = Queue.TopKey(); for(i = 1;i < 10;i++) { Tuple2C &KP =Queue.GetTopPair(); const int Val = KP.Data2(); const int Key = KP.Data1(); if(Key < Last) { printf("\n ERROR !!! %d %d \n",KP.Data1(),Val); break; } Last = Key; } // Insert. for(i = 1;i < 10;i++) { Queue.Insert(rand(),i+1); } } printf("Checking remaining queue. \n"); Last = Queue.TopKey(); while(Queue.IsElm()) { Tuple2C &KP =Queue.GetTopPair(); const int Val = KP.Data2(); const int Key = KP.Data1(); if(Key < Last) { printf("\n ERROR !!! %d %d \n",KP.Data1(),Val); break; } Last = Key; } printf("Interleave test passed. \n"); return ; }