]> git.mdlowis.com Git - projs/libcds.git/commitdiff
Update linked list source for C++ compatibility and delte unimplemented tests
authorMike D. Lowis <mike@mdlowis.com>
Fri, 7 Dec 2012 21:04:51 +0000 (16:04 -0500)
committerMike D. Lowis <mike@mdlowis.com>
Fri, 7 Dec 2012 21:04:51 +0000 (16:04 -0500)
premake4.lua
source/list/sll.c
source/list/sll.h
tests/test_dll.cpp [deleted file]
tests/test_rbt.cpp [deleted file]
tests/test_sll.cpp [deleted file]

index 5240b7d8e604823feec850b1b23c40b694a517f7..0ef8d2163b89170570134370aa2d9c7af2d69a6b 100644 (file)
@@ -1,5 +1,5 @@
 -------------------------------------------------------------------------------
--- Jersey Build Configuration
+-- CDS Build Configuration
 -------------------------------------------------------------------------------
 solution "C Data Structures"
 configurations { "Release" }
@@ -14,13 +14,14 @@ project "cds"
     location "build"
     files { "source/**.*" }
 
-project "test"
+project "tests"
     kind "ConsoleApp"
     language "C++"
     location "build"
+    links { "UnitTest++", "cds" }
     includedirs { "source/**", "tools/UnitTest++/**" }
-    links { "cds", "UnitTest++" }
-    files { "tests/**.*" }
+    files { "tests/**.c*" }
+    postbuildcommands { "./tests.exe" }
 
 -------------------------------------------------------------------------------
 -- UnitTest++ - A C++ unit testing library
index c27d04fa313f061d68e12d440b2b00bf083ee133..f0300d7c7ccf66490021a263b226587684cc69d7 100644 (file)
@@ -1,5 +1,5 @@
-#include "sll.h"
 #include <stdlib.h>
+#include "sll.h"
 
 sll_t* sll_new(void)
 {
index d937aa0d0573cb02f73b69c6368024c4e8ee937b..ea3bd0fa1c2e3293057c16f1b246463c765e6b45 100644 (file)
@@ -1,21 +1,25 @@
 #ifndef SLL_H
 #define SLL_H
 
-//! A linked list node.
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** A linked list node. */
 typedef struct sll_node_t
 {
-    //! Pointer to the contents the node
+    /* Pointer to the contents the node */
     void* contents;
-    //! Pointer to next node in the list.
+    /* Pointer to next node in the list. */
     struct sll_node_t* next;
 } sll_node_t;
 
-//! A singly linked list
+/* A singly linked list */
 typedef struct sll_t
 {
-    //! Pointer to the first element in the list
+    /* Pointer to the first element in the list */
     sll_node_t* head;
-    //! Pointer to the last element in the list
+    /* Pointer to the last element in the list */
     sll_node_t* tail;
 } sll_t;
 
@@ -24,7 +28,7 @@ typedef struct sll_t
  *
  * @return A pointer to the newly created list.
  **/
-sll_t* sll_new(void);
+extern sll_t* sll_new(void);
 
 /**
  * @brief Creates a new node with given contents.
@@ -57,7 +61,22 @@ void sll_free(sll_t* list, int free_contents);
  */
 void sll_free_node(sll_node_t* node, int free_contents);
 
+/**
+ * @brief
+ *
+ * @param list
+ *
+ * @return
+ */
 sll_node_t* sll_front( sll_t* list );
+
+/**
+ * @brief
+ *
+ * @param list
+ *
+ * @return
+ */
 sll_node_t* sll_back( sll_t* list );
 
 /**
@@ -166,4 +185,8 @@ sll_node_t* sll_insert( sll_t* list, unsigned int index, void* contents);
  **/
 sll_node_t* sll_delete( sll_t* list, unsigned int index, int free_contents);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/tests/test_dll.cpp b/tests/test_dll.cpp
deleted file mode 100644 (file)
index 4155a9c..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// Unit Test Framework Includes
-#include "UnitTest++.h"
-
-// File To Test
-#include "dll.h"
-
-using namespace UnitTest;
-
-//-----------------------------------------------------------------------------
-// Begin Unit Tests
-//-----------------------------------------------------------------------------
-namespace {
-    //-------------------------------------------------------------------------
-    // Test XXX Function
-    //-------------------------------------------------------------------------
-    TEST(Verify_XXX)
-    {
-    }
-}
diff --git a/tests/test_rbt.cpp b/tests/test_rbt.cpp
deleted file mode 100644 (file)
index 86a65a7..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// Unit Test Framework Includes
-#include "UnitTest++.h"
-
-// File To Test
-#include "rbt.h"
-
-using namespace UnitTest;
-
-//-----------------------------------------------------------------------------
-// Begin Unit Tests
-//-----------------------------------------------------------------------------
-namespace {
-    //-------------------------------------------------------------------------
-    // Test XXX Function
-    //-------------------------------------------------------------------------
-    TEST(Verify_XXX)
-    {
-    }
-}
diff --git a/tests/test_sll.cpp b/tests/test_sll.cpp
deleted file mode 100644 (file)
index 2c014ff..0000000
+++ /dev/null
@@ -1,382 +0,0 @@
-// Unit Test Framework Includes
-#include "UnitTest++.h"
-#include <cstdlib>
-
-// File To Test
-#include "sll.h"
-
-using namespace UnitTest;
-
-//-----------------------------------------------------------------------------
-// Begin Unit Tests
-//-----------------------------------------------------------------------------
-namespace {
-    //-------------------------------------------------------------------------
-    // Test sll_new function
-    //-------------------------------------------------------------------------
-    TEST(Verify_sll_new_returns_newly_allocated_empty_list)
-    {
-        sll_t* list = sll_new();
-        CHECK( NULL != list );
-        CHECK( NULL == list->head );
-        CHECK( NULL == list->tail );
-        free( list );
-    }
-
-    //-------------------------------------------------------------------------
-    // Test sll_new_node function
-    //-------------------------------------------------------------------------
-    TEST(Verify_sll_new_node_returns_newly_allocated_node_with_given_contents)
-    {
-        int stuff = 0;
-        sll_node_t* node = sll_new_node( &stuff );
-        CHECK( NULL != node );
-        CHECK( &stuff == node->contents );
-        CHECK( NULL == node->next );
-        free( node );
-    }
-
-    //-------------------------------------------------------------------------
-    // Test sll_free function
-    //-------------------------------------------------------------------------
-    TEST(Verify_sll_free_does_nothing_on_null_pointer)
-    {
-        sll_free( NULL, 0 );
-    }
-
-    TEST(Verify_sll_free_frees_the_given_empty_list)
-    {
-        sll_t* list = sll_new();
-        sll_free( list, 0 );
-    }
-
-    TEST(Verify_sll_free_frees_the_given_list_including_nodes)
-    {
-        sll_t* list = sll_new();
-        list->head = sll_new_node(NULL);
-        list->tail = list->head;
-        sll_free( list, 0 );
-    }
-
-    TEST(Verify_sll_free_frees_the_given_list_including_nodes_and_node_contents)
-    {
-        sll_t* list = sll_new();
-        int* foo = (int*)malloc( sizeof(int) );
-        list->head = sll_new_node( foo );
-        list->tail = list->head;
-        sll_free( list, 1 );
-    }
-
-    //-------------------------------------------------------------------------
-    // Test sll_free_node function
-    //-------------------------------------------------------------------------
-    TEST(Verify_sll_free_node_does_nothing_on_null_pointer)
-    {
-        sll_free_node( NULL, 0 );
-    }
-
-    TEST(Verify_sll_free_node_frees_the_given_node)
-    {
-        sll_node_t* node = sll_new_node( NULL );
-        sll_free_node( node, 0 );
-    }
-
-    TEST(Verify_sll_free_node_frees_the_given_node_and_contents)
-    {
-        int* foo = (int*)malloc( sizeof(int) );
-        sll_node_t* node = sll_new_node( foo );
-        sll_free_node( node, 1 );
-    }
-
-    //-------------------------------------------------------------------------
-    // Test sll_front function
-    //-------------------------------------------------------------------------
-    TEST(Verify_sll_front_returns_NULL_if_list_is_NULL)
-    {
-        CHECK( NULL == sll_front( NULL ) );
-    }
-
-    TEST(Verify_sll_front_returns_NULL_if_list_is_empty)
-    {
-        sll_t list = { NULL, NULL };
-        CHECK( NULL == sll_front( &list ) );
-    }
-
-    TEST(Verify_sll_front_returns_the_head_of_the_list)
-    {
-        sll_node_t node2 = { NULL, NULL };
-        sll_node_t node1 = { NULL, &node2 };
-        sll_t list = { &node1, &node2 };
-        CHECK( &node1 == sll_front( &list ) );
-    }
-
-    //-------------------------------------------------------------------------
-    // Test sll_back function
-    //-------------------------------------------------------------------------
-    TEST(Verify_sll_back_returns_NULL_if_list_is_NULL)
-    {
-        CHECK( NULL == sll_back( NULL ) );
-    }
-
-    TEST(Verify_sll_back_returns_NULL_if_list_is_empty)
-    {
-        sll_t list = { NULL, NULL };
-        CHECK( NULL == sll_back( &list ) );
-    }
-
-    TEST(Verify_sll_back_returns_the_tail_of_the_list)
-    {
-        sll_node_t node2 = { NULL, NULL };
-        sll_node_t node1 = { NULL, &node2 };
-        sll_t list = { &node1, &node2 };
-        CHECK( &node2 == sll_back( &list ) );
-    }
-
-    //-------------------------------------------------------------------------
-    // Test sll_length function
-    //-------------------------------------------------------------------------
-    TEST(Verify_sll_length_returns_0_when_passed_null_pointer)
-    {
-        CHECK( 0 == sll_length(NULL) );
-    }
-
-    TEST(Verify_sll_length_returns_0_when_list_is_empty)
-    {
-        sll_t* list = sll_new();
-        CHECK( 0 == sll_length( list ) );
-        free( list );
-    }
-
-    TEST(Verify_sll_length_returns_1_when_list_is_length_1)
-    {
-        sll_node_t node1 = { NULL, NULL };
-        sll_t list = { &node1, &node1 };
-
-        CHECK( 1 == sll_length( &list ) );
-    }
-
-    TEST(Verify_sll_length_returns_2_when_list_is_length_2)
-    {
-        sll_node_t node2 = { NULL, NULL };
-        sll_node_t node1 = { NULL, &node2 };
-        sll_t list = { &node1, &node2 };
-
-        CHECK( 2 == sll_length( &list ) );
-    }
-
-    //-------------------------------------------------------------------------
-    // Test sll_index function
-    //-------------------------------------------------------------------------
-    TEST(Verify_sll_index_returns_NULL_on_null_pointer)
-    {
-        CHECK( NULL == sll_index( NULL, 0 ) );
-    }
-
-    TEST(Verify_sll_index_returns_NULL_when_list_is_empty)
-    {
-        sll_t list = { NULL, NULL };
-        CHECK( NULL == sll_index( &list, 0 ) );
-    }
-
-    TEST(Verify_sll_index_returns_NULL_when_index_out_of_range)
-    {
-        sll_node_t node3 = { NULL, NULL };
-        sll_node_t node2 = { NULL, &node3 };
-        sll_node_t node1 = { NULL, &node2 };
-        sll_t list = { &node1, &node3 };
-        CHECK( NULL == sll_index( &list, 3 ) );
-    }
-
-    TEST(Verify_sll_index_returns_node_at_index_0_of_3_element_list)
-    {
-        sll_node_t node3 = { NULL, NULL };
-        sll_node_t node2 = { NULL, &node3 };
-        sll_node_t node1 = { NULL, &node2 };
-        sll_t list = { &node1, &node3 };
-        CHECK( &node1 == sll_index( &list, 0 ) );
-    }
-
-    TEST(Verify_sll_index_returns_node_at_index_1_of_3_element_list)
-    {
-        sll_node_t node3 = { NULL, NULL };
-        sll_node_t node2 = { NULL, &node3 };
-        sll_node_t node1 = { NULL, &node2 };
-        sll_t list = { &node1, &node3 };
-        CHECK( &node2 == sll_index( &list, 1 ) );
-    }
-
-    TEST(Verify_sll_index_returns_node_at_index_2_of_3_element_list)
-    {
-        sll_node_t node3 = { NULL, NULL };
-        sll_node_t node2 = { NULL, &node3 };
-        sll_node_t node1 = { NULL, &node2 };
-        sll_t list = { &node1, &node3 };
-        CHECK( &node3 == sll_index( &list, 2 ) );
-    }
-
-    //-------------------------------------------------------------------------
-    // Test sll_push_front function
-    //-------------------------------------------------------------------------
-    TEST(Verify_sll_push_front_returns_null_if_list_is_null)
-    {
-        CHECK( NULL == sll_push_front( NULL, NULL ) );
-    }
-
-    TEST(Verify_sll_push_front_pushes_to_empty_list)
-    {
-        sll_t list = { NULL, NULL };
-        sll_node_t* node = sll_push_front( &list, (void*)0x1234 );
-        CHECK( NULL != node );
-        CHECK( (void*)0x1234 == node->contents );
-        CHECK( NULL == node->next );
-        CHECK( node == list.head );
-        CHECK( node == list.tail );
-    }
-
-    TEST(Verify_sll_push_front_pushes_to_front_of_list_of_length_1)
-    {
-        sll_node_t node1 = { NULL, NULL };
-        sll_t list = { &node1, &node1 };
-        sll_node_t* node = sll_push_front( &list, (void*)0x1234 );
-        CHECK( NULL != node );
-        CHECK( (void*)0x1234 == node->contents );
-        CHECK( NULL != node->next );
-        CHECK( node == list.head );
-        CHECK( node != list.tail );
-    }
-
-    //-------------------------------------------------------------------------
-    // Test sll_push_back function
-    //-------------------------------------------------------------------------
-    TEST(Verify_sll_push_back_returns_null_if_list_is_null)
-    {
-        CHECK( NULL == sll_push_back( NULL, NULL ) );
-    }
-
-    TEST(Verify_sll_push_back_pushes_to_empty_list)
-    {
-        sll_t list = { NULL, NULL };
-        sll_node_t* node = sll_push_back( &list, (void*)0x1234 );
-        CHECK( NULL != node );
-        CHECK( (void*)0x1234 == node->contents );
-        CHECK( NULL == node->next );
-        CHECK( node == list.head );
-        CHECK( node == list.tail );
-    }
-
-    TEST(Verify_sll_push_back_pushes_to_back_of_list_of_length_1)
-    {
-        sll_node_t node1 = { NULL, NULL };
-        sll_t list = { &node1, &node1 };
-        sll_node_t* node = sll_push_back( &list, (void*)0x1234 );
-        CHECK( NULL != node );
-        CHECK( (void*)0x1234 == node->contents );
-        CHECK( &node1 != node->next );
-        CHECK( node != list.head );
-        CHECK( node == list.tail );
-    }
-
-    //-------------------------------------------------------------------------
-    // Test sll_pop_front function
-    //-------------------------------------------------------------------------
-    TEST(Verify_pop_front_returns_null_if_list_is_null)
-    {
-        CHECK( NULL == sll_pop_front( NULL ) );
-    }
-
-    TEST(Verify_pop_front_returns_null_if_list_is_empty)
-    {
-        sll_t list = { NULL, NULL };
-        CHECK( NULL == sll_pop_front( &list ) );
-    }
-
-    TEST(Verify_pop_front_removes_a_node_from_the_front_of_a_list_of_length_1)
-    {
-        sll_node_t node1 = { NULL, NULL };
-        sll_t list = { &node1, &node1 };
-        CHECK( &node1 == sll_pop_front( &list ) );
-        CHECK( NULL == list.head );
-        CHECK( NULL == list.tail );
-    }
-
-    TEST(Verify_pop_front_removes_a_node_from_the_front_of_a_list_of_length_2)
-    {
-        sll_node_t node2 = { NULL, NULL };
-        sll_node_t node1 = { NULL, &node2 };
-        sll_t list = { &node1, &node2 };
-        CHECK( &node1 == sll_pop_front( &list ) );
-        CHECK( &node2 == list.head );
-        CHECK( &node2 == list.tail );
-    }
-
-    TEST(Verify_pop_front_removes_a_node_from_the_front_of_a_list_of_length_3)
-    {
-        sll_node_t node3 = { NULL, NULL };
-        sll_node_t node2 = { NULL, &node3 };
-        sll_node_t node1 = { NULL, &node2 };
-        sll_t list = { &node1, &node3 };
-        CHECK( &node1 == sll_pop_front( &list ) );
-        CHECK( &node2 == list.head );
-        CHECK( &node3 == list.tail );
-    }
-
-    //-------------------------------------------------------------------------
-    // Test sll_pop_back function
-    //-------------------------------------------------------------------------
-    TEST(Verify_pop_back_does_nothing_if_list_is_null)
-    {
-        CHECK( NULL == sll_pop_back( NULL ) );
-    }
-
-    TEST(Verify_pop_back_does_nothing_if_list_is_empty)
-    {
-        sll_t list = { NULL, NULL };
-        CHECK( NULL == sll_pop_back( &list ) );
-    }
-
-    TEST(Verify_pop_back_removes_a_node_from_the_back_of_a_list_of_length_1)
-    {
-        sll_node_t node1 = { NULL, NULL };
-        sll_t list = { &node1, &node1 };
-        CHECK( &node1 == sll_pop_back( &list ) );
-        CHECK( NULL == list.head );
-        CHECK( NULL == list.tail );
-    }
-
-    TEST(Verify_pop_back_removes_a_node_from_the_back_of_a_list_of_length_2)
-    {
-        sll_node_t node2 = { NULL, NULL };
-        sll_node_t node1 = { NULL, &node2 };
-        sll_t list = { &node1, &node2 };
-        CHECK( &node2 == sll_pop_back( &list ) );
-        CHECK( &node1 == list.head );
-        CHECK( &node1 == list.tail );
-    }
-
-    TEST(Verify_pop_back_removes_a_node_from_the_back_of_a_list_of_length_3)
-    {
-        sll_node_t node3 = { NULL, NULL };
-        sll_node_t node2 = { NULL, &node3 };
-        sll_node_t node1 = { NULL, &node2 };
-        sll_t list = { &node1, &node3 };
-        CHECK( &node3 == sll_pop_back( &list ) );
-        CHECK( &node1 == list.head );
-        CHECK( &node2 == list.tail );
-    }
-
-    //-------------------------------------------------------------------------
-    // Test sll_insert function
-    //-------------------------------------------------------------------------
-    TEST(Verify_insert_does_nothing_if_list_is_null)
-    {
-        CHECK( NULL == sll_insert( NULL, 0, (void*)0x1234 ) );
-    }
-
-    //-------------------------------------------------------------------------
-    // Test sll_delete function
-    //-------------------------------------------------------------------------
-    TEST(Verify_delete_does_nothing_if_list_is_null)
-    {
-        CHECK( NULL == sll_insert( NULL, 0, 0 ) );
-    }
-}