From 0624d36b39a71e3949ffd8227660f96ba20965d8 Mon Sep 17 00:00:00 2001 From: a bellenir Date: Tue, 12 Aug 2014 20:06:21 +0000 Subject: [PATCH] add a stress test --- tests/test_rbt.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/test_rbt.c b/tests/test_rbt.c index fd5a2e2..41a532a 100644 --- a/tests/test_rbt.c +++ b/tests/test_rbt.c @@ -1,8 +1,11 @@ // Unit Test Framework Includes +#include +#include #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); + } } -- 2.52.0