From 512b879241d79bf91f70eecdc97944505d64bf6e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 29 Oct 2017 18:23:33 +1100 Subject: BLI_heap: add validation check, improve tests Also minor readability changes, avoid running both heap_up/down gives minor speedup too. --- tests/gtests/blenlib/BLI_heap_test.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'tests/gtests') diff --git a/tests/gtests/blenlib/BLI_heap_test.cc b/tests/gtests/blenlib/BLI_heap_test.cc index e23e89b9cae..89e271d5167 100644 --- a/tests/gtests/blenlib/BLI_heap_test.cc +++ b/tests/gtests/blenlib/BLI_heap_test.cc @@ -158,18 +158,21 @@ TEST(heap, ReInsertSimple) MEM_freeN(nodes); } -TEST(heap, ReInsertRandom) +static void random_heap_reinsert_helper( + const int items_total, + const int random_seed) { - const int items_total = SIZE; Heap *heap = BLI_heap_new(); HeapNode **nodes = (HeapNode **)MEM_mallocN(sizeof(HeapNode *) * items_total, __func__); for (int in = 0; in < items_total; in++) { nodes[in] = BLI_heap_insert(heap, (float)in, SET_INT_IN_POINTER(in)); } - BLI_array_randomize(nodes, sizeof(HeapNode *), items_total, 1234); + BLI_array_randomize(nodes, sizeof(HeapNode *), items_total, random_seed); for (int i = 0; i < items_total; i++) { BLI_heap_node_value_update(heap, nodes[i], (float)i); } + EXPECT_TRUE(BLI_heap_is_valid(heap)); + for (int out_test = 0; out_test < items_total; out_test++) { HeapNode *node_top = BLI_heap_top(heap); float out = BLI_heap_node_value(node_top); @@ -180,3 +183,9 @@ TEST(heap, ReInsertRandom) BLI_heap_free(heap, NULL); MEM_freeN(nodes); } + +TEST(heap, ReInsertRandom1) { random_heap_reinsert_helper(1, 1234); } +TEST(heap, ReInsertRandom2) { random_heap_reinsert_helper(2, 1234); } +TEST(heap, ReInsertRandom100) { random_heap_reinsert_helper(100, 4321); } +TEST(heap, ReInsertRandom1024) { random_heap_reinsert_helper(1024, 9876); } +TEST(heap, ReInsertRandom2048) { random_heap_reinsert_helper(2048, 5321); } -- cgit v1.2.3