From a4c22303b1044eee5ccbf0766895a879a8f4810e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 19 Feb 2008 21:51:48 +0000 Subject: Oops. I made the Bu::Heap API look like a stack, not a queue, that's been fixed, and the Bu::ItoHeap is working and tested. Note that when multiple items have the same sort order, they will come out in random order. --- src/tests/itoheap.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/tests/itoheap.cpp (limited to 'src/tests/itoheap.cpp') diff --git a/src/tests/itoheap.cpp b/src/tests/itoheap.cpp new file mode 100644 index 0000000..67169e7 --- /dev/null +++ b/src/tests/itoheap.cpp @@ -0,0 +1,64 @@ +#include +#include + +#include "bu/itoheap.h" +#include "bu/ito.h" + +class Consumer : public Bu::Ito +{ +public: + Consumer() + { + } + + virtual ~Consumer() + { + } + + void *run() + { + for( int j = 0; j < 10; j++ ) + { + printf("Trying to read [%d].\n", j ); + + try + { + int iNum = hInt.dequeue( 0, 500000 ); + printf("Read %d\n", iNum ); + } + catch( Bu::HeapException &e ) + { + printf("Nothing yet...\n"); + } + } + + return NULL; + } + + Bu::ItoHeap hInt; +}; + + +int main() +{ + Consumer c; + + for( int j = 0; j < 3; j++ ) + { + int iNum = rand()%10; + printf("Enqueuing %d.\n", iNum ); + c.hInt.enqueue( iNum ); + } + + printf("Sarting consumer.\n"); + c.start(); + + for( int j = 0; j < 5; j++ ) + { + sleep( 1 ); + int iNum = rand()%10; + printf("Enqueuing %d.\n", iNum ); + c.hInt.enqueue( iNum ); + } +} + -- cgit v1.2.3