-
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.
adding the array_to_list function, fixing indexes from int to long
- Loading branch information
Showing
16 changed files
with
113 additions
and
57 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ a.out | |
*.log | ||
unit_tests | ||
liblist.so | ||
.vscode |
This file was deleted.
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
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,25 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** List in C | ||
** File description: | ||
** array_to_list.c | ||
*/ | ||
|
||
#include "list.h" | ||
|
||
list_t *array_to_list(void *const *const array, long size, | ||
list_elem_destroy_t destroy) | ||
{ | ||
list_t *list = NULL; | ||
|
||
if (0 >= size) | ||
return NULL; | ||
list = list_new(destroy); | ||
if (NULL == list) | ||
return NULL; | ||
do { | ||
--size; | ||
list_push_front(list, array[size]); | ||
} while (0 < size); | ||
return list; | ||
} |
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
#include "list.h" | ||
|
||
int list_count(list_t const *list) | ||
long list_count(list_t const *list) | ||
{ | ||
return list->count; | ||
} |
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
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
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
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
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
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
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,36 @@ | ||
/* | ||
** EPITECH PROJECT, 2024 | ||
** Tests of List in C | ||
** File description: | ||
** tests_array_to_list.c | ||
*/ | ||
|
||
#include "list.h" | ||
#include <criterion/criterion.h> | ||
#include <criterion/new/assert.h> | ||
|
||
Test(array_to_list, test_impl) | ||
{ | ||
void *array[] = { (void *) 1, (void *) 2, (void *) 3, (void *) 4, (void *) 5 }; | ||
long size = 5; | ||
list_t expected = { 0 }; | ||
list_t *list = array_to_list(array, size, NULL); | ||
|
||
cr_assert(eq(int, 0, list_push_back(&expected, (void *) 1))); | ||
cr_assert(eq(int, 0, list_push_back(&expected, (void *) 2))); | ||
cr_assert(eq(int, 0, list_push_back(&expected, (void *) 3))); | ||
cr_assert(eq(int, 0, list_push_back(&expected, (void *) 4))); | ||
cr_assert(eq(int, 0, list_push_back(&expected, (void *) 5))); | ||
cr_assert(ne(ptr, NULL, list)); | ||
cr_assert(eq(int, 1, list_equal(&expected, list, NULL))); | ||
list_destroy(list); | ||
list_clear(&expected); | ||
} | ||
|
||
Test(array_to_list, test_bad_inputs) | ||
{ | ||
void *array[] = { (void *) 1, (void *) 2, (void *) 3, (void *) 4, (void *) 5 }; | ||
|
||
cr_assert(eq(ptr, NULL, array_to_list(array, 0, NULL))); | ||
cr_assert(eq(ptr, NULL, array_to_list(array, -1, NULL))); | ||
} |
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
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
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
Oops, something went wrong.