diff --git a/README.md b/README.md index 3aba46c..c02af06 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Before using ToFu, ensure you have the following installed: # ====================== [wrap-git] url = https://github.com/fossillogic/fossil-tofu.git - revision = v0.1.3 + revision = v0.1.4 [provide] fossil-tofu = fossil_tofu_dep diff --git a/code/logic/doublylist.c b/code/logic/doublylist.c index 67ed417..7f7c77f 100644 --- a/code/logic/doublylist.c +++ b/code/logic/doublylist.c @@ -159,34 +159,6 @@ size_t fossil_dlist_size(const fossil_dlist_t* dlist) { return count; } -fossil_tofu_t* fossil_dlist_getter(fossil_dlist_t* dlist, fossil_tofu_t data) { - if (!dlist) return NULL; // Error checking for null list - - fossil_dlist_node_t* current = dlist->head; - while (current) { - if (fossil_tofu_equals(current->data, data)) { - return &(current->data); - } - current = current->next; - } - return NULL; // Not found -} - -int32_t fossil_dlist_setter(fossil_dlist_t* dlist, fossil_tofu_t data) { - if (!dlist) return FOSSIL_TOFU_FAILURE; // Error checking for null list - - fossil_dlist_node_t* current = dlist->head; - while (current) { - if (fossil_tofu_equals(current->data, data)) { - // Ensure to free old data if it was dynamically allocated - current->data = data; - return FOSSIL_TOFU_SUCCESS; // Success - } - current = current->next; - } - return FOSSIL_TOFU_FAILURE; // Not found -} - bool fossil_dlist_not_empty(const fossil_dlist_t* dlist) { return (dlist != NULL && dlist->head != NULL); } diff --git a/code/logic/dqueue.c b/code/logic/dqueue.c index 947e1f4..4f8c6c4 100644 --- a/code/logic/dqueue.c +++ b/code/logic/dqueue.c @@ -142,40 +142,6 @@ size_t fossil_dqueue_size(const fossil_dqueue_t* dqueue) { return count; } -fossil_tofu_t* fossil_dqueue_getter(fossil_dqueue_t* dqueue, fossil_tofu_t data) { - if (!dqueue) { - fprintf(stderr, "Error: dqueue cannot be NULL\n"); - return NULL; - } - - fossil_dqueue_node_t* current = dqueue->front; - while (current) { - if (fossil_tofu_equals(current->data, data)) { - return &(current->data); // Return pointer to the found data - } - current = current->next; - } - return NULL; // Not found -} - -int32_t fossil_dqueue_setter(fossil_dqueue_t* dqueue, fossil_tofu_t data) { - if (!dqueue) { - fprintf(stderr, "Error: dqueue cannot be NULL\n"); - return FOSSIL_TOFU_FAILURE; - } - - fossil_dqueue_node_t* current = dqueue->front; - while (current) { - if (fossil_tofu_equals(current->data, data)) { - // Assuming `data` should replace current->data - current->data = data; // Update data - return FOSSIL_TOFU_SUCCESS; // Success - } - current = current->next; - } - return FOSSIL_TOFU_FAILURE; // Not found -} - bool fossil_dqueue_not_empty(const fossil_dqueue_t* dqueue) { if (!dqueue) { fprintf(stderr, "Error: dqueue cannot be NULL\n"); diff --git a/code/logic/forwardlist.c b/code/logic/forwardlist.c index 5fe8379..201082c 100644 --- a/code/logic/forwardlist.c +++ b/code/logic/forwardlist.c @@ -141,39 +141,6 @@ size_t fossil_flist_size(const fossil_flist_t* flist) { return count; } -fossil_tofu_t* fossil_flist_getter(fossil_flist_t* flist, fossil_tofu_t data) { - if (!flist) { - fprintf(stderr, "Error: flist cannot be NULL\n"); - return NULL; - } - - fossil_flist_node_t* current = flist->head; - while (current) { - if (fossil_tofu_equals(current->data, data)) { - return &(current->data); // Return pointer to found data - } - current = current->next; - } - return NULL; // Not found -} - -int32_t fossil_flist_setter(fossil_flist_t* flist, fossil_tofu_t data) { - if (!flist) { - fprintf(stderr, "Error: flist cannot be NULL\n"); - return FOSSIL_TOFU_FAILURE; - } - - fossil_flist_node_t* current = flist->head; - while (current) { - if (fossil_tofu_equals(current->data, data)) { - current->data = data; // Update data - return FOSSIL_TOFU_SUCCESS; // Success - } - current = current->next; - } - return FOSSIL_TOFU_FAILURE; // Not found -} - bool fossil_flist_not_empty(const fossil_flist_t* flist) { if (!flist) { fprintf(stderr, "Error: flist cannot be NULL\n"); diff --git a/code/logic/fossil/tofu/doublylist.h b/code/logic/fossil/tofu/doublylist.h index 58c79cb..fcefb42 100644 --- a/code/logic/fossil/tofu/doublylist.h +++ b/code/logic/fossil/tofu/doublylist.h @@ -107,26 +107,6 @@ void fossil_dlist_reverse_backward(fossil_dlist_t* dlist); */ size_t fossil_dlist_size(const fossil_dlist_t* dlist); -/** - * Get the data from the doubly linked list matching the specified data. - * - * @param dlist The doubly linked list from which to get the data. - * @param data The data to search for. - * @return A pointer to the matching data. - * @note Time complexity: O(n) - */ -fossil_tofu_t* fossil_dlist_getter(fossil_dlist_t* dlist, fossil_tofu_t data); - -/** - * Set data in the doubly linked list. - * - * @param dlist The doubly linked list in which to set the data. - * @param data The data to set. - * @return The error code indicating the success or failure of the operation. - * @note Time complexity: O(n) - */ -int32_t fossil_dlist_setter(fossil_dlist_t* dlist, fossil_tofu_t data); - /** * Check if the doubly linked list is not empty. * @@ -198,14 +178,6 @@ namespace fossil { return fossil_dlist_size(dlist_); } - fossil_tofu_t* getter(fossil_tofu_t data) { - return fossil_dlist_getter(dlist_, data); - } - - void setter(fossil_tofu_t data) { - fossil_dlist_setter(dlist_, data); - } - void reverse_forward() { fossil_dlist_reverse_forward(dlist_); } diff --git a/code/logic/fossil/tofu/dqueue.h b/code/logic/fossil/tofu/dqueue.h index e429547..23fcae5 100644 --- a/code/logic/fossil/tofu/dqueue.h +++ b/code/logic/fossil/tofu/dqueue.h @@ -91,26 +91,6 @@ int32_t fossil_dqueue_search(const fossil_dqueue_t* dqueue, fossil_tofu_t data); */ size_t fossil_dqueue_size(const fossil_dqueue_t* dqueue); -/** - * Get the data from the dynamic queue matching the specified data. - * - * @param dqueue The dynamic queue from which to get the data. - * @param data The data to search for. - * @return A pointer to the matching data. - * @note Time complexity: O(n) - */ -fossil_tofu_t* fossil_dqueue_getter(fossil_dqueue_t* dqueue, fossil_tofu_t data); - -/** - * Set data in the dynamic queue. - * - * @param dqueue The dynamic queue in which to set the data. - * @param data The data to set. - * @return The error code indicating the success or failure of the operation. - * @note Time complexity: O(n) - */ -int32_t fossil_dqueue_setter(fossil_dqueue_t* dqueue, fossil_tofu_t data); - /** * Check if the dynamic queue is not empty. * @@ -182,14 +162,6 @@ namespace fossil { return fossil_dqueue_size(dqueue_); } - fossil_tofu_t* getter(fossil_tofu_t data) { - return fossil_dqueue_getter(dqueue_, data); - } - - void setter(fossil_tofu_t data) { - fossil_dqueue_setter(dqueue_, data); - } - bool not_empty() { return fossil_dqueue_not_empty(dqueue_); } diff --git a/code/logic/fossil/tofu/forwardlist.h b/code/logic/fossil/tofu/forwardlist.h index b6bb12f..a7eb99a 100644 --- a/code/logic/fossil/tofu/forwardlist.h +++ b/code/logic/fossil/tofu/forwardlist.h @@ -105,26 +105,6 @@ void fossil_flist_reverse_backward(fossil_flist_t* flist); */ size_t fossil_flist_size(const fossil_flist_t* flist); -/** - * Get the data from the forward list matching the specified data. - * - * @param flist The forward list from which to get the data. - * @param data The data to search for. - * @return A pointer to the matching data. - * @complexity O(n) - */ -fossil_tofu_t* fossil_flist_getter(fossil_flist_t* flist, fossil_tofu_t data); - -/** - * Set data in the forward list. - * - * @param flist The forward list in which to set the data. - * @param data The data to set. - * @return The error code indicating the success or failure of the operation. - * @complexity O(n) - */ -int32_t fossil_flist_setter(fossil_flist_t* flist, fossil_tofu_t data); - /** * Check if the forward list is not empty. * @@ -196,14 +176,6 @@ namespace fossil { return fossil_flist_size(flist_); } - fossil_tofu_t* getter(fossil_tofu_t data) { - return fossil_flist_getter(flist_, data); - } - - void setter(fossil_tofu_t data) { - fossil_flist_setter(flist_, data); - } - void reverse_forward() { fossil_flist_reverse_forward(flist_); } diff --git a/code/logic/fossil/tofu/pqueue.h b/code/logic/fossil/tofu/pqueue.h index 73a333e..82518a0 100644 --- a/code/logic/fossil/tofu/pqueue.h +++ b/code/logic/fossil/tofu/pqueue.h @@ -91,28 +91,6 @@ int32_t fossil_pqueue_search(const fossil_pqueue_t* pqueue, fossil_tofu_t data, */ size_t fossil_pqueue_size(const fossil_pqueue_t* pqueue); -/** - * Get the data from the priority queue matching the specified data and priority. - * - * @param pqueue The priority queue from which to get the data. - * @param data The data to search for. - * @param priority The priority of the data. - * @return A pointer to the matching data, or NULL if not found. - * @note Time complexity: O(n) - */ -fossil_tofu_t* fossil_pqueue_getter(fossil_pqueue_t* pqueue, fossil_tofu_t data, int32_t priority); - -/** - * Set data in the priority queue with the specified priority. - * - * @param pqueue The priority queue in which to set the data. - * @param data The data to set. - * @param priority The priority of the data. - * @return The error code indicating the success or failure of the operation. - * @note Time complexity: O(n) - */ -int32_t fossil_pqueue_setter(fossil_pqueue_t* pqueue, fossil_tofu_t data, int32_t priority); - /** * Check if the priority queue is not empty. * @@ -184,14 +162,6 @@ namespace fossil { return fossil_pqueue_size(pqueue_); } - fossil_tofu_t* getter(fossil_tofu_t data, int32_t priority) { - return fossil_pqueue_getter(pqueue_, data, priority); - } - - void setter(fossil_tofu_t data, int32_t priority) { - fossil_pqueue_setter(pqueue_, data, priority); - } - bool not_empty() { return fossil_pqueue_not_empty(pqueue_); } diff --git a/code/logic/fossil/tofu/queue.h b/code/logic/fossil/tofu/queue.h index 67362ec..0189b04 100644 --- a/code/logic/fossil/tofu/queue.h +++ b/code/logic/fossil/tofu/queue.h @@ -90,26 +90,6 @@ int32_t fossil_queue_search(const fossil_queue_t* queue, fossil_tofu_t data); */ size_t fossil_queue_size(const fossil_queue_t* queue); -/** - * Get the data from the queue matching the specified data. - * - * @param queue The queue from which to get the data. - * @param data The data to search for. - * @return A pointer to the matching data, or NULL if not found. - * @note Time complexity: O(n) - */ -fossil_tofu_t* fossil_queue_getter(fossil_queue_t* queue, fossil_tofu_t data); - -/** - * Set data in the queue. - * - * @param queue The queue in which to set the data. - * @param data The data to set. - * @return The error code indicating the success or failure of the operation. - * @note Time complexity: O(n) - */ -int32_t fossil_queue_setter(fossil_queue_t* queue, fossil_tofu_t data); - /** * Check if the queue is not empty. * @@ -181,14 +161,6 @@ namespace fossil { return fossil_queue_size(queue_); } - fossil_tofu_t* getter(fossil_tofu_t data) { - return fossil_queue_getter(queue_, data); - } - - void setter(fossil_tofu_t data) { - fossil_queue_setter(queue_, data); - } - bool not_empty() { return fossil_queue_not_empty(queue_); } diff --git a/code/logic/fossil/tofu/setof.h b/code/logic/fossil/tofu/setof.h index b9a9e64..282ecfb 100644 --- a/code/logic/fossil/tofu/setof.h +++ b/code/logic/fossil/tofu/setof.h @@ -89,26 +89,6 @@ int32_t fossil_set_search(const fossil_set_t* set, fossil_tofu_t data); */ size_t fossil_set_size(const fossil_set_t* set); -/** - * Get the data from the set matching the specified data. - * - * @param set The set from which to get the data. - * @param data The data to search for. - * @return A pointer to the matching data, or NULL if not found. - * @note O(n) - Linear time complexity, where n is the number of elements in the set. - */ -fossil_tofu_t* fossil_set_getter(fossil_set_t* set, fossil_tofu_t data); - -/** - * Set data in the set. - * - * @param set The set in which to set the data. - * @param data The data to set. - * @return The error code indicating the success or failure of the operation. - * @note O(n) - Linear time complexity, where n is the number of elements in the set. - */ -int32_t fossil_set_setter(fossil_set_t* set, fossil_tofu_t data); - /** * Check if the set is not empty. * @@ -188,14 +168,6 @@ namespace fossil { return fossil_set_size(set_); } - fossil_tofu_t* getter(fossil_tofu_t data) { - return fossil_set_getter(set_, data); - } - - void setter(fossil_tofu_t data) { - fossil_set_setter(set_, data); - } - bool not_empty() { return fossil_set_not_empty(set_); } diff --git a/code/logic/fossil/tofu/stack.h b/code/logic/fossil/tofu/stack.h index 2a872ea..b0c71ae 100644 --- a/code/logic/fossil/tofu/stack.h +++ b/code/logic/fossil/tofu/stack.h @@ -88,26 +88,6 @@ int32_t fossil_stack_search(const fossil_stack_t* stack, fossil_tofu_t data); */ size_t fossil_stack_size(const fossil_stack_t* stack); -/** - * Get the data from the stack matching the specified data. - * - * @param stack The stack from which to get the data. - * @param data The data to search for. - * @return A pointer to the matching data, or NULL if not found. - * @note Time complexity: O(n) - */ -fossil_tofu_t* fossil_stack_getter(fossil_stack_t* stack, fossil_tofu_t data); - -/** - * Set data in the stack. - * - * @param stack The stack in which to set the data. - * @param data The data to set. - * @return The error code indicating the success or failure of the operation. - * @note Time complexity: O(n) - */ -int32_t fossil_stack_setter(fossil_stack_t* stack, fossil_tofu_t data); - /** * Check if the stack is not empty. * @@ -189,14 +169,6 @@ namespace fossil { return fossil_stack_size(stack_); } - fossil_tofu_t* getter(fossil_tofu_t data) { - return fossil_stack_getter(stack_, data); - } - - void setter(fossil_tofu_t data) { - fossil_stack_setter(stack_, data); - } - bool not_empty() { return fossil_stack_not_empty(stack_); } diff --git a/code/logic/fossil/tofu/vector.h b/code/logic/fossil/tofu/vector.h index ef33059..9d3760b 100644 --- a/code/logic/fossil/tofu/vector.h +++ b/code/logic/fossil/tofu/vector.h @@ -188,28 +188,6 @@ bool fossil_vector_is_empty(const fossil_vector_t* vector); */ bool fossil_vector_not_empty(const fossil_vector_t* vector); -/** - * Set the element at the specified index in the vector. - * - * Time complexity: O(1) - * - * @param vector The vector in which to set the element. - * @param index The index at which to set the element. - * @param element The element to set. - */ -void fossil_vector_setter(fossil_vector_t* vector, size_t index, fossil_tofu_t element); - -/** - * Get the element at the specified index in the vector. - * - * Time complexity: O(1) - * - * @param vector The vector from which to get the element. - * @param index The index from which to get the element. - * @return The element at the specified index. - */ -fossil_tofu_t* fossil_vector_getter(const fossil_vector_t* vector, size_t index); - /** * Get the size of the vector. * @@ -304,14 +282,6 @@ namespace fossil { return fossil_vector_not_empty(vector_); } - void setter(size_t index, fossil_tofu_t element) { - fossil_vector_setter(vector_, index, element); - } - - fossil_tofu_t* getter(size_t index) { - return fossil_vector_getter(vector_, index); - } - size_t size() { return fossil_vector_size(vector_); } diff --git a/code/logic/pqueue.c b/code/logic/pqueue.c index 458fe63..98d48c7 100644 --- a/code/logic/pqueue.c +++ b/code/logic/pqueue.c @@ -150,39 +150,6 @@ size_t fossil_pqueue_size(const fossil_pqueue_t* pqueue) { return count; } -fossil_tofu_t* fossil_pqueue_getter(fossil_pqueue_t* pqueue, fossil_tofu_t data, int32_t priority) { - if (!pqueue) { - fprintf(stderr, "Error: pqueue cannot be NULL\n"); - return NULL; - } - - fossil_pqueue_node_t* current = pqueue->front; - while (current) { - if (current->priority == priority && fossil_tofu_equals(current->data, data)) { - return &(current->data); // Return pointer to found data - } - current = current->next; - } - return NULL; // Not found -} - -int32_t fossil_pqueue_setter(fossil_pqueue_t* pqueue, fossil_tofu_t data, int32_t priority) { - if (!pqueue) { - fprintf(stderr, "Error: pqueue cannot be NULL\n"); - return FOSSIL_TOFU_FAILURE; - } - - fossil_pqueue_node_t* current = pqueue->front; - while (current) { - if (current->priority == priority && fossil_tofu_equals(current->data, data)) { - current->data = data; // Update data - return FOSSIL_TOFU_SUCCESS; // Success - } - current = current->next; - } - return FOSSIL_TOFU_FAILURE; // Not found -} - bool fossil_pqueue_not_empty(const fossil_pqueue_t* pqueue) { if (!pqueue) { fprintf(stderr, "Error: pqueue cannot be NULL\n"); diff --git a/code/logic/queue.c b/code/logic/queue.c index c3fb308..3b69ae4 100644 --- a/code/logic/queue.c +++ b/code/logic/queue.c @@ -137,39 +137,6 @@ size_t fossil_queue_size(const fossil_queue_t* queue) { return count; } -fossil_tofu_t* fossil_queue_getter(fossil_queue_t* queue, fossil_tofu_t data) { - if (!queue) { - fprintf(stderr, "Error: Cannot get data from a NULL queue.\n"); - return NULL; - } - - fossil_queue_node_t* current = queue->front; - while (current) { - if (fossil_tofu_equals(current->data, data)) { - return &(current->data); // Return pointer to found data - } - current = current->next; - } - return NULL; // Not found -} - -int32_t fossil_queue_setter(fossil_queue_t* queue, fossil_tofu_t data) { - if (!queue) { - fprintf(stderr, "Error: Cannot set data in a NULL queue.\n"); - return FOSSIL_TOFU_FAILURE; - } - - fossil_queue_node_t* current = queue->front; - while (current) { - if (fossil_tofu_equals(current->data, data)) { - current->data = data; // Update data - return FOSSIL_TOFU_SUCCESS; // Success - } - current = current->next; - } - return FOSSIL_TOFU_FAILURE; // Not found -} - bool fossil_queue_not_empty(const fossil_queue_t* queue) { if (!queue) { fprintf(stderr, "Error: Cannot check if a NULL queue is not empty.\n"); diff --git a/code/logic/setof.c b/code/logic/setof.c index f34c7ab..ec88e01 100644 --- a/code/logic/setof.c +++ b/code/logic/setof.c @@ -137,39 +137,6 @@ size_t fossil_set_size(const fossil_set_t* set) { return count; } -fossil_tofu_t* fossil_set_getter(fossil_set_t* set, fossil_tofu_t data) { - if (!set) { - fprintf(stderr, "Error: set cannot be NULL\n"); - return NULL; - } - - fossil_set_node_t* current = set->head; - while (current) { - if (fossil_tofu_equals(current->data, data)) { - return &(current->data); // Return pointer to found data - } - current = current->next; - } - return NULL; // Not found -} - -int32_t fossil_set_setter(fossil_set_t* set, fossil_tofu_t data) { - if (!set) { - fprintf(stderr, "Error: set cannot be NULL\n"); - return -1; - } - - fossil_set_node_t* current = set->head; - while (current) { - if (fossil_tofu_equals(current->data, data)) { - current->data = data; // Update data - return FOSSIL_TOFU_SUCCESS; // Success - } - current = current->next; - } - return FOSSIL_TOFU_FAILURE; // Not found -} - bool fossil_set_not_empty(const fossil_set_t* set) { if (!set) { fprintf(stderr, "Error: set cannot be NULL\n"); diff --git a/code/logic/stack.c b/code/logic/stack.c index 1d0e5e7..cca1b21 100644 --- a/code/logic/stack.c +++ b/code/logic/stack.c @@ -105,37 +105,6 @@ size_t fossil_stack_size(const fossil_stack_t* stack) { return count; } -fossil_tofu_t* fossil_stack_getter(fossil_stack_t* stack, fossil_tofu_t data) { - if (!stack) { - return NULL; // Error: stack is NULL - } - - fossil_stack_node_t* current = stack->top; - while (current) { - if (fossil_tofu_equals(current->data, data)) { - return &(current->data); // Return pointer to found data - } - current = current->next; - } - return NULL; // Not found -} - -int32_t fossil_stack_setter(fossil_stack_t* stack, fossil_tofu_t data) { - if (!stack) { - return FOSSIL_TOFU_FAILURE; // Error: stack is NULL - } - - fossil_stack_node_t* current = stack->top; - while (current) { - if (fossil_tofu_equals(current->data, data)) { - current->data = data; // Update data - return FOSSIL_TOFU_SUCCESS; // Success - } - current = current->next; - } - return FOSSIL_TOFU_FAILURE; // Not found -} - bool fossil_stack_not_empty(const fossil_stack_t* stack) { if (!stack) { return false; // Error: stack is NULL diff --git a/code/logic/vector.c b/code/logic/vector.c index c0a2be0..717fcdb 100644 --- a/code/logic/vector.c +++ b/code/logic/vector.c @@ -43,7 +43,6 @@ void fossil_vector_destroy(fossil_vector_t* vector) { vector->data = NULL; vector->size = 0; vector->capacity = 0; - fossil_tofu_free(vector->type); // Free the duplicated type string fossil_tofu_free(vector); } @@ -264,33 +263,6 @@ bool fossil_vector_not_empty(const fossil_vector_t* vector) { return vector->size != 0; } -void fossil_vector_setter(fossil_vector_t* vector, size_t index, fossil_tofu_t element) { - if (!vector) { - fprintf(stderr, "Error: Attempt to set an element in a null vector.\n"); - return; - } - - if (index < vector->size) { - vector->data[index] = element; - } else { - fprintf(stderr, "Error: Attempt to set an element at an out-of-bounds index.\n"); - } -} - -fossil_tofu_t* fossil_vector_getter(const fossil_vector_t* vector, size_t index) { - if (!vector) { - fprintf(stderr, "Error: Attempt to get an element from a null vector.\n"); - return NULL; - } - - if (index < vector->size) { - return &(vector->data[index]); - } else { - fprintf(stderr, "Error: Attempt to get an element at an out-of-bounds index.\n"); - return NULL; - } -} - size_t fossil_vector_size(const fossil_vector_t* vector) { if (!vector) { fprintf(stderr, "Error: Attempt to get the size of a null vector.\n"); diff --git a/code/tests/test_doublylist.c b/code/tests/test_doublylist.c index a398ed2..623fb20 100644 --- a/code/tests/test_doublylist.c +++ b/code/tests/test_doublylist.c @@ -93,18 +93,9 @@ FOSSIL_TEST(test_dlist_reverse_forward) { // Reverse the doubly linked list forward fossil_dlist_reverse_forward(mock_dlist); - // Check if the elements are in reverse order - fossil_tofu_t* retrievedElement = fossil_dlist_getter(mock_dlist, element3); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(5, retrievedElement->value.int_val); // Updated to reflect correct order - - retrievedElement = fossil_dlist_getter(mock_dlist, element2); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(10, retrievedElement->value.int_val); - - retrievedElement = fossil_dlist_getter(mock_dlist, element1); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(42, retrievedElement->value.int_val); + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); } FOSSIL_TEST(test_dlist_reverse_backward) { @@ -120,18 +111,9 @@ FOSSIL_TEST(test_dlist_reverse_backward) { // Reverse the doubly linked list backward fossil_dlist_reverse_backward(mock_dlist); - // Check if the elements are in reverse order - fossil_tofu_t* retrievedElement = fossil_dlist_getter(mock_dlist, element3); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(5, retrievedElement->value.int_val); // Updated to reflect correct order - - retrievedElement = fossil_dlist_getter(mock_dlist, element2); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(10, retrievedElement->value.int_val); - - retrievedElement = fossil_dlist_getter(mock_dlist, element1); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(42, retrievedElement->value.int_val); + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); } // benchmarking cases to capture the true diff --git a/code/tests/test_dqueue.c b/code/tests/test_dqueue.c index 4dc0ec9..26f521f 100644 --- a/code/tests/test_dqueue.c +++ b/code/tests/test_dqueue.c @@ -50,7 +50,19 @@ FOSSIL_TEST(test_dqueue_create_and_destroy) { ASSUME_ITS_CNULL(mock_dqueue->rear); } -FOSSIL_TEST(test_dqueue_insert_and_size) { +FOSSIL_TEST(test_dqueue_insert) { + // Insert an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + fossil_dqueue_insert(mock_dqueue, element); + + // Check if the element is inserted + ASSUME_NOT_CNULL(mock_dqueue->front); + ASSUME_NOT_CNULL(mock_dqueue->rear); + + fossil_tofu_destroy(&element); +} + +FOSSIL_TEST(test_dqueue_size) { // Insert some elements fossil_tofu_t element1 = fossil_tofu_create("int", "42"); fossil_tofu_t element2 = fossil_tofu_create("int", "10"); @@ -85,26 +97,6 @@ FOSSIL_TEST(test_dqueue_remove) { ASSUME_ITS_EQUAL_SIZE(2, fossil_dqueue_size(mock_dqueue)); } -FOSSIL_TEST(test_dqueue_getter_and_setter) { - // Insert an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - ASSUME_ITS_TRUE(fossil_dqueue_insert(mock_dqueue, element)); - - // Get the value for an element - fossil_tofu_t* retrievedElement = fossil_dqueue_getter(mock_dqueue, element); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(42, retrievedElement->value.int_val); - - // Update the value for an element - fossil_tofu_t updatedElement = fossil_tofu_create("int", "50"); - ASSUME_ITS_TRUE(fossil_dqueue_setter(mock_dqueue, updatedElement)); - - // Get the updated value for the element - retrievedElement = fossil_dqueue_getter(mock_dqueue, updatedElement); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(50, retrievedElement->value.int_val); -} - FOSSIL_TEST(test_dqueue_not_empty_and_is_empty) { // Check initially empty ASSUME_ITS_FALSE(fossil_dqueue_not_empty(mock_dqueue)); @@ -153,9 +145,9 @@ FOSSIL_TEST(stress_test_dqueue) { // * * * * * * * * * * * * * * * * * * * * * * * * FOSSIL_TEST_GROUP(c_dqueue_structure_tests) { ADD_TESTF(test_dqueue_create_and_destroy, struct_dqueue_fixture); - ADD_TESTF(test_dqueue_insert_and_size, struct_dqueue_fixture); + ADD_TESTF(test_dqueue_insert, struct_dqueue_fixture); + ADD_TESTF(test_dqueue_size, struct_dqueue_fixture); ADD_TESTF(test_dqueue_remove, struct_dqueue_fixture); - //ADD_TESTF(test_dqueue_getter_and_setter, struct_dqueue_fixture); ADD_TESTF(test_dqueue_not_empty_and_is_empty, struct_dqueue_fixture); // Benchmarking cases diff --git a/code/tests/test_forwardlist.c b/code/tests/test_forwardlist.c index 55c242d..727c825 100644 --- a/code/tests/test_forwardlist.c +++ b/code/tests/test_forwardlist.c @@ -48,18 +48,10 @@ FOSSIL_TEST(test_flist_create_and_destroy) { ASSUME_ITS_CNULL(mock_flist->head); } -FOSSIL_TEST(test_flist_insert_and_size) { - // Insert some elements - fossil_tofu_t element1 = fossil_tofu_create("int", "42"); - fossil_tofu_t element2 = fossil_tofu_create("int", "10"); - fossil_tofu_t element3 = fossil_tofu_create("int", "5"); - - ASSUME_ITS_TRUE(fossil_flist_insert(mock_flist, element1) == 0); - ASSUME_ITS_TRUE(fossil_flist_insert(mock_flist, element2) == 0); - ASSUME_ITS_TRUE(fossil_flist_insert(mock_flist, element3) == 0); - - // Check if the size is correct - ASSUME_ITS_EQUAL_SIZE(3, fossil_flist_size(mock_flist)); +FOSSIL_TEST(test_flist_insert) { + // Insert an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + ASSUME_ITS_TRUE(fossil_flist_insert(mock_flist, element) == 0); } FOSSIL_TEST(test_flist_remove) { @@ -83,6 +75,36 @@ FOSSIL_TEST(test_flist_remove) { ASSUME_ITS_EQUAL_SIZE(2, fossil_flist_size(mock_flist)); } +FOSSIL_TEST(test_flist_size) { + // Insert some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + ASSUME_ITS_TRUE(fossil_flist_insert(mock_flist, element1) == 0); + ASSUME_ITS_TRUE(fossil_flist_insert(mock_flist, element2) == 0); + ASSUME_ITS_TRUE(fossil_flist_insert(mock_flist, element3) == 0); + + // Check if the size is correct + ASSUME_ITS_EQUAL_SIZE(3, fossil_flist_size(mock_flist)); +} + +FOSSIL_TEST(test_flist_search) { + // Insert an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + fossil_flist_insert(mock_flist, element); + + // Search for the element + ASSUME_ITS_TRUE(fossil_flist_search(mock_flist, element) == 0); + + // Search for a non-existent element + fossil_tofu_t nonExistentElement = fossil_tofu_create("int", "100"); + ASSUME_ITS_TRUE(fossil_flist_search(mock_flist, nonExistentElement) == -1); + + fossil_tofu_destroy(&nonExistentElement); + fossil_tofu_destroy(&element); +} + FOSSIL_TEST(test_flist_reverse_forward) { // Insert some elements fossil_tofu_t element1 = fossil_tofu_create("int", "42"); @@ -96,18 +118,9 @@ FOSSIL_TEST(test_flist_reverse_forward) { // Reverse the linked list forward fossil_flist_reverse_forward(mock_flist); - // Check if the elements are in reverse order - fossil_tofu_t* retrievedElement = fossil_flist_getter(mock_flist, element3); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(5, retrievedElement->value.int_val); - - retrievedElement = fossil_flist_getter(mock_flist, element2); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(10, retrievedElement->value.int_val); - - retrievedElement = fossil_flist_getter(mock_flist, element1); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(42, retrievedElement->value.int_val); + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); } FOSSIL_TEST(test_flist_reverse_backward) { @@ -123,20 +136,50 @@ FOSSIL_TEST(test_flist_reverse_backward) { // Reverse the linked list backward fossil_flist_reverse_backward(mock_flist); - // Check if the elements are in reverse order - fossil_tofu_t* retrievedElement = fossil_flist_getter(mock_flist, element3); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(5, retrievedElement->value.int_val); + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); +} + +FOSSIL_TEST(test_flist_is_empty) { + // Check initially empty + ASSUME_ITS_TRUE(fossil_flist_is_empty(mock_flist)); - retrievedElement = fossil_flist_getter(mock_flist, element2); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(10, retrievedElement->value.int_val); + // Insert an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + fossil_flist_insert(mock_flist, element); + + // Check if the linked list is not empty + ASSUME_ITS_FALSE(fossil_flist_is_empty(mock_flist)); - retrievedElement = fossil_flist_getter(mock_flist, element1); - ASSUME_NOT_CNULL(retrievedElement); - ASSUME_ITS_EQUAL_I32(42, retrievedElement->value.int_val); + fossil_tofu_destroy(&element); } +FOSSIL_TEST(test_flist_not_empty) { + // Check initially not empty + ASSUME_ITS_FALSE(fossil_flist_not_empty(mock_flist)); + + // Insert an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + fossil_flist_insert(mock_flist, element); + + // Check if the linked list is not empty + ASSUME_ITS_TRUE(fossil_flist_not_empty(mock_flist)); + + fossil_tofu_destroy(&element); +} + +FOSSIL_TEST(test_flist_is_cnullptr) { + // Check initially cnullptr + ASSUME_ITS_FALSE(fossil_flist_is_cnullptr(mock_flist)); +} + +FOSSIL_TEST(test_flist_not_cnullptr) { + // Check initially not cnullptr + ASSUME_ITS_TRUE(fossil_flist_not_cnullptr(mock_flist)); +} + + // benchmarking cases to capture the true // performence based on current structures // implmentation. @@ -164,10 +207,16 @@ FOSSIL_TEST(stress_test_flist) { // * * * * * * * * * * * * * * * * * * * * * * * * FOSSIL_TEST_GROUP(c_flist_structure_tests) { ADD_TESTF(test_flist_create_and_destroy, struct_flist_fixture); - ADD_TESTF(test_flist_insert_and_size, struct_flist_fixture); + ADD_TESTF(test_flist_insert, struct_flist_fixture); ADD_TESTF(test_flist_remove, struct_flist_fixture); + ADD_TESTF(test_flist_size, struct_flist_fixture); + ADD_TESTF(test_flist_search, struct_flist_fixture); ADD_TESTF(test_flist_reverse_forward, struct_flist_fixture); ADD_TESTF(test_flist_reverse_backward, struct_flist_fixture); + ADD_TESTF(test_flist_is_cnullptr, struct_flist_fixture); + ADD_TESTF(test_flist_not_cnullptr, struct_flist_fixture); + ADD_TESTF(test_flist_is_empty, struct_flist_fixture); + ADD_TESTF(test_flist_not_empty, struct_flist_fixture); // Benchmarking cases ADD_TESTF(stress_test_flist, struct_flist_fixture); diff --git a/code/tests/test_pqueue.c b/code/tests/test_pqueue.c index 436a8ab..6c5367b 100644 --- a/code/tests/test_pqueue.c +++ b/code/tests/test_pqueue.c @@ -49,18 +49,10 @@ FOSSIL_TEST(test_pqueue_create_and_destroy) { ASSUME_ITS_CNULL(mock_pqueue->front); } -FOSSIL_TEST(test_pqueue_insert_and_size) { - // Insert some elements - fossil_tofu_t element1 = fossil_tofu_create("int", "42"); - fossil_tofu_t element2 = fossil_tofu_create("int", "10"); - fossil_tofu_t element3 = fossil_tofu_create("int", "5"); - - ASSUME_ITS_TRUE(fossil_pqueue_insert(mock_pqueue, element1, 2) == 0); - ASSUME_ITS_TRUE(fossil_pqueue_insert(mock_pqueue, element2, 1) == 0); - ASSUME_ITS_TRUE(fossil_pqueue_insert(mock_pqueue, element3, 3) == 0); - - // Check if the size is correct - ASSUME_ITS_EQUAL_SIZE(3, fossil_pqueue_size(mock_pqueue)); +FOSSIL_TEST(test_pqueue_insert) { + // Insert an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + ASSUME_ITS_TRUE(fossil_pqueue_insert(mock_pqueue, element, 2) == 0); } FOSSIL_TEST(test_pqueue_remove) { @@ -79,22 +71,47 @@ FOSSIL_TEST(test_pqueue_remove) { ASSUME_ITS_TRUE(fossil_pqueue_remove(mock_pqueue, &removedElement, removedPriority)); } -FOSSIL_TEST(test_pqueue_not_empty_and_is_empty) { - // Check initially not empty - ASSUME_ITS_FALSE(fossil_pqueue_not_empty(mock_pqueue)); - ASSUME_ITS_TRUE(fossil_pqueue_is_empty(mock_pqueue)); - +FOSSIL_TEST(test_pqueue_search) { // Insert an element fossil_tofu_t element = fossil_tofu_create("int", "42"); - ASSUME_ITS_TRUE(fossil_pqueue_insert(mock_pqueue, element, 2) == 0); + fossil_pqueue_insert(mock_pqueue, element, 2); - // Check not empty after insertion - ASSUME_ITS_TRUE(fossil_pqueue_not_empty(mock_pqueue)); + // Search for the element + ASSUME_ITS_TRUE(fossil_pqueue_search(mock_pqueue, element, 2) == 0); +} - // Remove the element - fossil_tofu_t removedElement; - int removedPriority = 0; - ASSUME_ITS_TRUE(fossil_pqueue_remove(mock_pqueue, &removedElement, removedPriority)); +FOSSIL_TEST(test_pqueue_size) { + // Insert some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + ASSUME_ITS_TRUE(fossil_pqueue_insert(mock_pqueue, element1, 2) == 0); + ASSUME_ITS_TRUE(fossil_pqueue_insert(mock_pqueue, element2, 1) == 0); + ASSUME_ITS_TRUE(fossil_pqueue_insert(mock_pqueue, element3, 3) == 0); + + // Check if the size is correct + ASSUME_ITS_EQUAL_SIZE(3, fossil_pqueue_size(mock_pqueue)); +} + +FOSSIL_TEST(test_pqueue_is_cnullptr) { + // Check initially cnullptr + ASSUME_ITS_FALSE(fossil_pqueue_is_cnullptr(mock_pqueue)); +} + +FOSSIL_TEST(test_pqueue_not_cnullptr) { + // Check initially not cnullptr + ASSUME_ITS_TRUE(fossil_pqueue_not_cnullptr(mock_pqueue)); +} + +FOSSIL_TEST(test_pqueue_is_empty) { + // Check initially empty + ASSUME_ITS_TRUE(fossil_pqueue_is_empty(mock_pqueue)); +} + +FOSSIL_TEST(test_pqueue_not_empty) { + // Check initially not empty + ASSUME_ITS_FALSE(fossil_pqueue_not_empty(mock_pqueue)); } // benchmarking cases to capture the true @@ -125,9 +142,14 @@ FOSSIL_TEST(stress_test_pqueue) { FOSSIL_TEST_GROUP(c_pqueue_structure_tests) { // Priority Queue Fixture ADD_TESTF(test_pqueue_create_and_destroy, struct_pqueue_fixture); - ADD_TESTF(test_pqueue_insert_and_size, struct_pqueue_fixture); + ADD_TESTF(test_pqueue_insert, struct_pqueue_fixture); ADD_TESTF(test_pqueue_remove, struct_pqueue_fixture); - ADD_TESTF(test_pqueue_not_empty_and_is_empty, struct_pqueue_fixture); + ADD_TESTF(test_pqueue_search, struct_pqueue_fixture); + ADD_TESTF(test_pqueue_size, struct_pqueue_fixture); + ADD_TESTF(test_pqueue_is_cnullptr, struct_pqueue_fixture); + ADD_TESTF(test_pqueue_not_cnullptr, struct_pqueue_fixture); + ADD_TESTF(test_pqueue_is_empty, struct_pqueue_fixture); + ADD_TESTF(test_pqueue_not_empty, struct_pqueue_fixture); // Benchmarking ADD_TESTF(stress_test_pqueue, struct_pqueue_fixture); diff --git a/code/tests/test_queue.c b/code/tests/test_queue.c index bef7248..31ececa 100644 --- a/code/tests/test_queue.c +++ b/code/tests/test_queue.c @@ -50,18 +50,13 @@ FOSSIL_TEST(test_queue_create_and_destroy) { ASSUME_ITS_CNULL(mock_queue->rear); } -FOSSIL_TEST(test_queue_insert_and_size) { - // Insert some elements - fossil_tofu_t element1 = fossil_tofu_create("int", "42"); - fossil_tofu_t element2 = fossil_tofu_create("int", "10"); - fossil_tofu_t element3 = fossil_tofu_create("int", "5"); +FOSSIL_TEST(test_queue_insert) { + // Insert an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); - ASSUME_ITS_TRUE(fossil_queue_insert(mock_queue, element1) == 0); - ASSUME_ITS_TRUE(fossil_queue_insert(mock_queue, element2) == 0); - ASSUME_ITS_TRUE(fossil_queue_insert(mock_queue, element3) == 0); + ASSUME_ITS_TRUE(fossil_queue_insert(mock_queue, element) == 0); - // Check if the size is correct - ASSUME_ITS_EQUAL_SIZE(3, fossil_queue_size(mock_queue)); + fossil_tofu_destroy(&element); } FOSSIL_TEST(test_queue_remove) { @@ -90,19 +85,57 @@ FOSSIL_TEST(test_queue_remove) { fossil_tofu_destroy(&element3); } -FOSSIL_TEST(test_queue_not_empty_and_is_empty) { - // Check initially not empty - ASSUME_ITS_FALSE(fossil_queue_not_empty(mock_queue)); +FOSSIL_TEST(test_queue_search) { + // Insert some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_queue_insert(mock_queue, element1); + fossil_queue_insert(mock_queue, element2); + fossil_queue_insert(mock_queue, element3); + + // Check if the elements are in the queue + ASSUME_ITS_TRUE(fossil_queue_search(mock_queue, element1) == 0); + ASSUME_ITS_TRUE(fossil_queue_search(mock_queue, element3) == 0); + + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); +} + +FOSSIL_TEST(test_queue_is_cnullptr) { + // Check if the queue is a nullptr + ASSUME_ITS_FALSE(fossil_queue_is_cnullptr(mock_queue)); +} + +FOSSIL_TEST(test_queue_not_cnullptr) { + // Check if the queue is not a nullptr + ASSUME_ITS_TRUE(fossil_queue_not_cnullptr(mock_queue)); +} + +FOSSIL_TEST(test_queue_is_empty) { + // Check if the queue is empty ASSUME_ITS_TRUE(fossil_queue_is_empty(mock_queue)); +} - // Insert an element - fossil_tofu_t element = fossil_tofu_create("int", "42"); - ASSUME_ITS_TRUE(fossil_queue_insert(mock_queue, element) == 0); +FOSSIL_TEST(test_queue_not_empty) { + // Check if the queue is not empty + ASSUME_ITS_FALSE(fossil_queue_not_empty(mock_queue)); +} - // Check not empty after insertion - ASSUME_ITS_FALSE(fossil_queue_is_empty(mock_queue)); +FOSSIL_TEST(test_queue_size) { + // Insert some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); - fossil_tofu_destroy(&element); + ASSUME_ITS_TRUE(fossil_queue_insert(mock_queue, element1) == 0); + ASSUME_ITS_TRUE(fossil_queue_insert(mock_queue, element2) == 0); + ASSUME_ITS_TRUE(fossil_queue_insert(mock_queue, element3) == 0); + + // Check if the size is correct + ASSUME_ITS_EQUAL_SIZE(3, fossil_queue_size(mock_queue)); } // benchmarking cases to capture the true @@ -133,9 +166,14 @@ FOSSIL_TEST(stress_test_queue) { FOSSIL_TEST_GROUP(c_structure_tests) { // Queue Fixture ADD_TESTF(test_queue_create_and_destroy, struct_queue_fixture); - ADD_TESTF(test_queue_insert_and_size, struct_queue_fixture); + ADD_TESTF(test_queue_insert, struct_queue_fixture); ADD_TESTF(test_queue_remove, struct_queue_fixture); - ADD_TESTF(test_queue_not_empty_and_is_empty, struct_queue_fixture); + ADD_TESTF(test_queue_search, struct_queue_fixture); + ADD_TESTF(test_queue_is_cnullptr, struct_queue_fixture); + ADD_TESTF(test_queue_not_cnullptr, struct_queue_fixture); + ADD_TESTF(test_queue_is_empty, struct_queue_fixture); + ADD_TESTF(test_queue_not_empty, struct_queue_fixture); + ADD_TESTF(test_queue_size, struct_queue_fixture); // Benchmarking ADD_TESTF(stress_test_queue, struct_queue_fixture); diff --git a/code/tests/test_setof.c b/code/tests/test_setof.c index f9ddc2a..0b876d9 100644 --- a/code/tests/test_setof.c +++ b/code/tests/test_setof.c @@ -49,25 +49,33 @@ FOSSIL_TEST(test_set_create_and_destroy) { ASSUME_ITS_CNULL(mock_set->head); } -FOSSIL_TEST(test_set_insert_and_size) { +FOSSIL_TEST(test_set_insert) { + // Insert an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + ASSUME_ITS_TRUE(fossil_set_insert(mock_set, element) == 0); + + fossil_tofu_destroy(&element); +} + +FOSSIL_TEST(test_set_remove) { // Insert some elements fossil_tofu_t element1 = fossil_tofu_create("int", "42"); fossil_tofu_t element2 = fossil_tofu_create("int", "10"); fossil_tofu_t element3 = fossil_tofu_create("int", "5"); - ASSUME_ITS_TRUE(fossil_set_insert(mock_set, element1) == 0); - ASSUME_ITS_TRUE(fossil_set_insert(mock_set, element2) == 0); - ASSUME_ITS_TRUE(fossil_set_insert(mock_set, element3) == 0); + fossil_set_insert(mock_set, element1); + fossil_set_insert(mock_set, element2); + fossil_set_insert(mock_set, element3); - // Check if the size is correct - ASSUME_ITS_EQUAL_SIZE(3, fossil_set_size(mock_set)); + // Remove an element + ASSUME_ITS_TRUE(fossil_set_remove(mock_set, element2) == 0); - fossil_tofu_destroy(&element1); - fossil_tofu_destroy(&element2); - fossil_tofu_destroy(&element3); + // Check if the size is correct + ASSUME_ITS_EQUAL_SIZE(2, fossil_set_size(mock_set)); } -FOSSIL_TEST(test_set_remove) { +FOSSIL_TEST(test_set_search) { // Insert some elements fossil_tofu_t element1 = fossil_tofu_create("int", "42"); fossil_tofu_t element2 = fossil_tofu_create("int", "10"); @@ -77,11 +85,35 @@ FOSSIL_TEST(test_set_remove) { fossil_set_insert(mock_set, element2); fossil_set_insert(mock_set, element3); - // Remove an element - ASSUME_ITS_TRUE(fossil_set_remove(mock_set, element2) == 0); + // Search for an element + ASSUME_ITS_TRUE(fossil_set_search(mock_set, element1) == 0); + + // Check for non-existing element + fossil_tofu_t nonExistingElement = fossil_tofu_create("int", "44"); + ASSUME_NOT_TRUE(fossil_set_search(mock_set, nonExistingElement) == 1); + + fossil_tofu_destroy(&nonExistingElement); + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); +} + +FOSSIL_TEST(test_set_size) { + // Insert some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + ASSUME_ITS_TRUE(fossil_set_insert(mock_set, element1) == 0); + ASSUME_ITS_TRUE(fossil_set_insert(mock_set, element2) == 0); + ASSUME_ITS_TRUE(fossil_set_insert(mock_set, element3) == 0); // Check if the size is correct - ASSUME_ITS_EQUAL_SIZE(2, fossil_set_size(mock_set)); + ASSUME_ITS_EQUAL_SIZE(3, fossil_set_size(mock_set)); + + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); } FOSSIL_TEST(test_set_contains) { @@ -108,6 +140,26 @@ FOSSIL_TEST(test_set_contains) { fossil_tofu_destroy(&element3); } +FOSSIL_TEST(test_set_is_cnullptr) { + // Check if the set is not a nullptr + ASSUME_ITS_FALSE(fossil_set_is_cnullptr(mock_set)); +} + +FOSSIL_TEST(test_set_not_cnullptr) { + // Check if the set is not a nullptr + ASSUME_ITS_TRUE(fossil_set_not_cnullptr(mock_set)); +} + +FOSSIL_TEST(test_set_is_empty) { + // Check if the set is empty + ASSUME_ITS_TRUE(fossil_set_is_empty(mock_set)); +} + +FOSSIL_TEST(test_set_not_empty) { + // Check if the set is empty + ASSUME_ITS_FALSE(fossil_set_not_empty(mock_set)); +} + // benchmarking cases to capture the true // performence based on current structures // implmentation. @@ -136,9 +188,15 @@ FOSSIL_TEST(stress_test_set) { FOSSIL_TEST_GROUP(c_setof_structure_tests) { // Set Fixture ADD_TESTF(test_set_create_and_destroy, struct_set_fixture); - ADD_TESTF(test_set_insert_and_size, struct_set_fixture); + ADD_TESTF(test_set_insert, struct_set_fixture); ADD_TESTF(test_set_remove, struct_set_fixture); + ADD_TESTF(test_set_search, struct_set_fixture); + ADD_TESTF(test_set_size, struct_set_fixture); ADD_TESTF(test_set_contains, struct_set_fixture); + ADD_TESTF(test_set_is_cnullptr, struct_set_fixture); + ADD_TESTF(test_set_not_cnullptr, struct_set_fixture); + ADD_TESTF(test_set_is_empty, struct_set_fixture); + ADD_TESTF(test_set_not_empty, struct_set_fixture); // Benchmarking ADD_TESTF(stress_test_set, struct_set_fixture); diff --git a/code/tests/test_stack.c b/code/tests/test_stack.c index 321e147..870ebbf 100644 --- a/code/tests/test_stack.c +++ b/code/tests/test_stack.c @@ -49,25 +49,42 @@ FOSSIL_TEST(test_stack_create_and_destroy) { ASSUME_ITS_CNULL(mock_stack->top); } -FOSSIL_TEST(test_stack_insert_and_size) { +FOSSIL_TEST(test_stack_insert) { + // Insert an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + + // Check if the element is inserted correctly + ASSUME_ITS_TRUE(fossil_stack_insert(mock_stack, element) == 0); + + fossil_tofu_destroy(&element); +} + +FOSSIL_TEST(test_stack_remove) { // Insert some elements fossil_tofu_t element1 = fossil_tofu_create("int", "42"); fossil_tofu_t element2 = fossil_tofu_create("int", "10"); fossil_tofu_t element3 = fossil_tofu_create("int", "5"); - ASSUME_ITS_TRUE(fossil_stack_insert(mock_stack, element1) == 0); - ASSUME_ITS_TRUE(fossil_stack_insert(mock_stack, element2) == 0); - ASSUME_ITS_TRUE(fossil_stack_insert(mock_stack, element3) == 0); + fossil_stack_insert(mock_stack, element1); + fossil_stack_insert(mock_stack, element2); + fossil_stack_insert(mock_stack, element3); + + // Remove an element + fossil_tofu_t removedElement; + ASSUME_ITS_TRUE(fossil_stack_remove(mock_stack, &removedElement) == 0); + + // Check if the removed element is correct + ASSUME_ITS_EQUAL_I32(5, removedElement.value.int_val); // Check if the size is correct - ASSUME_ITS_EQUAL_SIZE(3, fossil_stack_size(mock_stack)); + ASSUME_ITS_EQUAL_SIZE(2, fossil_stack_size(mock_stack)); fossil_tofu_destroy(&element1); fossil_tofu_destroy(&element2); fossil_tofu_destroy(&element3); } -FOSSIL_TEST(test_stack_remove) { +FOSSIL_TEST(test_stack_search) { // Insert some elements fossil_tofu_t element1 = fossil_tofu_create("int", "42"); fossil_tofu_t element2 = fossil_tofu_create("int", "10"); @@ -77,21 +94,60 @@ FOSSIL_TEST(test_stack_remove) { fossil_stack_insert(mock_stack, element2); fossil_stack_insert(mock_stack, element3); - // Remove an element - fossil_tofu_t removedElement; - ASSUME_ITS_TRUE(fossil_stack_remove(mock_stack, &removedElement) == 0); + // Search for an element + fossil_tofu_t searchElement = fossil_tofu_create("int", "10"); + ASSUME_ITS_TRUE(fossil_stack_search(mock_stack, searchElement) == 0); - // Check if the removed element is correct - ASSUME_ITS_EQUAL_I32(5, removedElement.value.int_val); + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); + fossil_tofu_destroy(&searchElement); +} + +FOSSIL_TEST(test_stack_size) { + // Insert some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_stack_insert(mock_stack, element1); + fossil_stack_insert(mock_stack, element2); + fossil_stack_insert(mock_stack, element3); // Check if the size is correct - ASSUME_ITS_EQUAL_SIZE(2, fossil_stack_size(mock_stack)); + ASSUME_ITS_EQUAL_SIZE(3, fossil_stack_size(mock_stack)); fossil_tofu_destroy(&element1); fossil_tofu_destroy(&element2); fossil_tofu_destroy(&element3); } +FOSSIL_TEST(test_stack_is_empty) { + // Check if the stack is empty + ASSUME_ITS_TRUE(fossil_stack_is_empty(mock_stack)); +} + +FOSSIL_TEST(test_stack_not_empty) { + // Insert an element + fossil_tofu_t element = fossil_tofu_create("int", "42"); + fossil_stack_insert(mock_stack, element); + + // Check if the stack is not empty + ASSUME_ITS_TRUE(fossil_stack_not_empty(mock_stack)); + + fossil_tofu_destroy(&element); +} + +FOSSIL_TEST(test_stack_is_cnullptr) { + // Check if the stack is not a nullptr + ASSUME_ITS_TRUE(fossil_stack_is_cnullptr(mock_stack) == 0); +} + +FOSSIL_TEST(test_stack_not_cnullptr) { + // Check if the stack is not a nullptr + ASSUME_ITS_TRUE(fossil_stack_not_cnullptr(mock_stack)); +} + // benchmarking cases to capture the true // performence based on current structures // implmentation. @@ -121,8 +177,14 @@ FOSSIL_TEST(stress_test_stack) { FOSSIL_TEST_GROUP(c_stack_structure_tests) { // Stack Fixture ADD_TESTF(test_stack_create_and_destroy, struct_stack_fixture); - ADD_TESTF(test_stack_insert_and_size, struct_stack_fixture); + ADD_TESTF(test_stack_insert, struct_stack_fixture); ADD_TESTF(test_stack_remove, struct_stack_fixture); + ADD_TESTF(test_stack_search, struct_stack_fixture); + ADD_TESTF(test_stack_size, struct_stack_fixture); + ADD_TESTF(test_stack_is_empty, struct_stack_fixture); + ADD_TESTF(test_stack_not_empty, struct_stack_fixture); + ADD_TESTF(test_stack_is_cnullptr, struct_stack_fixture); + ADD_TESTF(test_stack_not_cnullptr, struct_stack_fixture); // Stack Benchmark ADD_TESTF(stress_test_stack, struct_stack_fixture); diff --git a/code/tests/test_vector.c b/code/tests/test_vector.c index fdadaef..db73425 100644 --- a/code/tests/test_vector.c +++ b/code/tests/test_vector.c @@ -43,6 +43,27 @@ FOSSIL_TEARDOWN(struct_vect_fixture) { // as samples for library usage. // * * * * * * * * * * * * * * * * * * * * * * * * +FOSSIL_TEST(test_vector_push_front) { + // Push back some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_vector_push_front(mock_vector, element1); + fossil_vector_push_front(mock_vector, element2); + fossil_vector_push_front(mock_vector, element3); + + // Check if the elements are added correctly + ASSUME_ITS_EQUAL_U32(3, mock_vector->size); + ASSUME_ITS_EQUAL_I32(5, mock_vector->data[0].value.int_val); + ASSUME_ITS_EQUAL_I32(10, mock_vector->data[1].value.int_val); + ASSUME_ITS_EQUAL_I32(42, mock_vector->data[2].value.int_val); + + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); +} + FOSSIL_TEST(test_vector_push_back) { // Push back some elements fossil_tofu_t element1 = fossil_tofu_create("int", "42"); @@ -64,6 +85,150 @@ FOSSIL_TEST(test_vector_push_back) { fossil_tofu_destroy(&element3); } +FOSSIL_TEST(test_vector_push_at) { + // Push back some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_vector_push_back(mock_vector, element1); + fossil_vector_push_back(mock_vector, element2); + fossil_vector_push_back(mock_vector, element3); + + // Push at some elements + fossil_tofu_t element4 = fossil_tofu_create("int", "100"); + fossil_vector_push_at(mock_vector, 1, element4); + + // Check if the elements are added correctly + ASSUME_ITS_EQUAL_U32(4, mock_vector->size); + ASSUME_ITS_EQUAL_I32(42, mock_vector->data[0].value.int_val); + ASSUME_ITS_EQUAL_I32(100, mock_vector->data[1].value.int_val); + ASSUME_ITS_EQUAL_I32(10, mock_vector->data[2].value.int_val); + ASSUME_ITS_EQUAL_I32(5, mock_vector->data[3].value.int_val); + + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); + fossil_tofu_destroy(&element4); +} + +FOSSIL_TEST(test_vector_pop_front) { + // Push back some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_vector_push_front(mock_vector, element1); + fossil_vector_push_front(mock_vector, element2); + fossil_vector_push_front(mock_vector, element3); + + // Pop front some elements + fossil_vector_pop_front(mock_vector); + fossil_vector_pop_front(mock_vector); + + // Check if the elements are removed correctly + ASSUME_ITS_EQUAL_U32(1, mock_vector->size); + ASSUME_ITS_EQUAL_I32(42, mock_vector->data[0].value.int_val); + + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); +} + +FOSSIL_TEST(test_vector_pop_back) { + // Push back some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_vector_push_back(mock_vector, element1); + fossil_vector_push_back(mock_vector, element2); + fossil_vector_push_back(mock_vector, element3); + + // Pop back some elements + fossil_vector_pop_back(mock_vector); + fossil_vector_pop_back(mock_vector); + + // Check if the elements are removed correctly + ASSUME_ITS_EQUAL_U32(1, mock_vector->size); + ASSUME_ITS_EQUAL_I32(42, mock_vector->data[0].value.int_val); + + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); +} + +FOSSIL_TEST(test_vector_pop_at) { + // Push back some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_vector_push_back(mock_vector, element1); + fossil_vector_push_back(mock_vector, element2); + fossil_vector_push_back(mock_vector, element3); + + // Pop at some elements + fossil_vector_pop_at(mock_vector, 1); + + // Check if the elements are removed correctly + ASSUME_ITS_EQUAL_U32(2, mock_vector->size); + ASSUME_ITS_EQUAL_I32(42, mock_vector->data[0].value.int_val); + ASSUME_ITS_EQUAL_I32(5, mock_vector->data[1].value.int_val); + + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); +} + +FOSSIL_TEST(test_vector_erase) { + // Push back some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_vector_push_back(mock_vector, element1); + fossil_vector_push_back(mock_vector, element2); + fossil_vector_push_back(mock_vector, element3); + + // Erase some elements + fossil_vector_erase(mock_vector, 1); + + // Check if the elements are removed correctly + ASSUME_ITS_EQUAL_U32(2, mock_vector->size); + ASSUME_ITS_EQUAL_I32(42, mock_vector->data[0].value.int_val); + ASSUME_ITS_EQUAL_I32(5, mock_vector->data[1].value.int_val); + + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); +} + +FOSSIL_TEST(test_vector_erase_if) { + // Push back some elements + fossil_tofu_t element1 = fossil_tofu_create("int", "42"); + fossil_tofu_t element2 = fossil_tofu_create("int", "10"); + fossil_tofu_t element3 = fossil_tofu_create("int", "5"); + + fossil_vector_push_back(mock_vector, element1); + fossil_vector_push_back(mock_vector, element2); + fossil_vector_push_back(mock_vector, element3); + + // Erase some elements + fossil_tofu_t targetElement = fossil_tofu_create("int", "10"); + fossil_vector_erase_if(mock_vector, targetElement); + + // Check if the elements are removed correctly + ASSUME_ITS_EQUAL_U32(2, mock_vector->size); + ASSUME_ITS_EQUAL_I32(42, mock_vector->data[0].value.int_val); + ASSUME_ITS_EQUAL_I32(5, mock_vector->data[1].value.int_val); + + fossil_tofu_destroy(&element1); + fossil_tofu_destroy(&element2); + fossil_tofu_destroy(&element3); + fossil_tofu_destroy(&targetElement); +} + FOSSIL_TEST(test_vector_search) { // Push back some elements fossil_tofu_t element1 = fossil_tofu_create("int", "42"); @@ -130,6 +295,31 @@ FOSSIL_TEST(test_vector_size) { fossil_tofu_destroy(&element3); } +FOSSIL_TEST(test_vector_is_cullptr) { + // Check if the vector is cullptr + ASSUME_ITS_FALSE(fossil_vector_is_cnullptr(mock_vector)); +} + +FOSSIL_TEST(test_vector_not_cullptr) { + // Check if the vector is not cullptr + ASSUME_ITS_TRUE(fossil_vector_not_cnullptr(mock_vector)); +} + +FOSSIL_TEST(test_vector_is_empty) { + // Check if the vector is empty + ASSUME_ITS_TRUE(fossil_vector_is_empty(mock_vector)); +} + +FOSSIL_TEST(test_vector_not_empty) { + // Check if the vector is not empty + ASSUME_ITS_FALSE(fossil_vector_not_empty(mock_vector)); +} + +FOSSIL_TEST(test_vector_is_capacity) { + // Check the capacity of the vector + ASSUME_ITS_EQUAL_SIZE(0, fossil_vector_capacity(mock_vector)); +} + // benchmarking cases to capture the true // performence based on current structures // implmentation. @@ -162,10 +352,22 @@ FOSSIL_TEST(stress_test_vector_usage) { FOSSIL_TEST_GROUP(c_vector_structure_tests) { // Vector Fixture + ADD_TESTF(test_vector_push_front, struct_vect_fixture); ADD_TESTF(test_vector_push_back, struct_vect_fixture); + ADD_TESTF(test_vector_push_at, struct_vect_fixture); + ADD_TESTF(test_vector_pop_front, struct_vect_fixture); + ADD_TESTF(test_vector_pop_back, struct_vect_fixture); + ADD_TESTF(test_vector_pop_at, struct_vect_fixture); + ADD_TESTF(test_vector_erase, struct_vect_fixture); + ADD_TESTF(test_vector_erase_if, struct_vect_fixture); ADD_TESTF(test_vector_search, struct_vect_fixture); ADD_TESTF(test_vector_reverse, struct_vect_fixture); ADD_TESTF(test_vector_size, struct_vect_fixture); + ADD_TESTF(test_vector_is_cullptr, struct_vect_fixture); + ADD_TESTF(test_vector_not_cullptr, struct_vect_fixture); + ADD_TESTF(test_vector_is_empty, struct_vect_fixture); + ADD_TESTF(test_vector_not_empty, struct_vect_fixture); + ADD_TESTF(test_vector_is_capacity, struct_vect_fixture); // Vector Benchmark ADD_TESTF(stress_test_vector_usage, struct_vect_fixture); diff --git a/meson.build b/meson.build index d5ae390..699f305 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project('Fossil ToFu', 'c', 'cpp', meson_version: '>=1.3.0', license: 'MPL-2.0', - version: '0.1.3', + version: '0.1.4', default_options: ['c_std=c18', 'cpp_std=c++20']) subdir('code')