test(bonus)
This commit is contained in:
parent
bb43c3b95a
commit
f091b6c53a
3
Makefile
3
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)
|
||||
|
||||
|
|
19
ft_strcmp.s
19
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
|
||||
|
|
28
main.c
28
main.c
|
@ -1,28 +0,0 @@
|
|||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#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;
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue