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:
@@ -2,33 +2,31 @@
|
||||
|
||||
#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;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
|
||||
const ArrayHeader *header = array_get_header(arr);
|
||||
const ArrayHeader* header = array_get_header(arr);
|
||||
TEST_ASSERT_EQUAL(DYNAMIC_ARRAY_DEFAULT_ARRAY_SIZE, header->capacity);
|
||||
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_destroy(void) {
|
||||
int *arr = NULL;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
array_destroy(arr);
|
||||
TEST_ASSERT_NULL(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_size_initial(void) {
|
||||
int *arr = NULL;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, array_get_header(arr)->size);
|
||||
@@ -36,9 +34,8 @@ void test_array_size_initial(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_push_value(void) {
|
||||
int *arr = NULL;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
|
||||
array_push_value(arr, 42);
|
||||
@@ -49,9 +46,8 @@ void test_array_push_value(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_push_multiple_values(void) {
|
||||
int *arr = NULL;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
|
||||
array_push_value(arr, 10);
|
||||
@@ -66,9 +62,8 @@ void test_array_push_multiple_values(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_pop_decrements_size(void) {
|
||||
int *arr = NULL;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
|
||||
array_push_value(arr, 42);
|
||||
@@ -80,9 +75,8 @@ void test_array_pop_decrements_size(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_pop_on_empty_is_noop(void) {
|
||||
int *arr = NULL;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
|
||||
array_push_value(arr, 99);
|
||||
@@ -98,9 +92,8 @@ void test_array_pop_on_empty_is_noop(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_get_capacity_default(void) {
|
||||
int *arr = NULL;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
|
||||
TEST_ASSERT_EQUAL(DYNAMIC_ARRAY_DEFAULT_ARRAY_SIZE, array_get_header(arr)->capacity);
|
||||
@@ -108,25 +101,23 @@ void test_array_get_capacity_default(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_size_capacity_relationship(void) {
|
||||
int *arr = NULL;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
|
||||
array_push_value(arr, 1);
|
||||
array_push_value(arr, 2);
|
||||
array_push_value(arr, 3);
|
||||
|
||||
const ArrayHeader *header = array_get_header(arr);
|
||||
const ArrayHeader* header = array_get_header(arr);
|
||||
TEST_ASSERT_EQUAL(3, header->size);
|
||||
TEST_ASSERT_LESS_OR_EQUAL(header->capacity, header->size);
|
||||
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_push_beyond_capacity(void) {
|
||||
int *arr = NULL;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
|
||||
const int num_elements = DYNAMIC_ARRAY_DEFAULT_ARRAY_SIZE * 2;
|
||||
@@ -134,16 +125,15 @@ void test_array_push_beyond_capacity(void) {
|
||||
array_push_value(arr, i);
|
||||
}
|
||||
|
||||
const ArrayHeader *header = array_get_header(arr);
|
||||
const ArrayHeader* header = array_get_header(arr);
|
||||
TEST_ASSERT_EQUAL(num_elements, header->size);
|
||||
TEST_ASSERT_GREATER_THAN(DYNAMIC_ARRAY_DEFAULT_ARRAY_SIZE, header->capacity);
|
||||
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_values_correct_after_growth(void) {
|
||||
int *arr = NULL;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
|
||||
const int num_elements = 1000;
|
||||
@@ -159,9 +149,8 @@ void test_array_values_correct_after_growth(void) {
|
||||
array_destroy(arr);
|
||||
}
|
||||
|
||||
|
||||
void test_array_looping(void) {
|
||||
int *arr = NULL;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
|
||||
const int num_elements = DYNAMIC_ARRAY_DEFAULT_ARRAY_SIZE * 2;
|
||||
@@ -169,7 +158,7 @@ void test_array_looping(void) {
|
||||
array_push_value(arr, i);
|
||||
}
|
||||
|
||||
const ArrayHeader *header = array_get_header(arr);
|
||||
const ArrayHeader* header = array_get_header(arr);
|
||||
TEST_ASSERT_EQUAL(num_elements, header->size);
|
||||
|
||||
for (int i = 0; i < header->size; i++) {
|
||||
@@ -177,25 +166,22 @@ 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;
|
||||
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;
|
||||
int* arr = NULL;
|
||||
array_destroy(arr);
|
||||
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;
|
||||
int* arr = NULL;
|
||||
array_push_value(arr, 7);
|
||||
TEST_ASSERT_NOT_NULL(arr);
|
||||
TEST_ASSERT_EQUAL(7, arr[0]);
|
||||
@@ -203,25 +189,22 @@ 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;
|
||||
int* arr = NULL;
|
||||
array_pop(arr);
|
||||
TEST_ASSERT_NULL(arr);
|
||||
}
|
||||
|
||||
|
||||
/* --- array_size branch: NULL arr → 0 --- */
|
||||
void test_array_size_on_null_returns_zero(void) {
|
||||
int *arr = NULL;
|
||||
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;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
array_push_value(arr, 1);
|
||||
array_push_value(arr, 2);
|
||||
@@ -229,25 +212,21 @@ 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;
|
||||
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;
|
||||
int* arr = NULL;
|
||||
array_create(arr);
|
||||
TEST_ASSERT_EQUAL(DYNAMIC_ARRAY_DEFAULT_ARRAY_SIZE, array_capacity(arr));
|
||||
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