diff --git a/Makefile b/Makefile index 5f2b39d..e9b64ce 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,9 @@ all: $(NAME) bonus: $(OBJ) $(OBJBONUS) ar rcs libasm.a $(OBJ) $(OBJBONUS) +test_bonus: bonus + gcc -Wall -Werror -Wextra -pie main_bonus.c -L . -lasm -o test_bonus + $(NAME): $(OBJ) ar rcs libasm.a $(OBJ) diff --git a/ft_strcmp.s b/ft_strcmp.s index 6c8ff62..56aab75 100644 --- a/ft_strcmp.s +++ b/ft_strcmp.s @@ -1,20 +1,19 @@ global ft_strcmp ft_strcmp: - xor rdx, rdx + xor rcx, rcx xor rax, rax + xor rdx, rdx .loop: - mov al, [rsi + rdx] - cmp byte [rdi + rdx], al + mov al, [rsi + rcx] + cmp byte [rdi + rcx], al jne .done - cmp byte [rdi + rdx], 0 + cmp byte [rdi + rcx], 0 je .done - inc rdx + inc rcx jmp .loop .done: - xor rax, rax - xor rbx, rbx - mov al, byte [rdi + rdx] - mov bl, byte [rsi + rdx] - sub rax, rbx + mov al, byte [rdi + rcx] + mov dl, byte [rsi + rcx] + sub rax, rdx ret diff --git a/main.c b/main.c deleted file mode 100644 index 758a375..0000000 --- a/main.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include -#include "libasm.h" - -void do_nothing(void *data) { - (void)data; -} - -int ft_strcmp(const char *s1, const char *s2) { - printf("s1: %ss2: %s", s1, s2); - while (*s1 && *s2 && *s1 == *s2) { - s1++; - s2++; - } - return *s1 - *s2; -} - -int main(void) { - t_list *l = NULL; - ft_list_push_front(&l, "Salut\n"); - ft_list_print(l); - int test = ft_atoi_base("700chmod", "01234567"); - printf("%d\n", test); - - return 0; -} - diff --git a/main_bonus.c b/main_bonus.c new file mode 100644 index 0000000..9830540 --- /dev/null +++ b/main_bonus.c @@ -0,0 +1,41 @@ +#include +#include +#include "libasm.h" + +void test_ft_list(void) { + t_list *list = NULL; + + assert(ft_list_size(list) == 0); + ft_list_push_front(&list, ft_strdup("abc")); + ft_list_push_front(&list, ft_strdup("cdb")); + ft_list_push_front(&list, ft_strdup("abc")); + ft_list_push_front(&list, ft_strdup("egh")); + ft_list_push_front(&list, ft_strdup("egb")); + ft_list_push_front(&list, ft_strdup("abc")); + assert(ft_list_size(list) == 6); + ft_list_push_front(&list, ft_strdup("dgb")); + ft_list_push_front(&list, ft_strdup("zzz")); + assert(ft_list_size(list) == 8); + ft_list_remove_if(&list, (void *)"abc", &ft_strcmp, &free); + assert(ft_list_size(list) == 5); + assert(ft_strcmp(list->data, "zzz") == 0); + ft_list_sort(&list, &ft_strcmp); + assert(ft_strcmp(list->data, "cdb") == 0); +} + +void test_ft_atoi_base(void) { + assert(ft_atoi_base("01", "01") == 1); + assert(ft_atoi_base("123chmod", "0123456789") == 123); + assert(ft_atoi_base("123", "0123456789") == 123); + assert(ft_atoi_base("+++++123", "0123456789") == 123); + assert(ft_atoi_base("+++++----123", "0123456789") == 123); + assert(ft_atoi_base("+-++++----123", "0123456789") == -123); + assert(ft_atoi_base("poneyvif", "poneyvif") == 342391); +} + +int main(void) { + test_ft_list(); + test_ft_atoi_base(); + return 0; +} + diff --git a/test_bonus b/test_bonus new file mode 100755 index 0000000..a49c281 Binary files /dev/null and b/test_bonus differ