]> git.mdlowis.com Git - projs/libcds.git/commitdiff
rename rbt_count_nodes to rbt_size; remove testing-only functions from .h
authora bellenir <a@bellenir.com>
Tue, 2 Sep 2014 19:13:10 +0000 (19:13 +0000)
committera bellenir <a@bellenir.com>
Tue, 2 Sep 2014 19:13:10 +0000 (19:13 +0000)
Rakefile
source/rbt/rbt.c
source/rbt/rbt.h
tests/test_rbt.c

index 3241ce8e7cc5ac8616ef81d106661024d3ea59bb..c62d83073a3749e2ced4277b7f256dcb475096da 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -24,7 +24,7 @@ end
 TestEnv = Env.clone  do |env|
   env.build_dir('source','build/obj/test_source')
   env.build_dir('tests','build/obj/tests/source')
-  env['CFLAGS']  += ['-g', '--coverage', '-DLEAK_DETECT_LEVEL=1']
+  env['CFLAGS']  += ['-g', '--coverage', '-DLEAK_DETECT_LEVEL=1', '-DTESTING']
   #env['CFLAGS']  += ['-DNDEBUG'] #disables asserts so they won't effect coverage analysis
   env["LDFLAGS"] += ['--coverage']
   env['CPPPATH'] += Dir['tests/']
index 80cfde14b36fa28e1a40f8b129b31802552cf9de..4faeb8003a664c5d7306c7a17f2f85a8a11b0b3a 100644 (file)
@@ -34,6 +34,9 @@ static void rbt_node_free(void* v_node){
        if(node->left) mem_release(node->left);
        if(node->right) mem_release(node->right);
 }
+#ifndef TESTING
+static
+#endif
 rbt_node_t* rbt_node_new(void* contents){
        rbt_node_t* node = mem_allocate(sizeof(rbt_node_t), &rbt_node_free);
        node->left = NULL;
@@ -48,7 +51,9 @@ rbt_node_t* rbt_node_new(void* contents){
 /* ---------------------------------------- */
 /*    informational / querying functions    */
 /* ---------------------------------------- */
-
+#ifndef TESTING
+static
+#endif
 rbt_color_t rbt_node_color(rbt_node_t* node){
        //leaves are NULL and black implicitly
        return (node ? node->color : BLACK);
@@ -76,7 +81,7 @@ static rbt_node_t* rightmost_descendant(rbt_node_t* node){
 static int rbt_count(rbt_node_t* node){
        return (!node ? 0 : (1 + rbt_count(node->left) + rbt_count(node->right)));
 }
-int rbt_count_nodes(rbt_t* tree){
+int rbt_size(rbt_t* tree){
        return rbt_count(tree->root);
 }
 
index dff00c232dd91185fb4640bfc0cd2ab22c3968f8..adb05bf3682c86c5c87a346dddc52cb68dfc3c44 100644 (file)
@@ -46,26 +46,6 @@ typedef struct {
 rbt_t* rbt_new(comparator_t comparator);
 
 
-/**
- * @brief creates a new node for a red-black tree
- *
- * @param contents pointer to the contents of the node
- *
- * @return pointer to newly created node
- */
-rbt_node_t* rbt_node_new(void* contents);
-
-
-/**
- * @brief get the color of a given node
- *
- * @param node the node on which to operate
- *
- * @return RED or BLACK. BLACK if node is NULL (a leaf)
- */
-rbt_color_t rbt_node_color(rbt_node_t* node);
-
-
 /**
  * @brief find a value in a red-black tree
  *
@@ -85,7 +65,7 @@ rbt_node_t* rbt_lookup(rbt_t* tree, void* value);
  *
  * @return the number of nodes present in the tree
  */
-int rbt_count_nodes(rbt_t* tree);
+int rbt_size(rbt_t* tree);
 
 /**
  * @brief insert a value into a red-black tree
index 172f10534a4b04406cda101a608cbb47d43c19ef..0cd9c417f3fe235e2ee379d14932b99608c6d70e 100644 (file)
@@ -7,6 +7,9 @@
 #include "mem.h"
 #include "list.h"
 
+extern rbt_color_t rbt_node_color(rbt_node_t* node);
+extern rbt_node_t* rbt_node_new(void* contents);
+
 static int test_compare(void* a, void* b){
        int ia = (int)(mem_unbox(a));
        int ib = (int)(mem_unbox(b));
@@ -82,7 +85,6 @@ TEST_SUITE(RBT) {
                CHECK(NULL == node->right);
                CHECK(NULL == node->parent);
                CHECK(box42 == node->contents);
-               //CHECK(OK == rbt_check_node(node, -1, -1)); //TODO: fix this?
                mem_release(node);
        }
 
@@ -417,13 +419,13 @@ TEST_SUITE(RBT) {
        //-------------------------------------------------------------------------
        // Test node count function
        //-------------------------------------------------------------------------
-       TEST(Verify_count_nodes_works){
+       TEST(Verify_size_works){
                int i=0;
                rbt_t* tree = rbt_new(NULL);
-               CHECK(0 == rbt_count_nodes(tree));
+               CHECK(0 == rbt_size(tree));
                for(i = 1; i < 10; i++){
                        rbt_insert(tree, mem_box(i));
-                       CHECK(i == rbt_count_nodes(tree));
+                       CHECK(i == rbt_size(tree));
                }
                mem_release(tree);
        }
@@ -2534,19 +2536,19 @@ TEST_SUITE(RBT) {
                //rbt_t* tree = rbt_new(NULL);
                rbt_delete(tree, target);
                CHECK(OK == rbt_check_status(tree));
-               CHECK(0 == rbt_count_nodes(tree));
+               CHECK(0 == rbt_size(tree));
                rbt_insert(tree, box88);
                rbt_delete(tree, target);
                CHECK(OK == rbt_check_status(tree));
-               CHECK(1 == rbt_count_nodes(tree));
+               CHECK(1 == rbt_size(tree));
                rbt_insert(tree, box36);
                rbt_delete(tree, target);
                CHECK(OK == rbt_check_status(tree));
-               CHECK(2 == rbt_count_nodes(tree));
+               CHECK(2 == rbt_size(tree));
                rbt_insert(tree, box99);
                rbt_delete(tree, target);
                CHECK(OK == rbt_check_status(tree));
-               CHECK(3 == rbt_count_nodes(tree));
+               CHECK(3 == rbt_size(tree));
                mem_release(target);
                mem_release(tree);
        }
@@ -2566,7 +2568,7 @@ TEST_SUITE(RBT) {
                                mem_retain(foo);
                                rbt_insert(tree, foo);
                                listsize++;
-                               CHECK(listsize == rbt_count_nodes(tree));
+                               CHECK(listsize == rbt_size(tree));
                        }
                        rbt_status_t status = rbt_check_status(tree);
                        //printf("status after inserts is %d\n", status);
@@ -2578,7 +2580,7 @@ TEST_SUITE(RBT) {
                                rbt_delete(tree, foo);
                                list_delete(vals, idx);
                                listsize--;
-                               CHECK(listsize == rbt_count_nodes(tree));
+                               CHECK(listsize == rbt_size(tree));
                        }
                        status = rbt_check_status(tree);
                        //printf("status after deletes is %d\n", status);