Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodenoughPhysicsLab committed Dec 23, 2024
1 parent bbd8fc5 commit 52e500d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.7.0)
project(c-vector VERSION 0.1.0)
project(c-vector LANGUAGES C VERSION 0.1.0)
enable_testing()

# ------ cvector library ------
Expand Down
14 changes: 7 additions & 7 deletions example.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ int main(int argc, char *argv[]) {
/* remove an element by specifying an array subscript */
cvector_erase(v, 2);

int *twenty = cvector_at(v, 1);
printf("twenty : %d\n", *twenty);
int twenty = cvector_at(v, 1);
printf("twenty : %d\n", twenty);

int *front = cvector_front(v);
printf("front : %d\n", *front);
int front = cvector_front(v);
printf("front : %d\n", front);

int *back = cvector_back(v);
printf("back : %d\n", *back);
int back = cvector_back(v);
printf("back : %d\n", back);

/* remove an element from the back */
cvector_pop_back(v);

back = cvector_back(v);
printf("back val after pop_back: %d\n", *back);
printf("back val after pop_back: %d\n", back);

/* print out some stats about the vector */
printf("pointer : %p\n", (void *)v);
Expand Down
24 changes: 6 additions & 18 deletions unit-tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ UTEST(test, cvector_back) {

ASSERT_TRUE(cvector_size(v) == 2);

int *back = cvector_back(v);
ASSERT_TRUE(*back == 1);
ASSERT_TRUE(cvector_back(v) == 1);

cvector_push_back(v, 2);

back = cvector_back(v);
ASSERT_TRUE(*back == 2);
ASSERT_TRUE(cvector_back(v) == 2);

cvector_free(v);
}
Expand All @@ -44,12 +42,10 @@ UTEST(test, cvector_front) {

ASSERT_TRUE(cvector_size(v) == 2);

int *front = cvector_front(v);
ASSERT_TRUE(*front == 0);
ASSERT_TRUE(cvector_front(v) == 0);

cvector_erase(v, 0);
front = cvector_front(v);
ASSERT_TRUE(*front == 1);
ASSERT_TRUE(cvector_front(v) == 1);

cvector_free(v);
}
Expand All @@ -67,18 +63,10 @@ UTEST(test, vector_at) {
if (v) {
int i = 0;
for (; i < (int)cvector_size(v); i++) {
ASSERT_TRUE(*cvector_at(v, i) == i);
ASSERT_TRUE(cvector_at(v, i) == i);
}
}

/* test non-exists position */
int pos_non_exists = 999;
ASSERT_TRUE(cvector_at(v, pos_non_exists) == NULL);

/* remove last element*/
cvector_pop_back(v);
ASSERT_TRUE(cvector_at(v, 4) == NULL);

cvector_free(v);
}

Expand Down Expand Up @@ -364,7 +352,7 @@ struct data_t **test(size_t count, ...) {

for (i = 0; i < count; i++) {
int num = va_arg(valist, int);
struct data_t *data = calloc(sizeof(struct data_t), 1);
struct data_t *data = calloc(1, sizeof(struct data_t));
data->num = num;
cvector_insert(vec, 0, data);
}
Expand Down

0 comments on commit 52e500d

Please sign in to comment.