-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added queue.h implementation with some tests
- Loading branch information
Showing
9 changed files
with
1,702 additions
and
98 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
enable_testing() | ||
|
||
add_subdirectory(stack) | ||
add_subdirectory(stack) | ||
add_subdirectory(queue) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
add_executable(queue_test_010 main.c | ||
create_queue_test.c | ||
destroy_queue_test.c | ||
) | ||
target_compile_definitions(queue_test_010 PRIVATE TEST_QUEUE_MODE=010) | ||
target_link_libraries(queue_test_010 PRIVATE greatest project_headers) | ||
add_test(NAME QUEUE_TEST_01 COMMAND queue_test_010) | ||
set_tests_properties(QUEUE_TEST_01 PROPERTIES LABELS "QUEUE_TEST") | ||
|
||
add_executable(queue_test_020 main.c | ||
create_queue_test.c | ||
destroy_queue_test.c | ||
) | ||
target_compile_definitions(queue_test_020 PRIVATE TEST_QUEUE_MODE=020) | ||
target_link_libraries(queue_test_020 PRIVATE greatest project_headers) | ||
add_test(NAME QUEUE_TEST_02 COMMAND queue_test_020) | ||
set_tests_properties(QUEUE_TEST_02 PROPERTIES LABELS "QUEUE_TEST") | ||
|
||
add_executable(queue_test_030 main.c | ||
create_queue_test.c | ||
destroy_queue_test.c | ||
) | ||
target_compile_definitions(queue_test_030 PRIVATE TEST_QUEUE_MODE=030) | ||
target_link_libraries(queue_test_030 PRIVATE greatest project_headers) | ||
add_test(NAME QUEUE_TEST_03 COMMAND queue_test_030) | ||
set_tests_properties(QUEUE_TEST_03 PROPERTIES LABELS "QUEUE_TEST") | ||
|
||
add_executable(queue_test_040 main.c | ||
create_queue_test.c | ||
destroy_queue_test.c | ||
) | ||
target_compile_definitions(queue_test_040 PRIVATE TEST_QUEUE_MODE=040) | ||
target_link_libraries(queue_test_040 PRIVATE greatest project_headers) | ||
add_test(NAME QUEUE_TEST_04 COMMAND queue_test_040) | ||
set_tests_properties(QUEUE_TEST_04 PROPERTIES LABELS "QUEUE_TEST") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
#include <greatest.h> | ||
|
||
#ifndef TEST_QUEUE_MODE | ||
|
||
#error No queue mode was defined before testing ('TEST_QUEUE_MODE' is not defined). | ||
|
||
#else | ||
|
||
#define QUEUE_MODE TEST_QUEUE_MODE | ||
|
||
#endif | ||
|
||
//#define QUEUE_MODE INFINITE_LIST_QUEUE | ||
#define LIST_ARRAY_QUEUE_CHUNK 10 | ||
#define REALLOC_QUEUE_CHUNK 10 | ||
#define PREPROCESSOR_QUEUE_SIZE 10 | ||
#include "queue.h" | ||
|
||
#if QUEUE_MODE == INFINITE_LIST_QUEUE | ||
|
||
/// @brief Tests if size of queue is zero when creating it. | ||
TEST test_010_01(void) { | ||
queue_s test = create_queue(); | ||
ASSERT_EQm("[ERROR] Queue size must be zero.", 0, test.size); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
/// @brief Tests if current index of queue is zero when creating it. | ||
TEST test_010_02(void) { | ||
queue_s test = create_queue(); | ||
ASSERT_EQm("[ERROR] Queue current index must be zero.", 0, test.current); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
/// @brief Tests if head of queue is NULL when creating it. | ||
TEST test_010_03(void) { | ||
queue_s test = create_queue(); | ||
ASSERT_EQm("[ERROR] Queue head must be NULL.", NULL, test.head); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
/// @brief Tests if tail of queue is NULL when creating it. | ||
TEST test_010_04(void) { | ||
queue_s test = create_queue(); | ||
ASSERT_EQm("[ERROR] Queue tail must be NULL.", NULL, test.tail); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
SUITE (create_queue_test) { | ||
RUN_TEST(test_010_01); | ||
RUN_TEST(test_010_02); | ||
RUN_TEST(test_010_03); | ||
RUN_TEST(test_010_04); | ||
} | ||
|
||
#elif QUEUE_MODE == FINITE_ALLOCATED_QUEUE | ||
|
||
/// @brief Tests if size of queue is zero when creating it. | ||
TEST test_020_01(void) { | ||
queue_s test = create_queue(10); | ||
ASSERT_EQm("[ERROR] Queue size must be zero.", 0, test.size); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
/// @brief Tests if current index of queue is zero when creating it. | ||
TEST test_020_02(void) { | ||
queue_s test = create_queue(10); | ||
ASSERT_EQm("[ERROR] Queue current index must be zero.", 0, test.current); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
/// @brief Tests if maximum size of queue is 10 when creating it. | ||
TEST test_020_03(void) { | ||
queue_s test = create_queue(10); | ||
ASSERT_EQm("[ERROR] Queue current index must be zero.", 10, test.max); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
/// @brief Tests if elements pointer of queue is initialized when creating it. | ||
TEST test_020_04(void) { | ||
queue_s test = create_queue(10); | ||
ASSERT_NEQm("[ERROR] Queue elements pointer must not be NULL.", NULL, test.elements); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
SUITE (create_queue_test) { | ||
RUN_TEST(test_020_01); | ||
RUN_TEST(test_020_02); | ||
RUN_TEST(test_020_03); | ||
RUN_TEST(test_020_04); | ||
} | ||
|
||
#elif QUEUE_MODE == INFINITE_REALLOC_QUEUE | ||
|
||
/// @brief Tests if size of queue is zero when creating it. | ||
TEST test_030_01(void) { | ||
queue_s test = create_queue(); | ||
ASSERT_EQm("[ERROR] Queue size must be zero.", 0, test.size); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
/// @brief Tests if current index of queue is zero when creating it. | ||
TEST test_030_02(void) { | ||
queue_s test = create_queue(); | ||
ASSERT_EQm("[ERROR] Queue current index must be zero.", 0, test.current); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
/// @brief Tests if elements pointer of queue is NULL when creating it. | ||
TEST test_030_03(void) { | ||
queue_s test = create_queue(); | ||
ASSERT_EQm("[ERROR] Queue current index must be zero.", NULL, test.elements); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
SUITE (create_queue_test) { | ||
RUN_TEST(test_030_01); | ||
RUN_TEST(test_030_02); | ||
RUN_TEST(test_030_03); | ||
} | ||
|
||
#elif QUEUE_MODE == FINITE_PRERPOCESSOR_QUEUE | ||
|
||
/// @brief Tests if size of queue is zero when creating it. | ||
TEST test_040_01(void) { | ||
queue_s test = create_queue(); | ||
ASSERT_EQm("[ERROR] Queue size must be zero.", 0, test.size); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
/// @brief Tests if current index of queue is zero when creating it. | ||
TEST test_040_02(void) { | ||
queue_s test = create_queue(); | ||
ASSERT_EQm("[ERROR] Queue size must be zero.", 0, test.current); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
/// @brief Tests if elements array of queue is correct size when creating it. | ||
TEST test_040_03(void) { | ||
queue_s test = create_queue(); | ||
ASSERT_EQm( | ||
"[ERROR] Queue size must be zero.", | ||
PREPROCESSOR_QUEUE_SIZE, sizeof(test.elements) / sizeof(QUEUE_DATA_TYPE) | ||
); | ||
destroy_queue(&test, NULL); | ||
|
||
PASS(); | ||
} | ||
|
||
SUITE (create_queue_test) { | ||
RUN_TEST(test_040_01); | ||
RUN_TEST(test_040_02); | ||
RUN_TEST(test_040_03); | ||
} | ||
|
||
#endif |
Oops, something went wrong.