]> git.mdlowis.com Git - projs/libcds.git/commitdiff
add a stress test
authora bellenir <a@bellenir.com>
Tue, 12 Aug 2014 20:06:21 +0000 (20:06 +0000)
committera bellenir <a@bellenir.com>
Tue, 12 Aug 2014 20:06:21 +0000 (20:06 +0000)
tests/test_rbt.c

index fd5a2e22f59770270a633f9486799f18bb098e7f..41a532a78100e60dbb1cdc900f3c2cdad30f2cc4 100644 (file)
@@ -1,8 +1,11 @@
 // Unit Test Framework Includes
+#include <time.h>
+#include <stdlib.h>
 #include "test.h"
 
 #include "rbt.h"
 #include "mem.h"
+#include "list.h"
 
 static int test_compare(void* a, void* b){
        int ia = (int)(mem_unbox(a));
@@ -2454,5 +2457,38 @@ TEST_SUITE(RBT) {
                mem_release(doomed);
                mem_release(tree);
        }
+
+       TEST(Ridiculous){
+               int test_val_count = 1024;
+               int i, j;
+               int list_size = 0;
+               rbt_t* tree = rbt_new(NULL);
+               list_t* vals = list_new();
+               srand(time(NULL));
+               for(j = 0; j < 10; j++){
+                       for(i = 0; i < test_val_count; i ++){
+                               void* foo = mem_box(rand());
+                               list_push_back(vals, foo);
+                               mem_retain(foo);
+                               rbt_insert(tree, foo);
+                               list_size++;
+                       }
+                       rbt_status_t status = rbt_check_status(tree);
+                       //printf("status after inserts is %d\n", status);
+                       CHECK(OK == status);
+                       for(i = 0; i < test_val_count/2; i++){
+                               int idx = rand()%list_size;
+                               void* foo = list_at(vals, idx);
+                               rbt_delete(tree, foo);
+                               list_delete(vals, idx);
+                               list_size--;
+                       }
+                       status = rbt_check_status(tree);
+                       //printf("status after deletes is %d\n", status);
+                       CHECK(OK == status);
+               }
+               mem_release(vals);
+               mem_release(tree);
+       }
 }