remove bonus
This commit is contained in:
parent
e3b2eb0852
commit
42b7aab1ae
@ -1,7 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *data;
|
||||
struct s_list *next;
|
||||
} t_list;
|
@ -1,27 +0,0 @@
|
||||
extern malloc
|
||||
|
||||
section .text
|
||||
global ft_list_push_front
|
||||
ft_list_push_front:
|
||||
|
||||
push rdi
|
||||
push rsi
|
||||
|
||||
mov rdi, 16
|
||||
|
||||
call malloc wrt ..plt
|
||||
|
||||
cmp rax, 0
|
||||
je out
|
||||
|
||||
pop rsi
|
||||
pop rdi
|
||||
|
||||
mov rdx, [rdi]
|
||||
mov [rax + 0], rsi ; .data = arg#1
|
||||
mov [rax + 8], rdx ; .next = *arg#0
|
||||
|
||||
mov [rdi], rax
|
||||
|
||||
out:
|
||||
ret
|
@ -1,19 +0,0 @@
|
||||
section .text
|
||||
global ft_list_size
|
||||
|
||||
ft_list_size:
|
||||
xor rcx, rcx
|
||||
|
||||
loop:
|
||||
cmp QWORD [rdi + 8], 0
|
||||
je out
|
||||
|
||||
mov rdi, [rdi + 8]
|
||||
|
||||
inc rcx
|
||||
|
||||
jmp loop
|
||||
|
||||
out:
|
||||
mov rax, rcx
|
||||
ret
|
105
test/test.c
105
test/test.c
@ -75,97 +75,6 @@ void multiple_test_atoi_base(char *(*own_func)(char *, const char *), const char
|
||||
}
|
||||
}
|
||||
|
||||
void destroy_list(t_list *root, void *(destroy_data)(void *))
|
||||
{
|
||||
t_list *current = root;
|
||||
t_list *prev;
|
||||
|
||||
while (current != NULL)
|
||||
{
|
||||
prev = current;
|
||||
if (current->data)
|
||||
if (destroy_data)
|
||||
destroy_data(current->data);
|
||||
current = current->next;
|
||||
free(prev);
|
||||
}
|
||||
}
|
||||
|
||||
t_list *create_list(size_t len)
|
||||
{
|
||||
t_list *root;
|
||||
t_list *current = root;
|
||||
|
||||
root = malloc(sizeof(t_list));
|
||||
if (root == NULL)
|
||||
return NULL;
|
||||
|
||||
current = root;
|
||||
for (size_t i = 0; i < len; i++)
|
||||
{
|
||||
current->next = malloc(sizeof(t_list));
|
||||
current->data = (void *) i;
|
||||
if (current->next == NULL)
|
||||
{
|
||||
destroy_list(current, NULL);
|
||||
return NULL;
|
||||
}
|
||||
current = current->next;
|
||||
}
|
||||
current->next = NULL;
|
||||
return root;
|
||||
}
|
||||
|
||||
#define nb_random_test 10
|
||||
#define nb_specific_test 1
|
||||
|
||||
void multiple_test_list_size()
|
||||
{
|
||||
size_t len;
|
||||
t_list *root;
|
||||
size_t specific_size[nb_specific_test] = {0};
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
for (size_t i = 0; i < nb_random_test + nb_specific_test; i++)
|
||||
{
|
||||
len = i < nb_specific_test ? specific_size[i] : rand() % 100;
|
||||
|
||||
root = create_list(len);
|
||||
if (root == NULL)
|
||||
return;
|
||||
test_int(len, ft_list_size(root));
|
||||
destroy_list(root, NULL);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
void multiple_test_push_front()
|
||||
{
|
||||
size_t len;
|
||||
t_list *root;
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
for (size_t i = 0; i < nb_random_test; i++)
|
||||
{
|
||||
len = rand() % 100;
|
||||
|
||||
root = create_list(len);
|
||||
if (root == NULL)
|
||||
return;
|
||||
ft_list_push_front(&root, (void *) 101);
|
||||
printf("data: ");
|
||||
test_size_t((size_t) root->data, 101);
|
||||
printf(" data-next: ");
|
||||
test_size_t((size_t) root->next->data, 0);
|
||||
printf(" list-size: ");
|
||||
test_int(len + 1, ft_list_size(root));
|
||||
printf("\n");
|
||||
destroy_list(root, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void multiple_test_strdup(const char * const *values)
|
||||
{
|
||||
char *tmp;
|
||||
@ -200,18 +109,4 @@ int main()
|
||||
const char *strdup_tests[] = {"yo", "", "bonjour", "co\0fgf", NULL};
|
||||
multiple_test_strdup(strdup_tests);
|
||||
printf("\n");
|
||||
|
||||
/*
|
||||
printf("ATOI_BASE\n");
|
||||
const char *atoi_base_tests[][2] = {{"0123", ""}, {"0123", "0"}, {"0123", "0123456789"}, {"bonjour", "bonjour"}, {"", ""}, {"bonjour", "salut"}, {"co\0fgf", "co\0fgf"}, NULL};
|
||||
multiple_test_int_2(strcmp, ft_strcmp, strcmp_tests);
|
||||
printf("\n");*/
|
||||
|
||||
printf("FT_LIST_SIZE\n");
|
||||
multiple_test_list_size();
|
||||
printf("\n");
|
||||
|
||||
printf("FT_LIST_PUSH_FRONT\n");
|
||||
multiple_test_push_front();
|
||||
printf("\n");
|
||||
}
|
Loading…
Reference in New Issue
Block a user