style: update formatting and alignment in dynamic array files
All checks were successful
CI / build (push) Successful in 10m53s
All checks were successful
CI / build (push) Successful in 10m53s
This commit is contained in:
@@ -6,7 +6,7 @@ UseTab: Never
|
||||
|
||||
ColumnLimit: 100
|
||||
|
||||
BreakBeforeBraces: Allman
|
||||
BreakBeforeBraces: Attach
|
||||
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
@@ -19,4 +19,4 @@ SortIncludes: true
|
||||
|
||||
IndentCaseLabels: true
|
||||
|
||||
AlignEscapedNewlines: Left
|
||||
AlignEscapedNewlines: Right
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
#define DYNAMIC_ARRAY_VERSION_MAJOR 0
|
||||
#define DYNAMIC_ARRAY_VERSION_MINOR 1
|
||||
#define DYNAMIC_ARRAY_VERSION_BUILD 0
|
||||
#define DYNAMIC_ARRAY_VERSION ((DYNAMIC_ARRAY_VERSION_MAJOR << 16) | (DYNAMIC_ARRAY_VERSION_MINOR << 8) | DYNAMIC_ARRAY_VERSION_BUILD)
|
||||
#define DYNAMIC_ARRAY_VERSION \
|
||||
((DYNAMIC_ARRAY_VERSION_MAJOR << 16) | (DYNAMIC_ARRAY_VERSION_MINOR << 8) | \
|
||||
DYNAMIC_ARRAY_VERSION_BUILD)
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
@@ -12,8 +14,6 @@
|
||||
#define DYNAMIC_ARRAY_DEFAULT_ARRAY_SIZE 10
|
||||
#define DYNAMIC_ARRAY_CAPACITY_FACTOR 2
|
||||
|
||||
|
||||
|
||||
// [ HEADER | ARRAY ELEMENTS ]
|
||||
// ↑
|
||||
// THIS IS THE POINTER RETURNED BY ALL MACROS
|
||||
@@ -22,12 +22,10 @@ typedef struct {
|
||||
size_t capacity;
|
||||
} ArrayHeader;
|
||||
|
||||
|
||||
#define array_create(arr) \
|
||||
do { \
|
||||
ArrayHeader *header = malloc( \
|
||||
sizeof(*(arr)) * DYNAMIC_ARRAY_DEFAULT_ARRAY_SIZE + sizeof(ArrayHeader) \
|
||||
); \
|
||||
ArrayHeader* header = \
|
||||
malloc(sizeof(*(arr)) * DYNAMIC_ARRAY_DEFAULT_ARRAY_SIZE + sizeof(ArrayHeader)); \
|
||||
if (header == NULL) { \
|
||||
abort(); \
|
||||
} \
|
||||
@@ -37,10 +35,7 @@ typedef struct {
|
||||
(arr) = (void*)(header + 1); \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define array_get_header(arr) \
|
||||
((arr) ? ((ArrayHeader*)(arr) - 1) : NULL)
|
||||
|
||||
#define array_get_header(arr) ((arr) ? ((ArrayHeader*)(arr) - 1) : NULL)
|
||||
|
||||
#define array_destroy(arr) \
|
||||
do { \
|
||||
@@ -51,7 +46,6 @@ typedef struct {
|
||||
(arr) = NULL; \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define array_push_value(arr, value) \
|
||||
do { \
|
||||
if ((arr) == NULL) { \
|
||||
@@ -60,9 +54,8 @@ typedef struct {
|
||||
ArrayHeader* header = array_get_header(arr); \
|
||||
if (header->size >= header->capacity) { \
|
||||
size_t new_capacity = header->capacity * DYNAMIC_ARRAY_CAPACITY_FACTOR; \
|
||||
ArrayHeader *new_header = realloc( \
|
||||
header, sizeof(*(arr)) * new_capacity + sizeof(ArrayHeader) \
|
||||
); \
|
||||
ArrayHeader* new_header = \
|
||||
realloc(header, sizeof(*(arr)) * new_capacity + sizeof(ArrayHeader)); \
|
||||
if (new_header == NULL) { \
|
||||
abort(); \
|
||||
} \
|
||||
@@ -74,7 +67,6 @@ typedef struct {
|
||||
header->size++; \
|
||||
} while (0)
|
||||
|
||||
|
||||
#define array_pop(arr) \
|
||||
do { \
|
||||
if ((arr) == NULL) { \
|
||||
@@ -87,11 +79,8 @@ typedef struct {
|
||||
header->size--; \
|
||||
} while (0)
|
||||
|
||||
#define array_size(arr) ((arr) ? array_get_header(arr)->size : 0)
|
||||
|
||||
#define array_size(arr) \
|
||||
((arr) ? array_get_header(arr)->size : 0)
|
||||
|
||||
#define array_capacity(arr) \
|
||||
((arr) ? array_get_header(arr)->capacity : 0)
|
||||
#define array_capacity(arr) ((arr) ? array_get_header(arr)->capacity : 0)
|
||||
|
||||
#endif
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
#include "dynamic_array.h"
|
||||
|
||||
void setUp(void) {
|
||||
}
|
||||
|
||||
void setUp(void) {}
|
||||
|
||||
void tearDown(void) {}
|
||||
|
||||
void tearDown(void) {
|
||||
}
|
||||
|
||||
void test_array_create_without_options(void) {
|
||||
int* arr = NULL;
|
||||
@@ -18,7 +18,6 @@ void test_array_create_without_options(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_destroy(void) {
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
@@ -26,7 +25,6 @@ void test_array_destroy(void) {
|
||||
TEST_ASSERT_NULL(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_size_initial(void) {
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
@@ -36,7 +34,6 @@ void test_array_size_initial(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_push_value(void) {
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
@@ -49,7 +46,6 @@ void test_array_push_value(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_push_multiple_values(void) {
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
@@ -66,7 +62,6 @@ void test_array_push_multiple_values(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_pop_decrements_size(void) {
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
@@ -80,7 +75,6 @@ void test_array_pop_decrements_size(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_pop_on_empty_is_noop(void) {
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
@@ -98,7 +92,6 @@ void test_array_pop_on_empty_is_noop(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_get_capacity_default(void) {
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
@@ -108,7 +101,6 @@ void test_array_get_capacity_default(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_size_capacity_relationship(void) {
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
@@ -124,7 +116,6 @@ void test_array_size_capacity_relationship(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_push_beyond_capacity(void) {
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
@@ -141,7 +132,6 @@ void test_array_push_beyond_capacity(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_values_correct_after_growth(void) {
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
@@ -159,7 +149,6 @@ void test_array_values_correct_after_growth(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_looping(void) {
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
@@ -177,14 +166,12 @@ void test_array_looping(void) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* --- array_get_header branch: NULL arr → returns NULL --- */
|
||||
void test_array_get_header_on_null_returns_null(void) {
|
||||
int* arr = NULL;
|
||||
TEST_ASSERT_NULL(array_get_header(arr));
|
||||
}
|
||||
|
||||
|
||||
/* --- array_destroy branch: NULL arr → no-op, does not crash --- */
|
||||
void test_array_destroy_on_null_is_noop(void) {
|
||||
int* arr = NULL;
|
||||
@@ -192,7 +179,6 @@ void test_array_destroy_on_null_is_noop(void) {
|
||||
TEST_ASSERT_NULL(arr);
|
||||
}
|
||||
|
||||
|
||||
/* --- array_push_value branch: NULL arr → auto-creates the array --- */
|
||||
void test_array_push_value_on_null_auto_creates(void) {
|
||||
int* arr = NULL;
|
||||
@@ -203,7 +189,6 @@ void test_array_push_value_on_null_auto_creates(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
/* --- array_pop branch: NULL arr → no-op, does not crash --- */
|
||||
void test_array_pop_on_null_is_noop(void) {
|
||||
int* arr = NULL;
|
||||
@@ -211,14 +196,12 @@ void test_array_pop_on_null_is_noop(void) {
|
||||
TEST_ASSERT_NULL(arr);
|
||||
}
|
||||
|
||||
|
||||
/* --- array_size branch: NULL arr → 0 --- */
|
||||
void test_array_size_on_null_returns_zero(void) {
|
||||
int* arr = NULL;
|
||||
TEST_ASSERT_EQUAL(0, array_size(arr));
|
||||
}
|
||||
|
||||
|
||||
/* --- array_size branch: non-NULL arr → current size --- */
|
||||
void test_array_size_returns_current_size(void) {
|
||||
int* arr = NULL;
|
||||
@@ -229,14 +212,12 @@ void test_array_size_returns_current_size(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
/* --- array_capacity branch: NULL arr → 0 --- */
|
||||
void test_array_capacity_on_null_returns_zero(void) {
|
||||
int* arr = NULL;
|
||||
TEST_ASSERT_EQUAL(0, array_capacity(arr));
|
||||
}
|
||||
|
||||
|
||||
/* --- array_capacity branch: non-NULL arr → current capacity --- */
|
||||
void test_array_capacity_returns_current_capacity(void) {
|
||||
int* arr = NULL;
|
||||
@@ -245,9 +226,7 @@ void test_array_capacity_returns_current_capacity(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int main(void) {
|
||||
UNITY_BEGIN();
|
||||
|
||||
RUN_TEST(test_array_create_without_options);
|
||||
|
||||
Reference in New Issue
Block a user