├── .gitignore ├── includes ├── tester.h └── libassert.h ├── srcs ├── test_ft_strjoin.c ├── test_ft_strdup.c ├── test_ft_strtrim.c ├── test_ft_lstnew.c ├── test_ft_memmove.c ├── test_ft_memcpy.c ├── test_ft_strlen.c ├── test_ft_strmapi.c ├── test_ft_substr.c ├── test_ft_calloc.c ├── test_ft_isdigit.c ├── test_ft_putchar_fd.c ├── test_ft_itoa.c ├── test_ft_bzero.c ├── test_ft_strcmp.c ├── test_ft_split.c ├── test_ft_putstr_fd.c ├── test_ft_strnstr.c ├── test_ft_striteri.c ├── test_ft_putendl_fd.c ├── test_ft_memset.c ├── test_ft_strncmp.c ├── test_ft_lstsize.c ├── test_ft_lstlast.c ├── test_ft_strlcat.c ├── test_ft_isalpha.c ├── test_ft_tolower.c ├── test_ft_toupper.c ├── test_ft_strchr.c ├── test_ft_putnbr_fd.c ├── test_ft_lstiter.c ├── test_ft_strrchr.c ├── test_ft_lstmap.c ├── test_ft_lstdelone.c ├── test_ft_isalnum.c ├── test_ft_isascii.c ├── test_ft_isprint.c ├── test_ft_memcmp.c ├── test_ft_lstclear.c ├── test_ft_strlcpy.c ├── test_ft_memchr.c ├── test_ft_lstadd_back.c ├── test_ft_lstadd_front.c └── test_ft_atoi.c ├── libs └── libassert │ ├── Makefile │ ├── libassert.h │ └── libassert.c ├── README.md └── Makefile /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | *.out 4 | *.log 5 | -------------------------------------------------------------------------------- /includes/tester.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* tester.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/05/02 09:47:36 by susami #+# #+# */ 9 | /* Updated: 2022/05/30 12:25:38 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef TESTER_H 14 | # define TESTER_H 15 | 16 | # include 17 | # include 18 | # include 19 | # include 20 | # include 21 | # include 22 | # include "libft.h" 23 | # include "libassert.h" 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /srcs/test_ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/18 16:20:37 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:09:15 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | /* 1 */ ASSERT_EQ_STR(ft_strjoin("hello", "world"), "helloworld"); 18 | /* 2 */ ASSERT_EQ_STR(ft_strjoin("", "world"), "world"); 19 | /* 3 */ ASSERT_EQ_STR(ft_strjoin("hello", ""), "hello"); 20 | /* 4 */ ASSERT_EQ_STR(ft_strjoin("", ""), ""); 21 | } 22 | -------------------------------------------------------------------------------- /libs/libassert/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: susami +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/04/15 09:32:16 by susami #+# #+# # 9 | # Updated: 2022/04/15 09:40:11 by susami ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | OBJ_DIR = objs 14 | CFLAGS = -Wall -Werror -Wextra 15 | SRCS = libassert.c 16 | OBJS = $(SRCS:%.c=$(OBJ_DIR)/%.o) 17 | NAME = libassert.a 18 | RM = rm -f 19 | 20 | all: $(NAME) 21 | 22 | $(NAME): $(OBJS) 23 | ar -rcs libassert.a $(OBJS) 24 | 25 | $(OBJ_DIR)/%.o: %.c 26 | @mkdir -p $(OBJ_DIR) 27 | $(CC) -c $< -o $@ $(CFLAGS) 28 | 29 | clean: 30 | $(RM) $(OBJS) 31 | 32 | fclean: clean 33 | $(RM) $(NAME) 34 | 35 | re: fclean all 36 | 37 | .PHONY: all clean fclean re 38 | -------------------------------------------------------------------------------- /srcs/test_ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/18 10:25:42 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:08:57 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | void check_strdup(char *str) 16 | { 17 | void *actual = ft_strdup(str); 18 | void *expected = strdup(str); 19 | ASSERT_EQ_MALLOC_SIZE(actual, expected); 20 | ASSERT_EQ_STR(actual, expected); 21 | } 22 | 23 | int main(void) 24 | { 25 | /* 1,2 */ check_strdup(""); 26 | /* 3,4 */ check_strdup("hello"); 27 | /* 5,6 */ check_strdup("hello world"); 28 | char *str = malloc(1000); 29 | str = memset(str, 'A', 999); 30 | str[999] = '\0'; 31 | /* 7,8 */ check_strdup(str); 32 | 33 | // Segmentation Fault 34 | // /* 1,2 */ check_strdup(NULL); 35 | return (0); 36 | } 37 | -------------------------------------------------------------------------------- /srcs/test_ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/18 16:26:25 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:10:25 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | /* 1 */ ASSERT_EQ_STR(ft_strtrim("hello world", "world"), "hello "); 18 | /* 2 */ ASSERT_EQ_STR(ft_strtrim("hello world", "hello"), " world"); 19 | /* 3 */ ASSERT_EQ_STR(ft_strtrim("hello world", ""), "hello world"); 20 | /* 4 */ ASSERT_EQ_STR(ft_strtrim("", ""), ""); 21 | /* 5 */ ASSERT_EQ_STR(ft_strtrim(" hello world ", " "), "hello world"); 22 | /* 6 */ ASSERT_EQ_STR(ft_strtrim(" \n\t\r hello \n\t\r world \r\t\n\t \r\n", " \n\t\r"), "hello \n\t\r world"); 23 | /* 7 */ ASSERT_EQ_STR(ft_strtrim("hello world", "abcdefghijklmnopqrstuvwxyz"), " "); 24 | } 25 | -------------------------------------------------------------------------------- /srcs/test_ft_lstnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_lstnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 11:39:54 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:06:15 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | t_list *lst = NULL; 18 | 19 | /* ptr to char */ 20 | char *str = "hello world"; 21 | lst = ft_lstnew(str); 22 | /* 1 */ ASSERT_EQ_PTR(lst->content, str); 23 | /* 2 */ ASSERT_EQ_PTR(lst->next, NULL); 24 | 25 | /* ptr to int */ 26 | int val = 100; 27 | lst = ft_lstnew(&val); 28 | /* 3 */ ASSERT_EQ_PTR(lst->content, &val); 29 | /* 4 */ ASSERT_EQ_PTR(lst->next, NULL); 30 | 31 | /* NULL */ 32 | lst = ft_lstnew(NULL); 33 | /* 5 */ ASSERT_EQ_PTR(lst->content, NULL); 34 | /* 6 */ ASSERT_EQ_PTR(lst->next, NULL); 35 | return (0); 36 | } 37 | -------------------------------------------------------------------------------- /srcs/test_ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/15 19:09:36 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:07:23 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | void check_memmove(void *dst, void *src, size_t size) 16 | { 17 | void *expected = malloc(size); 18 | memmove(expected, src, size); 19 | ft_memmove(dst, src, size); 20 | ASSERT_EQ_MEM(dst, expected, size); 21 | if (expected) 22 | free(expected); 23 | } 24 | 25 | int main(void) 26 | { 27 | char *src = malloc(100); 28 | for (int i = 0; i < 100; i++) 29 | src[i] = i; 30 | char *dst = malloc(100); 31 | /* 1 */ check_memmove(dst, src, 0); 32 | /* 2 */ check_memmove(dst, src, 10); 33 | /* 2 */ check_memmove(dst, src, 100); 34 | /* 3 forward overlap */ check_memmove(dst + 42, dst, 50); 35 | /* 4 backward overlap*/ check_memmove(dst, dst + 21, 50); 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /srcs/test_ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/15 18:04:04 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:07:14 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | void check_memcpy(void *dst, void *src, size_t size) 16 | { 17 | void *expected = malloc(size); 18 | memcpy(expected, src, size); 19 | ft_memcpy(dst, src, size); 20 | ASSERT_EQ_MEM(dst, expected, size); 21 | if (expected) 22 | free(expected); 23 | } 24 | 25 | int main(void) 26 | { 27 | char *src = malloc(100); 28 | for (int i = 0; i < 100; i++) 29 | src[i] = i; 30 | char *dst = malloc(100); 31 | /* 1 */ check_memcpy(dst, src, 0); 32 | /* 2 */ check_memcpy(dst, src, 10); 33 | /* 2 */ check_memcpy(dst, src, 100); 34 | // undefined: /* 3 forward overlap */ check_memcpy(dst + 5, dst, 10); 35 | // undefined: /* 4 backward overlap*/ check_memcpy(dst, dst + 3, 10); 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /srcs/test_ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/15 16:58:08 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:09:38 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | /* 1 */ ASSERT_EQ_I(ft_strlen(""), strlen("")); 18 | /* 2 */ ASSERT_EQ_I(ft_strlen("hello"), strlen("hello")); 19 | /* 3 */ ASSERT_EQ_I(ft_strlen("hello world"), strlen("hello world")); 20 | 21 | // These tests are slow 22 | // char *s; 23 | // s = calloc((size_t)INT_MAX + 10, sizeof(char)); 24 | // memset(s, 1, (size_t)INT_MAX - 5); 25 | // /* 4 very long */ ASSERT_EQ_I(ft_strlen(s), strlen(s)); 26 | // memset(s, 1, (size_t)INT_MAX + 5); 27 | // /* 5 int overflow */ ASSERT_EQ_I(ft_strlen(s), strlen(s)); 28 | // for (int i = 1; i < INT_MAX; i++) 29 | // s[i - 1] = i; 30 | // /* 6 various values */ ASSERT_EQ_I(ft_strlen(s), strlen(s)); 31 | // TODO: assert segmentation fault 32 | // /* 7 */ ASSERT_EQ_I(ft_strlen(NULL), strlen(NULL)); 33 | } 34 | -------------------------------------------------------------------------------- /srcs/test_ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shunusami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 09:08:38 by shunusam #+# #+# */ 9 | /* Updated: 2022/05/02 10:09:46 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | static int (*f)(int) = NULL; 16 | static char F(unsigned int i, char c) { (void)i; return (f(c)); }; 17 | static int plus_one(int c) { return (c + 1); } 18 | 19 | int main(void) 20 | { 21 | f = toupper; 22 | /* 1 */ ASSERT_EQ_STR(ft_strmapi("abcde", F), "ABCDE"); 23 | /* 2 */ ASSERT_EQ_STR(ft_strmapi("Hello World!", F), "HELLO WORLD!"); 24 | /* 3 */ ASSERT_EQ_STR(ft_strmapi("12345", F), "12345"); 25 | f = tolower; 26 | /* 4 */ ASSERT_EQ_STR(ft_strmapi("ABCDE", F), "abcde"); 27 | /* 5 */ ASSERT_EQ_STR(ft_strmapi("Hello World!", F), "hello world!"); 28 | /* 6 */ ASSERT_EQ_STR(ft_strmapi("12345", F), "12345"); 29 | f = plus_one; 30 | /* 7 */ ASSERT_EQ_STR(ft_strmapi("ABCDE", F), "BCDEF"); 31 | /* 8 */ ASSERT_EQ_STR(ft_strmapi("Hello World!", F), "Ifmmp!Xpsme\""); 32 | /* 9 */ ASSERT_EQ_STR(ft_strmapi("12345", F), "23456"); 33 | } 34 | -------------------------------------------------------------------------------- /srcs/test_ft_substr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_substr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/18 15:31:55 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:10:32 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | char *s = "libft-test-tokyo"; 18 | /* 1 */ ASSERT_EQ_STR(ft_substr(s, 0, 100), s); 19 | /* 3 */ ASSERT_EQ_STR(ft_substr(s, 5, 100), s + 5); 20 | /* 3 */ ASSERT_EQ_STR(ft_substr(s, 10, 100), s + 10); 21 | /* 4 */ ASSERT_EQ_STR(ft_substr(s, 15, 100), s + 15); 22 | /* 5 */ ASSERT_EQ_STR(ft_substr(s, 20, 100), ""); 23 | /* 6 */ ASSERT_EQ_STR(ft_substr(s, 0, 5), "libft"); 24 | /* 7 */ ASSERT_EQ_STR(ft_substr(s, 5, 5), "-test"); 25 | /* 8 */ ASSERT_EQ_STR(ft_substr(s, 10, 5), "-toky"); 26 | /* 9 */ ASSERT_EQ_STR(ft_substr(s, 15, 5), "o"); 27 | /* 10 */ ASSERT_EQ_STR(ft_substr(s, 20, 5), ""); 28 | /* 11 */ ASSERT_EQ_STR(ft_substr(s, 0, 0), ""); 29 | /* 12 */ ASSERT_EQ_STR(ft_substr(s, 5, 0), ""); 30 | /* 13 */ ASSERT_EQ_STR(ft_substr(s, 10, 0), ""); 31 | /* 14 */ ASSERT_EQ_STR(ft_substr(s, 15, 0), ""); 32 | /* 15 */ ASSERT_EQ_STR(ft_substr(s, 20, 0), ""); 33 | } 34 | -------------------------------------------------------------------------------- /srcs/test_ft_calloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_calloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/15 12:10:25 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:02:21 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | void check_calloc(size_t cnt, size_t size) 16 | { 17 | void *actual = ft_calloc(cnt, size); 18 | void *expected = calloc(cnt, size); 19 | ASSERT_EQ_MALLOC_SIZE(actual, expected); 20 | ASSERT_EQ_MEM(actual, expected, cnt * size); 21 | } 22 | 23 | int main(void) 24 | { 25 | /* 1,2 */ check_calloc(0, 0); 26 | /* 3,4 */ check_calloc(1, 0); 27 | /* 5,6 */ check_calloc(0, 1); 28 | /* 7,8 */ check_calloc(1, 1); 29 | /* 9,10 */ check_calloc(42, 1); 30 | /* 11,12 */ check_calloc(1, 42); 31 | /* 13,14 */ check_calloc(42, 42); 32 | /* 15,16 overflow */ check_calloc((size_t)SIZE_MAX / 10 + (size_t)1, 10); 33 | /* 17,18 too big 1*/ check_calloc(LONG_MAX, 1); 34 | /* 19,20 too big 2*/ check_calloc(ULONG_MAX, 1); 35 | /* 21,22 too big 3*/ check_calloc(SIZE_MAX, 1); 36 | // /* 23,24 very big 1*/ check_calloc(INT_MAX, 1); 37 | // /* 25,26 very big 2*/ check_calloc(UINT_MAX, 1); 38 | return (0); 39 | } 40 | -------------------------------------------------------------------------------- /srcs/test_ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/15 16:51:05 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:03:48 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | /* 1 */ ASSERT_EQ_I(ft_isdigit('0'), isdigit('0')); 18 | /* 2 */ ASSERT_EQ_I(ft_isdigit('0' - 1), isdigit('0' - 1)); 19 | /* 3 */ ASSERT_EQ_I(ft_isdigit('0' + 1), isdigit('0' + 1)); 20 | /* 4 */ ASSERT_EQ_I(ft_isdigit('9'), isdigit('9')); 21 | /* 5 */ ASSERT_EQ_I(ft_isdigit('9' - 1), isdigit('9' - 1)); 22 | /* 6 */ ASSERT_EQ_I(ft_isdigit('9' + 1), isdigit('9' + 1)); 23 | /* 7 */ ASSERT_EQ_I(ft_isdigit('!'), isdigit('!')); 24 | /* 8 */ ASSERT_EQ_I(ft_isdigit('{'), isdigit('}')); 25 | /* 9 */ ASSERT_EQ_I(ft_isdigit('~'), isdigit('~')); 26 | /* 10. zero */ ASSERT_EQ_I(ft_isdigit(0), isdigit(0)); 27 | /* 11. INI_MAX */ ASSERT_EQ_I(ft_isdigit(INT_MAX), isdigit(INT_MAX)); 28 | /* 12. INT_MIN */ ASSERT_EQ_I(ft_isdigit(INT_MIN), isdigit(INT_MIN)); 29 | /* 13 (-256~255) */ for (int i = -256; i < 256; i++) { ASSERT_EQ_I(ft_isdigit(i), isdigit(i)); } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /srcs/test_ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 09:54:15 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:07:38 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | remove("tmp.txt"); 18 | int fd = open("tmp.txt", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 19 | char buf[1024]; 20 | bzero(buf, 1024); ft_putchar_fd('a', fd); lseek(fd, 0, SEEK_SET); read(fd, buf, 1); 21 | /* 1 */ ASSERT_EQ_STR(buf, "a"); 22 | bzero(buf, 1024); ft_putchar_fd('b', fd); lseek(fd, 0, SEEK_SET); read(fd, buf, 2); 23 | /* 2 */ ASSERT_EQ_STR(buf, "ab"); 24 | bzero(buf, 1024); ft_putchar_fd('c', fd); lseek(fd, 0, SEEK_SET); read(fd, buf, 3); 25 | /* 3 */ ASSERT_EQ_STR(buf, "abc"); 26 | bzero(buf, 1024); ft_putchar_fd('\n', fd); lseek(fd, 0, SEEK_SET); read(fd, buf, 4); 27 | /* 4 */ ASSERT_EQ_STR(buf, "abc\n"); 28 | bzero(buf, 1024); ft_putchar_fd('\0', fd); lseek(fd, 0, SEEK_SET); read(fd, buf, 5); 29 | /* 5 */ ASSERT_EQ_STR(buf, "abc\n"); 30 | close(fd); 31 | remove("tmp.txt"); 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /srcs/test_ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/18 23:32:54 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:04:04 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | /* 1 */ ASSERT_EQ_STR(ft_itoa(0), "0"); 18 | /* 2 */ ASSERT_EQ_STR(ft_itoa(-0), "0"); 19 | /* 3 */ ASSERT_EQ_STR(ft_itoa(+0), "0"); 20 | /* 4 */ ASSERT_EQ_STR(ft_itoa(1),"1"); 21 | /* 5 */ ASSERT_EQ_STR(ft_itoa(-1),"-1"); 22 | /* 6 */ ASSERT_EQ_STR(ft_itoa(+1),"1"); 23 | /* 7 */ ASSERT_EQ_STR(ft_itoa(7),"7"); 24 | /* 8 */ ASSERT_EQ_STR(ft_itoa(-7),"-7"); 25 | /* 9 */ ASSERT_EQ_STR(ft_itoa(+7),"7"); 26 | /* 10 */ ASSERT_EQ_STR(ft_itoa(42), "42"); 27 | /* 11 */ ASSERT_EQ_STR(ft_itoa(-42), "-42"); 28 | /* 12 */ ASSERT_EQ_STR(ft_itoa(+42), "42"); 29 | /* 13. INT_MAX */ ASSERT_EQ_STR(ft_itoa(2147483647),"2147483647"); 30 | /* 14. INT_MIN */ ASSERT_EQ_STR(ft_itoa(-2147483648),"-2147483648"); 31 | /* 15. INT_MAX - 1 */ ASSERT_EQ_STR(ft_itoa(2147483646), "2147483646"); 32 | /* 16. INT_MIN + 1 */ ASSERT_EQ_STR(ft_itoa(-2147483647), "-2147483647"); 33 | 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /srcs/test_ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/15 17:40:45 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:02:12 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | void check_bzero(char *s1, char *s2, size_t size) 16 | { 17 | memset(s1, 'A', size); 18 | memset(s2, 'B', size); 19 | ft_bzero(s1, size); 20 | bzero(s2, size); 21 | void *actual = s1; 22 | void *expected = s2; 23 | ASSERT_EQ_MEM(actual, expected, size); 24 | } 25 | 26 | int main(void) 27 | { 28 | char *s1, *s2; 29 | 30 | /* 1 */ s1 = malloc(100); s2 = malloc(100); check_bzero(s1, s2, 0); free(s1); free(s2); 31 | /* 2 */ s1 = malloc(100); s2 = malloc(100); check_bzero(s1, s2, 1); free(s1); free(s2); 32 | /* 3 */ s1 = malloc(100); s2 = malloc(100); check_bzero(s1, s2, 42); free(s1); free(s2); 33 | /* 4 */ s1 = malloc(100); s2 = malloc(100); check_bzero(s1, s2, 100); free(s1); free(s2); 34 | 35 | // No seguemtation fault 36 | // /* 5 */ ft_bzero(NULL, 0); bzero(NULL, 0); 37 | // Segmentation Fault 38 | // /* 5 */ ft_bzero(NULL, 1); bzero(NULL, 1); 39 | 40 | // very slow 41 | // /* 5 */ s1 = malloc(INT_MAX); s2 = malloc(INT_MAX); check_bzero(s1, s2, INT_MAX); free(s1); free(s2); 42 | return (0); 43 | } 44 | -------------------------------------------------------------------------------- /srcs/test_ft_strcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_strcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/06/03 12:34:13 by susami #+# #+# */ 9 | /* Updated: 2022/06/03 13:15:13 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | char *s1, *s2; 18 | s1 = ""; s2 = ""; 19 | /* 1 */ ASSERT_EQ_I(ft_strcmp(s1, s2), strcmp(s1, s2)); 20 | s1 = "ABC"; s2 = "ABCDEFG"; 21 | /* 2 */ ASSERT_EQ_I(ft_strcmp(s1, s2), strcmp(s1, s2)); 22 | s1 = "ABC"; s2 = "Z"; 23 | /* 3 */ ASSERT_EQ_I(ft_strcmp(s1, s2), strcmp(s1, s2)); 24 | s1 = "ABC"; s2 = "A0"; 25 | /* 4 */ ASSERT_EQ_I(ft_strcmp(s1, s2), strcmp(s1, s2)); 26 | s1 = "ABC"; s2 = "é"; 27 | /* 5 */ ASSERT_EQ_I(ft_strcmp(s1, s2), strcmp(s1, s2)); 28 | s1 = "ABC"; s2 = "A"; 29 | /* 6 */ ASSERT_EQ_I(ft_strcmp(s1, s2), strcmp(s1, s2)); 30 | s1 = "abcde"; s2 = "abcdf"; 31 | /* 7 */ ASSERT_EQ_I(ft_strcmp(s1, s2), strcmp(s1, s2)); 32 | s1 = "abcde"; s2 = "abcdd"; 33 | /* 8 */ ASSERT_EQ_I(ft_strcmp(s1, s2), strcmp(s1, s2)); 34 | s1 = "abcde"; s2 = "abcd1"; 35 | /* 9 */ ASSERT_EQ_I(ft_strcmp(s1, s2), strcmp(s1, s2)); 36 | s1 = "abcde"; s2 = "abcd"; 37 | /* 10 */ ASSERT_EQ_I(ft_strcmp(s1, s2), strcmp(s1, s2)); 38 | s1 = "abcd"; s2 = "abcde"; 39 | /* 11 */ ASSERT_EQ_I(ft_strcmp(s1, s2), strcmp(s1, s2)); 40 | } 41 | -------------------------------------------------------------------------------- /srcs/test_ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/18 16:34:25 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:08:39 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | void assert_str_array(char **actual, char **expected) 16 | { 17 | // Check the non NULL elements 18 | while (*expected) 19 | ASSERT_EQ_STR(*actual++, *expected++); 20 | // Check the last element to be NULL 21 | ASSERT_EQ_PTR(*actual, *expected); 22 | } 23 | 24 | int main(void) 25 | { 26 | char *expected[] = {"hello","world","42","tokyo", NULL}; 27 | /* 1 ~ 5 */ assert_str_array(ft_split("hello,world,42,tokyo", ','), expected); 28 | /* 6 ~ 10 */ assert_str_array(ft_split("hello world 42 tokyo", ' '), expected); 29 | /* 11 ~ 15 */ assert_str_array(ft_split(",,,hello,,,world,,,42,,,tokyo,,,,", ','), expected); 30 | 31 | char *expected2[] = {"hello,world,42,tokyo", NULL}; 32 | /* 16 ~ 17 */ assert_str_array(ft_split("hello,world,42,tokyo", ' '), expected2); 33 | /* 18 ~ 19 */ assert_str_array(ft_split("hello,world,42,tokyo", '{'), expected2); 34 | 35 | char *expected3[] = {NULL}; 36 | /* 20 */ assert_str_array(ft_split("", ','), expected3); 37 | 38 | // Segmentation Fault 39 | // /* 21 */ assert_str_array(ft_split(NULL, ','), expected3); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /srcs/test_ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 10:38:44 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:08:32 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | remove("tmp.txt"); 18 | int fd = open("tmp.txt", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 19 | char buf[1024]; 20 | ft_putstr_fd("hello", fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 21 | /* 1 */ ASSERT_EQ_STR(buf, "hello"); 22 | ft_putstr_fd(" world", fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 23 | /* 2 */ ASSERT_EQ_STR(buf, "hello world"); 24 | ft_putstr_fd(" 42!", fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 25 | /* 3 */ ASSERT_EQ_STR(buf, "hello world 42!"); 26 | ft_putstr_fd("\0\0\0", fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 27 | /* 4 */ ASSERT_EQ_STR(buf, "hello world 42!"); 28 | ft_putstr_fd("\n\n\n", fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 29 | /* 5 */ ASSERT_EQ_STR(buf, "hello world 42!\n\n\n"); 30 | ft_putstr_fd("", fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 31 | /* 6 */ ASSERT_EQ_STR(buf, "hello world 42!\n\n\n"); 32 | close(fd); 33 | remove("tmp.txt"); 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /srcs/test_ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/18 09:06:34 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:10:08 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | char *str = "libft-test-tokyo"; 18 | int len = strlen(str); 19 | for (int i = 0; i < len; i++) 20 | { 21 | ASSERT_EQ_PTR(ft_strnstr(str, "", i), strnstr(str, "", i)); 22 | ASSERT_EQ_PTR(ft_strnstr(str, "libft-test-tokyo", i), strnstr(str, "libft-test-tokyo", i)); 23 | ASSERT_EQ_PTR(ft_strnstr(str, "libft", i), strnstr(str, "libft", i)); 24 | ASSERT_EQ_PTR(ft_strnstr(str, "test", i), strnstr(str, "test", i)); 25 | ASSERT_EQ_PTR(ft_strnstr(str, "tokyo", i), strnstr(str, "tokyo", i)); 26 | ASSERT_EQ_PTR(ft_strnstr(str, "libft~", i), strnstr(str, "libft~", i)); 27 | ASSERT_EQ_PTR(ft_strnstr(str, "z", i), strnstr(str, "z", i)); 28 | } 29 | /* 113 */ ASSERT_EQ_PTR(ft_strnstr("", "hello", 5), strnstr("", "hello", 5)); 30 | /* 114 */ ASSERT_EQ_PTR(ft_strnstr("", "", 0), strnstr("", "", 0)); 31 | /* 115 */ ASSERT_EQ_PTR(ft_strnstr(NULL, "1", 0), strnstr(NULL, "1", 0)); 32 | // Segmentation Fault 33 | // /* 116 */ ASSERT_EQ_PTR(ft_strnstr(NULL, "fake", 3), strnstr(NULL, "fake", 3)); 34 | // /* 116 */ ASSERT_EQ_PTR(ft_strnstr(NULL, "1", 1), ft_strnstr(NULL, "1", 1)); 35 | } 36 | -------------------------------------------------------------------------------- /srcs/test_ft_striteri.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_striteri.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: shunusami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 09:07:48 by shunusam #+# #+# */ 9 | /* Updated: 2022/05/02 10:09:02 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | static int (*f)(int) = NULL; 16 | static void F(unsigned int i, char *s) { (void)i; *s = f(*s); }; 17 | static int plus_one(int c) { return (c + 1); } 18 | 19 | static char buf[100] = {}; 20 | static void tobuf(unsigned int i, char *str) { 21 | static size_t idx = 0; 22 | (void)i; 23 | 24 | buf[idx++] = *str; 25 | } 26 | 27 | int main(void) 28 | { 29 | char str[] = "abcde"; 30 | 31 | f = toupper; ft_striteri(str, F); 32 | /* 1 */ ASSERT_EQ_STR(str, "ABCDE"); 33 | f = plus_one; ft_striteri(str, F); 34 | /* 2 */ ASSERT_EQ_STR(str, "BCDEF"); 35 | f = tolower; ft_striteri(str, F); 36 | /* 3 */ ASSERT_EQ_STR(str, "bcdef"); 37 | f = plus_one; ft_striteri(str, F); 38 | /* 4 */ ASSERT_EQ_STR(str, "cdefg"); 39 | f = toupper; ft_striteri(str, F); 40 | /* 5 */ ASSERT_EQ_STR(str, "CDEFG"); 41 | 42 | bzero(buf, 100); 43 | ft_striteri("hello", tobuf); 44 | /* 6 */ ASSERT_EQ_STR(buf, "hello"); 45 | ft_striteri(" world", tobuf); 46 | /* 7 */ ASSERT_EQ_STR(buf, "hello world"); 47 | ft_striteri(" 42!", tobuf); 48 | /* 8 */ ASSERT_EQ_STR(buf, "hello world 42!"); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /srcs/test_ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 10:47:50 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:08:09 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | remove("tmp.txt"); 18 | int fd = open("tmp.txt", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 19 | char buf[1024]; 20 | ft_putendl_fd("hello", fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 21 | /* 1 */ ASSERT_EQ_STR(buf, "hello\n"); 22 | ft_putendl_fd(" world", fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 23 | /* 2 */ ASSERT_EQ_STR(buf, "hello\n world\n"); 24 | ft_putendl_fd(" 42!", fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 25 | /* 3 */ ASSERT_EQ_STR(buf, "hello\n world\n 42!\n"); 26 | ft_putendl_fd("\0\0\0", fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 27 | /* 4 */ ASSERT_EQ_STR(buf, "hello\n world\n 42!\n\n"); 28 | ft_putendl_fd("\n\n\n", fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 29 | /* 5 */ ASSERT_EQ_STR(buf, "hello\n world\n 42!\n\n\n\n\n\n"); 30 | ft_putendl_fd("", fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 31 | /* 6 */ ASSERT_EQ_STR(buf, "hello\n world\n 42!\n\n\n\n\n\n\n"); 32 | close(fd); 33 | remove("tmp.txt"); 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /srcs/test_ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/15 17:11:14 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:07:30 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | void check_memset(char *s1, char *s2, int val, size_t size) 16 | { 17 | void *actual = ft_memset(s1, val, size); 18 | void *expected = memset(s2, val, size); 19 | ASSERT_EQ_MEM(actual, expected, size); 20 | } 21 | 22 | int main(void) 23 | { 24 | char *s1, *s2; 25 | 26 | /* 1 */ s1 = calloc(100, 100); s2 = calloc(100, 100); check_memset(s1, s2, 0, 0); free(s1); free(s2); 27 | /* 2 */ s1 = calloc(100, 100); s2 = calloc(100, 100); check_memset(s1, s2, 1, 0); free(s1); free(s2); 28 | /* 3 */ s1 = calloc(100, 100); s2 = calloc(100, 100); check_memset(s1, s2, 0, 1); free(s1); free(s2); 29 | /* 4 */ s1 = calloc(100, 100); s2 = calloc(100, 100); check_memset(s1, s2, 42, 0); free(s1); free(s2); 30 | /* 5 */ s1 = calloc(100, 100); s2 = calloc(100, 100); check_memset(s1, s2, 0, 42); free(s1); free(s2); 31 | /* 6 */ s1 = calloc(100, 100); s2 = calloc(100, 100); check_memset(s1, s2, 42, 42); free(s1); free(s2); 32 | /* 7 */ s1 = calloc(100, 100); s2 = calloc(100, 100); check_memset(s1, s2, INT_MAX, 42); free(s1); free(s2); 33 | /* 8 */ s1 = calloc(100, 100); s2 = calloc(100, 100); check_memset(s1, s2, INT_MIN, 42); free(s1); free(s2); 34 | /* 10 */ check_memset(NULL, NULL, 0, 0); 35 | // Very slow 36 | // /* 9 */ s1 = calloc(INT_MAX, 1); s2 = calloc(INT_MAX, 1); check_memset(s1, s2, 42, INT_MAX); free(s1); free(s2); 37 | return (0); 38 | } 39 | -------------------------------------------------------------------------------- /srcs/test_ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/18 08:17:32 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:45:43 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | char *str = "libft-test-tokyo"; 18 | char *cmp = "libft-test-tokyo"; 19 | int len = strlen(str); 20 | /* 1 ~ 17 */ 21 | for (int i = 0; i <= len; i++) 22 | ASSERT_EQ_I(ft_strncmp(str, cmp, i), strncmp(str, cmp, i)); 23 | /* 18 ~ 51 */ 24 | for (int i = 0; i <= len; i++) 25 | { 26 | cmp = strndup(str, i); 27 | ASSERT_EQ_I(ft_strncmp(str, cmp, i), strncmp(str, cmp, i)); 28 | ASSERT_EQ_I(ft_strncmp(str, cmp, len), strncmp(str, cmp, len)); 29 | free(cmp); 30 | } 31 | char *cmp2 = calloc(10, 1); 32 | strlcpy(cmp2, "libft", 10); 33 | cmp2[5] = CHAR_MIN; 34 | /* 52 */ ASSERT_EQ_I(ft_strncmp(str, cmp2, len), strncmp(str, cmp2, len)); 35 | cmp2[5] = -42; 36 | /* 53 */ ASSERT_EQ_I(ft_strncmp(str, cmp2, len), strncmp(str, cmp2, len)); 37 | cmp2[5] = 0; 38 | /* 54 */ ASSERT_EQ_I(ft_strncmp(str, cmp2, len), strncmp(str, cmp2, len)); 39 | cmp2[5] = 42; 40 | /* 55 */ ASSERT_EQ_I(ft_strncmp(str, cmp2, len), strncmp(str, cmp2, len)); 41 | cmp2[5] = CHAR_MAX; 42 | /* 56 */ ASSERT_EQ_I(ft_strncmp(str, cmp2, len), strncmp(str, cmp2, len)); 43 | /* 57 */ ASSERT_EQ_I(ft_strncmp("hello", NULL, 0), strncmp("hello", NULL, 0)); 44 | /* 58 */ ASSERT_EQ_I(ft_strncmp(NULL, "hello", 0), strncmp(NULL, "hello", 0)); 45 | /* 59 */ ASSERT_EQ_I(ft_strncmp(NULL, NULL, 0), strncmp(NULL, NULL, 0)); 46 | return (0); 47 | } 48 | -------------------------------------------------------------------------------- /srcs/test_ft_lstsize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_lstsize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 12:11:59 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:06:30 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | t_list *elem1 = calloc(sizeof(t_list), 1); 18 | t_list *elem2 = calloc(sizeof(t_list), 1); 19 | t_list *elem3 = calloc(sizeof(t_list), 1); 20 | t_list *elem4 = calloc(sizeof(t_list), 1); 21 | t_list *elem5 = calloc(sizeof(t_list), 1); 22 | char *s1 = "hello"; 23 | char *s2 = "world"; 24 | char *s3 = "42!"; 25 | int val4 = 42; 26 | int val5 = -42; 27 | elem1->content = s1; 28 | elem2->content = s2; 29 | elem3->content = s3; 30 | elem4->content = &val4; 31 | elem5->content = &val5; 32 | 33 | /* zero */ 34 | t_list *lst = NULL; 35 | /* 1 */ ASSERT_EQ_I(ft_lstsize(lst), 0); 36 | 37 | /* add back #1 */ 38 | lst = elem1; 39 | /* 2 */ ASSERT_EQ_I(ft_lstsize(lst), 1); 40 | 41 | /* add back #2 */ 42 | elem1->next = elem2; 43 | /* 3 */ ASSERT_EQ_I(ft_lstsize(lst), 2); 44 | 45 | /* add back #3 */ 46 | elem2->next = elem3; 47 | /* 4 */ ASSERT_EQ_I(ft_lstsize(lst), 3); 48 | 49 | /* add back #4 */ 50 | elem3->next = elem4; 51 | /* 5 */ ASSERT_EQ_I(ft_lstsize(lst), 4); 52 | 53 | /* add back #5 */ 54 | elem4->next = elem5; 55 | /* 6 */ ASSERT_EQ_I(ft_lstsize(lst), 5); 56 | 57 | /* unlink #1->#2 */ 58 | elem1->next = NULL; 59 | /* 7 */ ASSERT_EQ_I(ft_lstsize(lst), 1); 60 | } 61 | -------------------------------------------------------------------------------- /srcs/test_ft_lstlast.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_lstlast.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 12:19:04 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:05:54 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | t_list *elem1 = calloc(sizeof(t_list), 1); 18 | t_list *elem2 = calloc(sizeof(t_list), 1); 19 | t_list *elem3 = calloc(sizeof(t_list), 1); 20 | t_list *elem4 = calloc(sizeof(t_list), 1); 21 | t_list *elem5 = calloc(sizeof(t_list), 1); 22 | char *s1 = "hello"; 23 | char *s2 = "world"; 24 | char *s3 = "42!"; 25 | int val4 = 42; 26 | int val5 = -42; 27 | elem1->content = s1; 28 | elem2->content = s2; 29 | elem3->content = s3; 30 | elem4->content = &val4; 31 | elem5->content = &val5; 32 | 33 | /* zero */ 34 | t_list *lst = NULL; 35 | /* 1 */ ASSERT_EQ_PTR(ft_lstlast(lst), NULL); 36 | 37 | /* add back #1 */ 38 | lst = elem1; 39 | /* 2 */ ASSERT_EQ_PTR(ft_lstlast(lst), elem1); 40 | 41 | /* add back #2 */ 42 | elem1->next = elem2; 43 | /* 3 */ ASSERT_EQ_PTR(ft_lstlast(lst), elem2); 44 | 45 | /* add back #3 */ 46 | elem2->next = elem3; 47 | /* 4 */ ASSERT_EQ_PTR(ft_lstlast(lst), elem3); 48 | 49 | /* add back #4 */ 50 | elem3->next = elem4; 51 | /* 5 */ ASSERT_EQ_PTR(ft_lstlast(lst), elem4); 52 | 53 | /* add back #5 */ 54 | elem4->next = elem5; 55 | /* 6 */ ASSERT_EQ_PTR(ft_lstlast(lst), elem5); 56 | 57 | /* unlink #1->#2 */ 58 | elem1->next = NULL; 59 | /* 7 */ ASSERT_EQ_PTR(ft_lstlast(lst), elem1); 60 | } 61 | -------------------------------------------------------------------------------- /srcs/test_ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/17 21:16:21 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:09:22 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | char *dst1 = calloc(100, sizeof(char)); 18 | char *dst2 = calloc(100, sizeof(char)); 19 | /* 1 */ ASSERT_EQ_I(ft_strlcat(dst1, "", 100), strlcat(dst2, "", 100)); 20 | /* 2 */ ASSERT_EQ_STR(dst1, dst2); 21 | /* 3 */ ASSERT_EQ_I(ft_strlcat(dst1, "hello", 100), strlcat(dst2, "hello", 100)); 22 | /* 4 */ ASSERT_EQ_STR(dst1, dst2); 23 | /* 5 */ ASSERT_EQ_I(ft_strlcat(dst1, "world", 100), strlcat(dst2, "world", 100)); 24 | /* 6 */ ASSERT_EQ_STR(dst1, dst2); 25 | char *src1 = calloc(100, sizeof(char)); 26 | char *src2 = calloc(100, sizeof(char)); 27 | for (int i = 0; i < 99; i++) 28 | { 29 | src1[i] = i + 1; 30 | src2[i] = i + 1; 31 | } 32 | /* 7 */ ASSERT_EQ_I(ft_strlcat(dst1, src1, 0), strlcat(dst2, src2, 0)); 33 | /* 8 */ ASSERT_EQ_STR(dst1, dst2); 34 | /* 9 */ ASSERT_EQ_I(ft_strlcat(dst1, src1, 10), strlcat(dst2, src2, 10)); 35 | /* 10 */ ASSERT_EQ_STR(dst1, dst2); 36 | /* 11 */ ASSERT_EQ_I(ft_strlcat(dst1, src1, 50), strlcat(dst2, src2, 50)); 37 | /* 12 */ ASSERT_EQ_STR(dst1, dst2); 38 | /* 13 */ ASSERT_EQ_I(ft_strlcat(dst1, src1, 100), strlcat(dst2, src2, 100)); 39 | /* 14 */ ASSERT_EQ_STR(dst1, dst2); 40 | /* 15 */ ASSERT_EQ_I(ft_strlcat(dst1, src1, 10), strlcat(dst2, src2, 10)); 41 | /* 16 */ ASSERT_EQ_STR(dst1, dst2); 42 | /* 17 */ ASSERT_EQ_I(ft_strlcat(dst1, src1, 100), strlcat(dst2, src2, 100)); 43 | /* 18 */ ASSERT_EQ_STR(dst1, dst2); 44 | /* 19 */ ASSERT_EQ_I(ft_strlcat(NULL, src1, 0), strlcat(NULL, src2, 0)); 45 | } 46 | -------------------------------------------------------------------------------- /srcs/test_ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/15 16:35:50 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:02:33 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | /* 1 */ ASSERT_EQ_I(ft_isalpha('a'), isalpha('b')); 18 | /* 2 */ ASSERT_EQ_I(ft_isalpha('a' - 1), isalpha('a' - 1)); 19 | /* 3 */ ASSERT_EQ_I(ft_isalpha('a' + 1), isalpha('a' + 1)); 20 | /* 4 */ ASSERT_EQ_I(ft_isalpha('z'), isalpha('z')); 21 | /* 5 */ ASSERT_EQ_I(ft_isalpha('z' - 1), isalpha('z' - 1)); 22 | /* 6 */ ASSERT_EQ_I(ft_isalpha('z' + 1), isalpha('z' + 1)); 23 | /* 7 */ ASSERT_EQ_I(ft_isalpha('A'), isalpha('A')); 24 | /* 8 */ ASSERT_EQ_I(ft_isalpha('A' - 1), isalpha('A' - 1)); 25 | /* 9 */ ASSERT_EQ_I(ft_isalpha('A' + 1), isalpha('A' + 1)); 26 | /* 10 */ ASSERT_EQ_I(ft_isalpha('Z'), isalpha('Z')); 27 | /* 11 */ ASSERT_EQ_I(ft_isalpha('Z' - 1), isalpha('Z' - 1)); 28 | /* 12 */ ASSERT_EQ_I(ft_isalpha('Z' + 1), isalpha('Z' + 1)); 29 | /* 13 */ ASSERT_EQ_I(ft_isalpha('a' + 256), isalpha('a' + 256)); 30 | /* 14 */ ASSERT_EQ_I(ft_isalpha('a' - 256), isalpha('a' - 256)); 31 | /* 15 */ ASSERT_EQ_I(ft_isalpha('a' + 1), isalpha('a' + 1)); 32 | /* 16 */ ASSERT_EQ_I(ft_isalpha('!'), isalpha('!')); 33 | /* 17 */ ASSERT_EQ_I(ft_isalpha('{'), isalpha('}')); 34 | /* 18 */ ASSERT_EQ_I(ft_isalpha('~'), isalpha('~')); 35 | /* 19. zero */ ASSERT_EQ_I(ft_isalpha(0), isalpha(0)); 36 | /* 20. INI_MAX */ ASSERT_EQ_I(ft_isalpha(INT_MAX), isalpha(INT_MAX)); 37 | /* 21. INT_MIN */ ASSERT_EQ_I(ft_isalpha(INT_MIN), isalpha(INT_MIN)); 38 | /* 22 (-256~255) */ for (int i = -256; i < 256; i++) { ASSERT_EQ_I(ft_isalpha(i), isalpha(i)); } 39 | return (0); 40 | } 41 | -------------------------------------------------------------------------------- /srcs/test_ft_tolower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_tolower.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/17 22:28:39 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:10:38 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | /* 1 */ ASSERT_EQ_I(ft_tolower('a'), tolower('a')); 18 | /* 2 */ ASSERT_EQ_I(ft_tolower('a' - 1), tolower('a' - 1)); 19 | /* 3 */ ASSERT_EQ_I(ft_tolower('a' + 1), tolower('a' + 1)); 20 | /* 4 */ ASSERT_EQ_I(ft_tolower('z'), tolower('z')); 21 | /* 5 */ ASSERT_EQ_I(ft_tolower('z' - 1), tolower('z' - 1)); 22 | /* 6 */ ASSERT_EQ_I(ft_tolower('z' + 1), tolower('z' + 1)); 23 | /* 7 */ ASSERT_EQ_I(ft_tolower('A'), tolower('A')); 24 | /* 8 */ ASSERT_EQ_I(ft_tolower('A' - 1), tolower('A' - 1)); 25 | /* 9 */ ASSERT_EQ_I(ft_tolower('A' + 1), tolower('A' + 1)); 26 | /* 10 */ ASSERT_EQ_I(ft_tolower('Z'), tolower('Z')); 27 | /* 11 */ ASSERT_EQ_I(ft_tolower('Z' - 1), tolower('Z' - 1)); 28 | /* 12 */ ASSERT_EQ_I(ft_tolower('Z' + 1), tolower('Z' + 1)); 29 | /* 13 */ ASSERT_EQ_I(ft_tolower('a' + 256), tolower('a' + 256)); 30 | /* 14 */ ASSERT_EQ_I(ft_tolower('a' - 256), tolower('a' - 256)); 31 | /* 15 */ ASSERT_EQ_I(ft_tolower('a' + 1), tolower('a' + 1)); 32 | /* 16 */ ASSERT_EQ_I(ft_tolower('!'), tolower('!')); 33 | /* 17 */ ASSERT_EQ_I(ft_tolower('{'), tolower('{')); 34 | /* 18 */ ASSERT_EQ_I(ft_tolower('~'), tolower('~')); 35 | /* 19. zero */ ASSERT_EQ_I(ft_tolower(0), tolower(0)); 36 | /* 20. INI_MAX */ ASSERT_EQ_I(ft_tolower(INT_MAX), tolower(INT_MAX)); 37 | /* 21. INT_MIN */ ASSERT_EQ_I(ft_tolower(INT_MIN), tolower(INT_MIN)); 38 | /* 22 (-256~255) */ for (int i = -256; i < 256; i++) { ASSERT_EQ_I(ft_tolower(i), tolower(i)); } 39 | return (0); 40 | } 41 | -------------------------------------------------------------------------------- /srcs/test_ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/17 22:22:06 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:10:45 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | /* 1 */ ASSERT_EQ_I(ft_toupper('a'), toupper('a')); 18 | /* 2 */ ASSERT_EQ_I(ft_toupper('a' - 1), toupper('a' - 1)); 19 | /* 3 */ ASSERT_EQ_I(ft_toupper('a' + 1), toupper('a' + 1)); 20 | /* 4 */ ASSERT_EQ_I(ft_toupper('z'), toupper('z')); 21 | /* 5 */ ASSERT_EQ_I(ft_toupper('z' - 1), toupper('z' - 1)); 22 | /* 6 */ ASSERT_EQ_I(ft_toupper('z' + 1), toupper('z' + 1)); 23 | /* 7 */ ASSERT_EQ_I(ft_toupper('A'), toupper('A')); 24 | /* 8 */ ASSERT_EQ_I(ft_toupper('A' - 1), toupper('A' - 1)); 25 | /* 9 */ ASSERT_EQ_I(ft_toupper('A' + 1), toupper('A' + 1)); 26 | /* 10 */ ASSERT_EQ_I(ft_toupper('Z'), toupper('Z')); 27 | /* 11 */ ASSERT_EQ_I(ft_toupper('Z' - 1), toupper('Z' - 1)); 28 | /* 12 */ ASSERT_EQ_I(ft_toupper('Z' + 1), toupper('Z' + 1)); 29 | /* 13 */ ASSERT_EQ_I(ft_toupper('a' + 256), toupper('a' + 256)); 30 | /* 14 */ ASSERT_EQ_I(ft_toupper('a' - 256), toupper('a' - 256)); 31 | /* 15 */ ASSERT_EQ_I(ft_toupper('a' + 1), toupper('a' + 1)); 32 | /* 16 */ ASSERT_EQ_I(ft_toupper('!'), toupper('!')); 33 | /* 17 */ ASSERT_EQ_I(ft_toupper('{'), toupper('{')); 34 | /* 18 */ ASSERT_EQ_I(ft_toupper('~'), toupper('~')); 35 | /* 19. zero */ ASSERT_EQ_I(ft_toupper(0), toupper(0)); 36 | /* 20. INI_MAX */ ASSERT_EQ_I(ft_toupper(INT_MAX), toupper(INT_MAX)); 37 | /* 21. INT_MIN */ ASSERT_EQ_I(ft_toupper(INT_MIN), toupper(INT_MIN)); 38 | /* 22 (-256~255) */ for (int i = -256; i < 256; i++) { ASSERT_EQ_I(ft_toupper(i), toupper(i)); } 39 | return (0); 40 | } 41 | -------------------------------------------------------------------------------- /srcs/test_ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/18 07:35:38 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:08:48 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | char *s = "libft-test-tokyo"; 18 | /* 1 */ ASSERT_EQ_STR(ft_strchr(s, 'l'), strchr(s, 'l')); 19 | /* 2 */ ASSERT_EQ_STR(ft_strchr(s, 'i'), strchr(s, 'i')); 20 | /* 3 */ ASSERT_EQ_STR(ft_strchr(s, 'b'), strchr(s, 'b')); 21 | /* 4 */ ASSERT_EQ_STR(ft_strchr(s, 'f'), strchr(s, 'f')); 22 | /* 5 */ ASSERT_EQ_STR(ft_strchr(s, 't'), strchr(s, 't')); 23 | /* 6 */ ASSERT_EQ_STR(ft_strchr(s, '-'), strchr(s, '-')); 24 | /* 7 */ ASSERT_EQ_STR(ft_strchr(s, 't'), strchr(s, 't')); 25 | /* 8 */ ASSERT_EQ_STR(ft_strchr(s, 'e'), strchr(s, 'e')); 26 | /* 9 */ ASSERT_EQ_STR(ft_strchr(s, 's'), strchr(s, 's')); 27 | /* 10 */ ASSERT_EQ_STR(ft_strchr(s, 't'), strchr(s, 't')); 28 | /* 11 */ ASSERT_EQ_STR(ft_strchr(s, '-'), strchr(s, '-')); 29 | /* 12 */ ASSERT_EQ_STR(ft_strchr(s, 't'), strchr(s, 't')); 30 | /* 13 */ ASSERT_EQ_STR(ft_strchr(s, 'o'), strchr(s, 'o')); 31 | /* 14 */ ASSERT_EQ_STR(ft_strchr(s, 'k'), strchr(s, 'k')); 32 | /* 15 */ ASSERT_EQ_STR(ft_strchr(s, 'y'), strchr(s, 'y')); 33 | /* 16 */ ASSERT_EQ_STR(ft_strchr(s, 'o'), strchr(s, 'o')); 34 | /* 17 */ ASSERT_EQ_STR(ft_strchr(s, '\0'), strchr(s, '\0')); 35 | /* 18 */ ASSERT_EQ_STR(ft_strchr(s, 'l' + 256), strchr(s, 'l' + 256)); 36 | /* 19 */ ASSERT_EQ_STR(ft_strchr(s, 'i' + 256), strchr(s, 'i' + 256)); 37 | /* 20 */ ASSERT_EQ_STR(ft_strchr(s, 'l' - 256), strchr(s, 'l' - 256)); 38 | /* 21 */ ASSERT_EQ_STR(ft_strchr(s, 'i' - 256), strchr(s, 'i' - 256)); 39 | /* 22 */ ASSERT_EQ_STR(ft_strchr(s, 'z'), strchr(s, 'z')); 40 | /* 23 */ ASSERT_EQ_STR(ft_strchr(s, '~'), strchr(s, '~')); 41 | return (0); 42 | } 43 | -------------------------------------------------------------------------------- /srcs/test_ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 10:51:02 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:08:16 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | remove("tmp.txt"); 18 | int fd = open("tmp.txt", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); 19 | char buf[1024]; 20 | ft_putnbr_fd(0, fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 21 | /* 1 */ ASSERT_EQ_STR(buf, "0"); 22 | ft_putnbr_fd(1, fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 23 | /* 2 */ ASSERT_EQ_STR(buf, "01"); 24 | ft_putnbr_fd(-1, fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 25 | /* 3 */ ASSERT_EQ_STR(buf, "01-1"); 26 | ft_putnbr_fd(42, fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 27 | /* 4 */ ASSERT_EQ_STR(buf, "01-142"); 28 | ft_putnbr_fd(-42, fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 29 | /* 5 */ ASSERT_EQ_STR(buf, "01-142-42"); 30 | ft_putnbr_fd(INT_MAX, fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 31 | /* 6 */ ASSERT_EQ_STR(buf, "01-142-422147483647"); 32 | ft_putnbr_fd(INT_MIN, fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 33 | /* 7 */ ASSERT_EQ_STR(buf, "01-142-422147483647-2147483648"); 34 | ft_putnbr_fd(INT_MAX - 1, fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 35 | /* 8 */ ASSERT_EQ_STR(buf, "01-142-422147483647-21474836482147483646"); 36 | ft_putnbr_fd(INT_MIN + 1, fd); lseek(fd, 0, SEEK_SET); bzero(buf, 1024); read(fd, buf, 1024); 37 | /* 9 */ ASSERT_EQ_STR(buf, "01-142-422147483647-21474836482147483646-2147483647"); 38 | close(fd); 39 | remove("tmp.txt"); 40 | return (0); 41 | } 42 | -------------------------------------------------------------------------------- /srcs/test_ft_lstiter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_lstiter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 19:27:05 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:05:40 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | static void str_toupper(void *p) 16 | { 17 | char *str = (char *)p; 18 | while (*str) 19 | { 20 | *str = toupper(*str); 21 | str++; 22 | } 23 | } 24 | 25 | static void str_tolower(void *p) 26 | { 27 | char *str = (char *)p; 28 | while (*str) 29 | { 30 | *str = tolower(*str); 31 | str++; 32 | } 33 | } 34 | 35 | int main(void) 36 | { 37 | t_list *lst = ft_lstnew(strdup("Hello")); 38 | ft_lstadd_back(&lst, ft_lstnew(strdup(" World"))); 39 | ft_lstadd_back(&lst, ft_lstnew(strdup(" 42"))); 40 | ft_lstadd_back(&lst, ft_lstnew(strdup(" Tokyo!"))); 41 | ft_lstadd_back(&lst, ft_lstnew(strdup(""))); 42 | 43 | 44 | // toupper 45 | ft_lstiter(lst, str_toupper); 46 | /* 1 */ ASSERT_EQ_STR(lst->content, "HELLO"); 47 | /* 2 */ ASSERT_EQ_STR(lst->next->content, " WORLD"); 48 | /* 3 */ ASSERT_EQ_STR(lst->next->next->content, " 42"); 49 | /* 4 */ ASSERT_EQ_STR(lst->next->next->next->content, " TOKYO!"); 50 | /* 5 */ ASSERT_EQ_STR(lst->next->next->next->next->content, ""); 51 | /* 6 */ ASSERT_EQ_PTR(lst->next->next->next->next->next, NULL); 52 | 53 | // tolower 54 | ft_lstiter(lst, str_tolower); 55 | /* 7 */ ASSERT_EQ_STR(lst->content, "hello"); 56 | /* 8 */ ASSERT_EQ_STR(lst->next->content, " world"); 57 | /* 9 */ ASSERT_EQ_STR(lst->next->next->content, " 42"); 58 | /* 10 */ ASSERT_EQ_STR(lst->next->next->next->content, " tokyo!"); 59 | /* 11 */ ASSERT_EQ_STR(lst->next->next->next->next->content, ""); 60 | /* 12 */ ASSERT_EQ_PTR(lst->next->next->next->next->next, NULL); 61 | } 62 | -------------------------------------------------------------------------------- /srcs/test_ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/18 07:44:16 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:10:17 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | char *s = "libft-test-tokyo"; 18 | /* 1 */ ASSERT_EQ_STR(ft_strrchr(s, 'l'), strrchr(s, 'l')); 19 | /* 2 */ ASSERT_EQ_STR(ft_strrchr(s, 'i'), strrchr(s, 'i')); 20 | /* 3 */ ASSERT_EQ_STR(ft_strrchr(s, 'b'), strrchr(s, 'b')); 21 | /* 4 */ ASSERT_EQ_STR(ft_strrchr(s, 'f'), strrchr(s, 'f')); 22 | /* 5 */ ASSERT_EQ_STR(ft_strrchr(s, 't'), strrchr(s, 't')); 23 | /* 6 */ ASSERT_EQ_STR(ft_strrchr(s, '-'), strrchr(s, '-')); 24 | /* 7 */ ASSERT_EQ_STR(ft_strrchr(s, 't'), strrchr(s, 't')); 25 | /* 8 */ ASSERT_EQ_STR(ft_strrchr(s, 'e'), strrchr(s, 'e')); 26 | /* 9 */ ASSERT_EQ_STR(ft_strrchr(s, 's'), strrchr(s, 's')); 27 | /* 10 */ ASSERT_EQ_STR(ft_strrchr(s, 't'), strrchr(s, 't')); 28 | /* 11 */ ASSERT_EQ_STR(ft_strrchr(s, '-'), strrchr(s, '-')); 29 | /* 12 */ ASSERT_EQ_STR(ft_strrchr(s, 't'), strrchr(s, 't')); 30 | /* 13 */ ASSERT_EQ_STR(ft_strrchr(s, 'o'), strrchr(s, 'o')); 31 | /* 14 */ ASSERT_EQ_STR(ft_strrchr(s, 'k'), strrchr(s, 'k')); 32 | /* 15 */ ASSERT_EQ_STR(ft_strrchr(s, 'y'), strrchr(s, 'y')); 33 | /* 16 */ ASSERT_EQ_STR(ft_strrchr(s, 'o'), strrchr(s, 'o')); 34 | /* 17 */ ASSERT_EQ_STR(ft_strrchr(s, '\0'), strrchr(s, '\0')); 35 | /* 18 */ ASSERT_EQ_STR(ft_strrchr(s, 'l' + 256), strrchr(s, 'l' + 256)); 36 | /* 19 */ ASSERT_EQ_STR(ft_strrchr(s, 'i' + 256), strrchr(s, 'i' + 256)); 37 | /* 20 */ ASSERT_EQ_STR(ft_strrchr(s, 'l' - 256), strrchr(s, 'l' - 256)); 38 | /* 21 */ ASSERT_EQ_STR(ft_strrchr(s, 'i' - 256), strrchr(s, 'i' - 256)); 39 | /* 22 */ ASSERT_EQ_STR(ft_strrchr(s, 'z'), strrchr(s, 'z')); 40 | /* 23 */ ASSERT_EQ_STR(ft_strrchr(s, '~'), strrchr(s, '~')); 41 | return (0); 42 | } 43 | -------------------------------------------------------------------------------- /srcs/test_ft_lstmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_lstmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/21 11:33:52 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:06:05 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | static void *str_toupper(void *p) 16 | { 17 | char *str = strdup((char *)p); 18 | char *tmp = str; 19 | while (*tmp) 20 | { 21 | *tmp = toupper(*tmp); 22 | tmp++; 23 | } 24 | return (str); 25 | } 26 | 27 | static void *str_tolower(void *p) 28 | { 29 | char *str = strdup((char *)p); 30 | char *tmp = str; 31 | while (*tmp) 32 | { 33 | *tmp = tolower(*tmp); 34 | tmp++; 35 | } 36 | return (str); 37 | } 38 | 39 | int main(void) 40 | { 41 | t_list *lst = ft_lstnew(strdup("Hello")); 42 | ft_lstadd_back(&lst, ft_lstnew(strdup(" World"))); 43 | ft_lstadd_back(&lst, ft_lstnew(strdup(" 42"))); 44 | ft_lstadd_back(&lst, ft_lstnew(strdup(" Tokyo!"))); 45 | ft_lstadd_back(&lst, ft_lstnew(strdup(""))); 46 | 47 | // toupper 48 | t_list *newlst = ft_lstmap(lst, str_toupper, free); 49 | /* 1 */ ASSERT_EQ_STR(newlst->content, "HELLO"); 50 | /* 2 */ ASSERT_EQ_STR(newlst->next->content, " WORLD"); 51 | /* 3 */ ASSERT_EQ_STR(newlst->next->next->content, " 42"); 52 | /* 4 */ ASSERT_EQ_STR(newlst->next->next->next->content, " TOKYO!"); 53 | /* 5 */ ASSERT_EQ_STR(newlst->next->next->next->next->content, ""); 54 | /* 6 */ ASSERT_EQ_PTR(newlst->next->next->next->next->next, NULL); 55 | 56 | // tolower 57 | newlst = ft_lstmap(lst, str_tolower, free); 58 | /* 7 */ ASSERT_EQ_STR(newlst->content, "hello"); 59 | /* 8 */ ASSERT_EQ_STR(newlst->next->content, " world"); 60 | /* 9 */ ASSERT_EQ_STR(newlst->next->next->content, " 42"); 61 | /* 10 */ ASSERT_EQ_STR(newlst->next->next->next->content, " tokyo!"); 62 | /* 11 */ ASSERT_EQ_STR(newlst->next->next->next->next->content, ""); 63 | /* 12 */ ASSERT_EQ_PTR(newlst->next->next->next->next->next, NULL); 64 | } 65 | -------------------------------------------------------------------------------- /srcs/test_ft_lstdelone.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_lstdelone.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 12:22:17 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:05:32 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | static int counter = 0; 16 | static void *freed = NULL; 17 | static void cnt_free(void *p) { 18 | counter++; 19 | freed = p; 20 | free(p); 21 | } 22 | 23 | static void void_free(void *p) { 24 | counter++; 25 | freed = p; 26 | } 27 | 28 | int main(void) 29 | { 30 | t_list *elem1 = calloc(sizeof(t_list), 1); 31 | t_list *elem2 = calloc(sizeof(t_list), 1); 32 | t_list *elem3 = calloc(sizeof(t_list), 1); 33 | t_list *elem4 = calloc(sizeof(t_list), 1); 34 | t_list *elem5 = calloc(sizeof(t_list), 1); 35 | char *s1 = strdup("hello"); 36 | char *s2 = strdup("world"); 37 | char *s3 = strdup("42!"); 38 | int val4 = 42; 39 | int val5 = -42; 40 | elem1->content = s1; 41 | elem2->content = s2; 42 | elem3->content = s3; 43 | elem4->content = &val4; 44 | elem5->content = &val5; 45 | 46 | /* size = 0 */ 47 | t_list *lst = NULL; 48 | ft_lstdelone(lst, cnt_free); 49 | /* 1 */ ASSERT_EQ_PTR(lst, NULL); 50 | /* 2 */ ASSERT_EQ_I(counter, 0); 51 | 52 | 53 | /* size = 1 */ 54 | lst = elem1; 55 | ft_lstdelone(lst, cnt_free); 56 | /* 3 */ ASSERT_EQ_PTR(lst, elem1); 57 | /* 4 */ ASSERT_EQ_I(counter, 1); 58 | /* 5 */ ASSERT_EQ_PTR(freed, s1); 59 | 60 | /* size = 4 */ 61 | lst = elem2; 62 | elem2->next = elem3; 63 | elem3->next = elem4; 64 | elem4->next = elem5; 65 | ft_lstdelone(lst, cnt_free); 66 | /* 6 */ ASSERT_EQ_PTR(lst, elem2); 67 | /* 7 */ ASSERT_EQ_I(counter, 2); 68 | /* 8 */ ASSERT_EQ_PTR(freed, s2); 69 | 70 | ft_lstdelone(elem5, void_free); 71 | /* 9 */ ASSERT_EQ_PTR(lst, elem2); 72 | /* 10 */ ASSERT_EQ_I(counter, 3); 73 | /* 11 */ ASSERT_EQ_PTR(freed, &val5); 74 | 75 | // Segmentaiton Fault 76 | // /* */ ft_lstdelone(elem4, NULL); 77 | } 78 | -------------------------------------------------------------------------------- /srcs/test_ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/15 16:53:15 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:02:28 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | /* 1 */ ASSERT_EQ_I(ft_isalnum('a'), isalnum('a')); 18 | /* 2 */ ASSERT_EQ_I(ft_isalnum('a' - 1), isalnum('a' - 1)); 19 | /* 3 */ ASSERT_EQ_I(ft_isalnum('a' + 1), isalnum('a' + 1)); 20 | /* 4 */ ASSERT_EQ_I(ft_isalnum('z'), isalnum('z')); 21 | /* 5 */ ASSERT_EQ_I(ft_isalnum('z' - 1), isalnum('z' - 1)); 22 | /* 6 */ ASSERT_EQ_I(ft_isalnum('z' + 1), isalnum('z' + 1)); 23 | /* 7 */ ASSERT_EQ_I(ft_isalnum('A'), isalnum('A')); 24 | /* 8 */ ASSERT_EQ_I(ft_isalnum('A' - 1), isalnum('A' - 1)); 25 | /* 9 */ ASSERT_EQ_I(ft_isalnum('A' + 1), isalnum('A' + 1)); 26 | /* 10 */ ASSERT_EQ_I(ft_isalnum('Z'), isalnum('Z')); 27 | /* 11 */ ASSERT_EQ_I(ft_isalnum('Z' - 1), isalnum('Z' - 1)); 28 | /* 12 */ ASSERT_EQ_I(ft_isalnum('Z' + 1), isalnum('Z' + 1)); 29 | /* 13 */ ASSERT_EQ_I(ft_isalnum('a' + 256), isalnum('a' + 256)); 30 | /* 14 */ ASSERT_EQ_I(ft_isalnum('a' - 256), isalnum('a' - 256)); 31 | /* 15 */ ASSERT_EQ_I(ft_isalnum('a' + 1), isalnum('a' + 1)); 32 | /* 16 */ ASSERT_EQ_I(ft_isalnum('0'), isalnum('0')); 33 | /* 17 */ ASSERT_EQ_I(ft_isalnum('0' - 1), isalnum('0' - 1)); 34 | /* 18 */ ASSERT_EQ_I(ft_isalnum('0' + 1), isalnum('0' + 1)); 35 | /* 19 */ ASSERT_EQ_I(ft_isalnum('9'), isalnum('9')); 36 | /* 20 */ ASSERT_EQ_I(ft_isalnum('9' - 1), isalnum('9' - 1)); 37 | /* 21 */ ASSERT_EQ_I(ft_isalnum('9' + 1), isalnum('9' + 1)); 38 | /* 22 */ ASSERT_EQ_I(ft_isalnum('!'), isalnum('!')); 39 | /* 23 */ ASSERT_EQ_I(ft_isalnum('{'), isalnum('}')); 40 | /* 24 */ ASSERT_EQ_I(ft_isalnum('~'), isalnum('~')); 41 | /* 25. zero */ ASSERT_EQ_I(ft_isalnum(0), isalnum(0)); 42 | /* 26. INI_MAX */ ASSERT_EQ_I(ft_isalnum(INT_MAX), isalnum(INT_MAX)); 43 | /* 27. INT_MIN */ ASSERT_EQ_I(ft_isalnum(INT_MIN), isalnum(INT_MIN)); 44 | /* 28 (-256~255) */ for (int i = -256; i < 256; i++) { ASSERT_EQ_I(ft_isalnum(i), isalnum(i)); } 45 | return (0); 46 | } 47 | -------------------------------------------------------------------------------- /srcs/test_ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_isascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/15 16:54:50 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:03:42 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | /* 1 */ ASSERT_EQ_I(ft_isascii('a'), isascii('a')); 18 | /* 2 */ ASSERT_EQ_I(ft_isascii('a' - 1), isascii('a' - 1)); 19 | /* 3 */ ASSERT_EQ_I(ft_isascii('a' + 1), isascii('a' + 1)); 20 | /* 4 */ ASSERT_EQ_I(ft_isascii('z'), isascii('z')); 21 | /* 5 */ ASSERT_EQ_I(ft_isascii('z' - 1), isascii('z' - 1)); 22 | /* 6 */ ASSERT_EQ_I(ft_isascii('z' + 1), isascii('z' + 1)); 23 | /* 7 */ ASSERT_EQ_I(ft_isascii('A'), isascii('A')); 24 | /* 8 */ ASSERT_EQ_I(ft_isascii('A' - 1), isascii('A' - 1)); 25 | /* 9 */ ASSERT_EQ_I(ft_isascii('A' + 1), isascii('A' + 1)); 26 | /* 10 */ ASSERT_EQ_I(ft_isascii('Z'), isascii('Z')); 27 | /* 11 */ ASSERT_EQ_I(ft_isascii('Z' - 1), isascii('Z' - 1)); 28 | /* 12 */ ASSERT_EQ_I(ft_isascii('Z' + 1), isascii('Z' + 1)); 29 | /* 13 */ ASSERT_EQ_I(ft_isascii('a' + 256), isascii('a' + 256)); 30 | /* 14 */ ASSERT_EQ_I(ft_isascii('a' - 256), isascii('a' - 256)); 31 | /* 15 */ ASSERT_EQ_I(ft_isascii('a' + 1), isascii('a' + 1)); 32 | /* 16 */ ASSERT_EQ_I(ft_isascii('0'), isascii('0')); 33 | /* 17 */ ASSERT_EQ_I(ft_isascii('0' - 1), isascii('0' - 1)); 34 | /* 18 */ ASSERT_EQ_I(ft_isascii('0' + 1), isascii('0' + 1)); 35 | /* 19 */ ASSERT_EQ_I(ft_isascii('9'), isascii('9')); 36 | /* 20 */ ASSERT_EQ_I(ft_isascii('9' - 1), isascii('9' - 1)); 37 | /* 21 */ ASSERT_EQ_I(ft_isascii('9' + 1), isascii('9' + 1)); 38 | /* 22 */ ASSERT_EQ_I(ft_isascii('!'), isascii('!')); 39 | /* 23 */ ASSERT_EQ_I(ft_isascii('{'), isascii('}')); 40 | /* 24 */ ASSERT_EQ_I(ft_isascii('~'), isascii('~')); 41 | /* 25. zero */ ASSERT_EQ_I(ft_isascii(0), isascii(0)); 42 | /* 26. INI_MAX */ ASSERT_EQ_I(ft_isascii(INT_MAX), isascii(INT_MAX)); 43 | /* 27. INT_MIN */ ASSERT_EQ_I(ft_isascii(INT_MIN), isascii(INT_MIN)); 44 | /* 28 (-256~255) */ for (int i = -256; i < 256; i++) { ASSERT_EQ_I(ft_isascii(i), isascii(i)); } 45 | return (0); 46 | } 47 | -------------------------------------------------------------------------------- /srcs/test_ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/15 16:56:06 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:03:55 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | /* 1 */ ASSERT_EQ_I(ft_isprint('a'), isprint('a')); 18 | /* 2 */ ASSERT_EQ_I(ft_isprint('a' - 1), isprint('a' - 1)); 19 | /* 3 */ ASSERT_EQ_I(ft_isprint('a' + 1), isprint('a' + 1)); 20 | /* 4 */ ASSERT_EQ_I(ft_isprint('z'), isprint('z')); 21 | /* 5 */ ASSERT_EQ_I(ft_isprint('z' - 1), isprint('z' - 1)); 22 | /* 6 */ ASSERT_EQ_I(ft_isprint('z' + 1), isprint('z' + 1)); 23 | /* 7 */ ASSERT_EQ_I(ft_isprint('A'), isprint('A')); 24 | /* 8 */ ASSERT_EQ_I(ft_isprint('A' - 1), isprint('A' - 1)); 25 | /* 9 */ ASSERT_EQ_I(ft_isprint('A' + 1), isprint('A' + 1)); 26 | /* 10 */ ASSERT_EQ_I(ft_isprint('Z'), isprint('Z')); 27 | /* 11 */ ASSERT_EQ_I(ft_isprint('Z' - 1), isprint('Z' - 1)); 28 | /* 12 */ ASSERT_EQ_I(ft_isprint('Z' + 1), isprint('Z' + 1)); 29 | /* 13 */ ASSERT_EQ_I(ft_isprint('a' + 256), isprint('a' + 256)); 30 | /* 14 */ ASSERT_EQ_I(ft_isprint('a' - 256), isprint('a' - 256)); 31 | /* 15 */ ASSERT_EQ_I(ft_isprint('a' + 1), isprint('a' + 1)); 32 | /* 16 */ ASSERT_EQ_I(ft_isprint('0'), isprint('0')); 33 | /* 17 */ ASSERT_EQ_I(ft_isprint('0' - 1), isprint('0' - 1)); 34 | /* 18 */ ASSERT_EQ_I(ft_isprint('0' + 1), isprint('0' + 1)); 35 | /* 19 */ ASSERT_EQ_I(ft_isprint('9'), isprint('9')); 36 | /* 20 */ ASSERT_EQ_I(ft_isprint('9' - 1), isprint('9' - 1)); 37 | /* 21 */ ASSERT_EQ_I(ft_isprint('9' + 1), isprint('9' + 1)); 38 | /* 22 */ ASSERT_EQ_I(ft_isprint('!'), isprint('!')); 39 | /* 23 */ ASSERT_EQ_I(ft_isprint('{'), isprint('}')); 40 | /* 24 */ ASSERT_EQ_I(ft_isprint('~'), isprint('~')); 41 | /* 25. zero */ ASSERT_EQ_I(ft_isprint(0), isprint(0)); 42 | /* 26. INI_MAX */ ASSERT_EQ_I(ft_isprint(INT_MAX), isprint(INT_MAX)); 43 | /* 27. INT_MIN */ ASSERT_EQ_I(ft_isprint(INT_MIN), isprint(INT_MIN)); 44 | /* 28 (-256~255) */ for (int i = -256; i < 256; i++) { ASSERT_EQ_I(ft_isprint(i), isprint(i)); } 45 | return (0); 46 | } 47 | -------------------------------------------------------------------------------- /srcs/test_ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/18 08:56:22 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:11:08 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | int len = 30; 18 | char *str = calloc(30, sizeof(char)); 19 | char *cmp = calloc(30, sizeof(char)); 20 | memcpy(str, "libft-test-tokyo", 16); 21 | memcpy(cmp, "libft-test-tokyo", 16); 22 | memcpy(str + 20, "acdfg", 5); 23 | memcpy(cmp + 20, "acdfg", 5); 24 | /* 1 ~ 31 */ 25 | for (int i = 0; i <= len; i++) 26 | ASSERT_EQ_I(ft_memcmp(str, cmp, i), memcmp(str, cmp, i)); 27 | /* 32 ~ 93 */ 28 | for (int i = 0; i <= len; i++) 29 | { 30 | cmp = strndup(str, i); 31 | ASSERT_EQ_I(ft_memcmp(str, cmp, i), memcmp(str, cmp, i)); 32 | ASSERT_EQ_I(ft_memcmp(str, cmp, len), memcmp(str, cmp, len)); 33 | free(cmp); 34 | } 35 | char *cmp2 = calloc(30, sizeof(char)); 36 | strlcpy(cmp2, "libft", sizeof(char)); 37 | cmp2[5] = CHAR_MIN; 38 | /* 94 */ ASSERT_EQ_I(ft_memcmp(str, cmp2, len), memcmp(str, cmp2, len)); 39 | cmp2[5] = -42; 40 | /* 95 */ ASSERT_EQ_I(ft_memcmp(str, cmp2, len), memcmp(str, cmp2, len)); 41 | cmp2[5] = 0; 42 | /* 96 */ ASSERT_EQ_I(ft_memcmp(str, cmp2, len), memcmp(str, cmp2, len)); 43 | cmp2[5] = 42; 44 | /* 97 */ ASSERT_EQ_I(ft_memcmp(str, cmp2, len), memcmp(str, cmp2, len)); 45 | cmp2[5] = CHAR_MAX; 46 | /* 98 */ ASSERT_EQ_I(ft_memcmp(str, cmp2, len), memcmp(str, cmp2, len)); 47 | 48 | strlcpy(cmp2, "libft-test-tokyo", sizeof(char)); 49 | strlcpy(cmp2 + 20, "acdfg", sizeof(char)); 50 | cmp2[29] = CHAR_MIN; 51 | /* 99 */ ASSERT_EQ_I(ft_memcmp(str, cmp2, len), memcmp(str, cmp2, len)); 52 | cmp2[29] = -42; 53 | /* 100 */ ASSERT_EQ_I(ft_memcmp(str, cmp2, len), memcmp(str, cmp2, len)); 54 | cmp2[29] = 0; 55 | /* 101 */ ASSERT_EQ_I(ft_memcmp(str, cmp2, len), memcmp(str, cmp2, len)); 56 | cmp2[29] = 42; 57 | /* 102 */ ASSERT_EQ_I(ft_memcmp(str, cmp2, len), memcmp(str, cmp2, len)); 58 | cmp2[29] = CHAR_MAX; 59 | /* 103 */ ASSERT_EQ_I(ft_memcmp(str, cmp2, len), memcmp(str, cmp2, len)); 60 | return (0); 61 | } 62 | -------------------------------------------------------------------------------- /srcs/test_ft_lstclear.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_lstclear.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 13:53:53 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:05:23 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | static int counter = 0; 16 | static void *freed[10] = {}; 17 | static void cnt_free(void *p) { 18 | freed[counter++] = p; 19 | free(p); 20 | } 21 | 22 | static void void_free(void *p) { 23 | freed[counter++] = p; 24 | } 25 | 26 | static int contains(void *arr[10], void *p) 27 | { 28 | for (int i = 0; i < 10; i++) 29 | { 30 | if (arr[i] == p) 31 | return (1); 32 | } 33 | return (0); 34 | } 35 | 36 | int main(void) 37 | { 38 | t_list *elem1 = calloc(sizeof(t_list), 1); 39 | t_list *elem2 = calloc(sizeof(t_list), 1); 40 | t_list *elem3 = calloc(sizeof(t_list), 1); 41 | t_list *elem4 = calloc(sizeof(t_list), 1); 42 | t_list *elem5 = calloc(sizeof(t_list), 1); 43 | char *s1 = strdup("hello"); 44 | char *s2 = strdup("world"); 45 | char *s3 = strdup("42!"); 46 | int val4 = 42; 47 | int val5 = -42; 48 | elem1->content = s1; 49 | elem2->content = s2; 50 | elem3->content = s3; 51 | elem4->content = &val4; 52 | elem5->content = &val5; 53 | elem1->next = elem2; 54 | elem2->next = elem3; 55 | elem3->next = elem4; 56 | elem4->next = elem5; 57 | 58 | /* size = 0 */ 59 | t_list *lst = NULL; 60 | ft_lstclear(&lst, cnt_free); 61 | /* 1 */ ASSERT_EQ_PTR(lst, NULL); 62 | /* 2 */ ASSERT_EQ_I(counter, 0); 63 | 64 | 65 | /* size = 2 */ 66 | lst = elem4; 67 | ft_lstclear(&lst, void_free); 68 | /* 3 */ ASSERT_EQ_PTR(lst, NULL); 69 | /* 4 */ ASSERT_EQ_I(counter, 2); 70 | /* 5 */ ASSERT_TRUE(contains(freed, &val5)); 71 | 72 | /* size = 3 */ 73 | lst = elem1; 74 | elem3->next = NULL; 75 | ft_lstclear(&lst, cnt_free); 76 | /* 6 */ ASSERT_EQ_PTR(lst, NULL); 77 | /* 7 */ ASSERT_EQ_I(counter, 5); 78 | /* 8 */ ASSERT_TRUE(contains(freed, s1)); 79 | /* 9 */ ASSERT_TRUE(contains(freed, s2)); 80 | /* 10 */ ASSERT_TRUE(contains(freed, s3)); 81 | } 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # How to use 2 | 3 | 1. Clone this repository to the root directory of your libft repository. 4 | 2. Run the make command inside this repository. 5 | 6 | 7 | ## 1. Clone this repository 8 | ``` 9 | $ cd /path/to/your/libft/directory 10 | $ git clone https://github.com/usatie/libft-tester-tokyo.git 11 | $ cd libft-tester-tokyo 12 | ``` 13 | 14 | * If you would like to clone this repository to somewhere else, you can. 15 | In that case, please run the make command like this. 16 | ``` 17 | $ make LIBFT_DIR=/path/to/your/libft/dir 18 | ``` 19 | 20 | ## 2. Test Mandatory functions 21 | ``` 22 | $ make all 23 | ``` 24 | 25 | If you want to test Libft-00 ~ Libft-02, please use below. (Please change part number `00` to same as your project.) 26 | 27 | ``` 28 | $ make libft-00 29 | ``` 30 | 31 | Screen Shot 2022-04-18 at 9 34 55 32 | 33 | ## 3. Test Bonus functions 34 | ``` 35 | $ make bonus 36 | ``` 37 | 38 | ## 4. Test individual function 39 | ``` 40 | $ make strlen 41 | $ make atoi 42 | $ make strnstr 43 | ``` 44 | 45 | If you want to test functions when trying to Libft-00 ~ Libft-02, please type with suffix `.re` like below. 46 | 47 | ``` 48 | $ make strlen.re 49 | $ make atoi.re 50 | $ make strnstr.re 51 | ``` 52 | 53 | Screen Shot 2022-04-18 at 9 35 27 54 | 55 | ## 5. Test Norminette & coding rules 56 | ``` 57 | $ make norm 58 | ``` 59 | 60 | If you want to run norm check for Libft-00 ~ Libft-02, please use below. (Please change part number `00` to same as your project.) 61 | 62 | ``` 63 | $ make norm00 64 | ``` 65 | 66 | Screen Shot 2022-04-18 at 15 27 40 67 | 68 | 69 | # Please add more test cases! 70 | Thanks for trying it out! 71 | If you notice anything or want to add some test cases, feel free to send issues/PRs! 72 | 73 | ## Sample Code for your first contribution 74 | `ASSERT_EQ`functions are very easy to use. 75 | Basically the first argument is the actual value and the second argument is the expected value. 76 | for creating unit tests 77 | ``` 78 | int main(void) 79 | { 80 | ASSERT_EQ_I(ft_atoi("123"), 123); 81 | ASSERT_EQ_I(ft_atoi("-42"), -42); 82 | 83 | ASSERT_EQ_STR(ft_itoa(123), "123"); 84 | ASSERT_EQ_STR(ft_itoa(-42), "-42"); 85 | 86 | int len = 10; 87 | char *actual = ft_calloc(len, sizeof(char)); 88 | char *expected = calloc(len, sizeof(char)); 89 | ASSERT_EQ_MEM(actual, expected, len); 90 | } 91 | ``` 92 | 93 | ## Thanks predecessors! 94 | This project is inspired by these projects, and many cases are imported from them too. 95 | Thanks a lot! 96 | - https://github.com/Tripouille/libftTester 97 | - https://github.com/alelievr/libft-unit-test 98 | -------------------------------------------------------------------------------- /srcs/test_ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/17 21:57:05 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:09:30 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | char *dst1 = calloc(10, sizeof(char)); 18 | char *dst2 = calloc(10, sizeof(char)); 19 | char *src1 = calloc(10, sizeof(char)); 20 | char *src2 = calloc(10, sizeof(char)); 21 | memset(src1, 'z', 9); 22 | memset(src2, 'z', 9); 23 | 24 | /* 1 */ ASSERT_EQ_I(ft_strlcpy(dst1, "", 10), strlcpy(dst2, "", 10)); 25 | /* 2 */ ASSERT_EQ_STR(dst1, dst2); 26 | /* 3 */ ASSERT_EQ_I(ft_strlcpy(dst1, "hello", 10), strlcpy(dst2, "hello", 10)); 27 | /* 4 */ ASSERT_EQ_STR(dst1, dst2); 28 | /* 5 */ ASSERT_EQ_I(ft_strlcpy(dst1, "world", 10), strlcpy(dst2, "world", 10)); 29 | /* 6 */ ASSERT_EQ_STR(dst1, dst2); 30 | /* 7 */ ASSERT_EQ_I(ft_strlcpy(dst1, src1, 0), strlcpy(dst2, src2, 0)); 31 | /* 8 */ ASSERT_EQ_STR(dst1, dst2); 32 | /* 9 */ ASSERT_EQ_I(ft_strlcpy(dst1, src1, 10), strlcpy(dst2, src2, 10)); 33 | /* 10 */ ASSERT_EQ_I(ft_strlcpy(NULL, "", 0), strlcpy(NULL, "", 0)); 34 | bzero(dst1, 10); 35 | bzero(dst2, 10); 36 | 37 | char *s1 = "hello"; 38 | char *s2 = "hello wonderfule world!"; 39 | /* 11 ~ 20 */ 40 | for (size_t i = 0; i < strlen(s1); i++) 41 | { 42 | ASSERT_EQ_I(ft_strlcpy(dst1, s1, i), strlcpy(dst2, s1, i)); 43 | ASSERT_EQ_STR(dst1, dst2); 44 | } 45 | /* 21 ~ 40 */ 46 | for (int i = 0; i < 10; i++) 47 | { 48 | ASSERT_EQ_I(ft_strlcpy(dst1, s2, 10), strlcpy(dst2, s2, 10)); 49 | ASSERT_EQ_STR(dst1, dst2); 50 | } 51 | /* 41 */ ASSERT_EQ_I(ft_strlcpy(dst1, "", 10), strlcpy(dst2, "", 10)); 52 | /* 42 */ ASSERT_EQ_STR(dst1, dst2); 53 | /* 43 */ ASSERT_EQ_I(ft_strlcpy(dst1, "hello", 10), strlcpy(dst2, "hello", 10)); 54 | /* 44 */ ASSERT_EQ_STR(dst1, dst2); 55 | /* 45 */ ASSERT_EQ_I(ft_strlcpy(dst1, "world", 10), strlcpy(dst2, "world", 10)); 56 | /* 46 */ ASSERT_EQ_STR(dst1, dst2); 57 | /* 47 */ ASSERT_EQ_I(ft_strlcpy(dst1, src1, 0), strlcpy(dst2, src2, 0)); 58 | /* 48 */ ASSERT_EQ_STR(dst1, dst2); 59 | /* 49 */ ASSERT_EQ_I(ft_strlcpy(dst1, src1, 10), strlcpy(dst2, src2, 10)); 60 | /* 50 */ ASSERT_EQ_I(ft_strlcpy(NULL, "", 0), strlcpy(NULL, "", 0)); 61 | } 62 | -------------------------------------------------------------------------------- /srcs/test_ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/18 08:41:43 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:11:03 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | // s = "libft-test-tokyo\0\0\0acdfg\0\0\0\0\0" 18 | char *s = calloc(30, sizeof(char)); 19 | memcpy(s, "libft-test-tokyo", 17); 20 | memcpy(s + 20, "acdfg", 5); 21 | /* 1 */ ASSERT_EQ_PTR(ft_memchr(s, 'l', 30), memchr(s, 'l', 30)); 22 | /* 2 */ ASSERT_EQ_PTR(ft_memchr(s, 'i', 30), memchr(s, 'i', 30)); 23 | /* 3 */ ASSERT_EQ_PTR(ft_memchr(s, 'b', 30), memchr(s, 'b', 30)); 24 | /* 4 */ ASSERT_EQ_PTR(ft_memchr(s, 'f', 30), memchr(s, 'f', 30)); 25 | /* 5 */ ASSERT_EQ_PTR(ft_memchr(s, 't', 30), memchr(s, 't', 30)); 26 | /* 6 */ ASSERT_EQ_PTR(ft_memchr(s, '-', 30), memchr(s, '-', 30)); 27 | /* 7 */ ASSERT_EQ_PTR(ft_memchr(s, 't', 30), memchr(s, 't', 30)); 28 | /* 8 */ ASSERT_EQ_PTR(ft_memchr(s, 'e', 30), memchr(s, 'e', 30)); 29 | /* 9 */ ASSERT_EQ_PTR(ft_memchr(s, 's', 30), memchr(s, 's', 30)); 30 | /* 10 */ ASSERT_EQ_PTR(ft_memchr(s, 't', 30), memchr(s, 't', 30)); 31 | /* 11 */ ASSERT_EQ_PTR(ft_memchr(s, '-', 30), memchr(s, '-', 30)); 32 | /* 12 */ ASSERT_EQ_PTR(ft_memchr(s, 't', 30), memchr(s, 't', 30)); 33 | /* 13 */ ASSERT_EQ_PTR(ft_memchr(s, 'o', 30), memchr(s, 'o', 30)); 34 | /* 14 */ ASSERT_EQ_PTR(ft_memchr(s, 'k', 30), memchr(s, 'k', 30)); 35 | /* 15 */ ASSERT_EQ_PTR(ft_memchr(s, 'y', 30), memchr(s, 'y', 30)); 36 | /* 16 */ ASSERT_EQ_PTR(ft_memchr(s, 'o', 30), memchr(s, 'o', 30)); 37 | /* 17 */ ASSERT_EQ_PTR(ft_memchr(s, '\0', 30), memchr(s, '\0', 30)); 38 | 39 | // char overflow 40 | /* 18 */ ASSERT_EQ_PTR(ft_memchr(s, 'l' + 256, 30), memchr(s, 'l' + 256, 30)); 41 | /* 19 */ ASSERT_EQ_PTR(ft_memchr(s, 'i' + 256, 30), memchr(s, 'i' + 256, 30)); 42 | /* 20 */ ASSERT_EQ_PTR(ft_memchr(s, 'l' - 256, 30), memchr(s, 'l' - 256, 30)); 43 | /* 21 */ ASSERT_EQ_PTR(ft_memchr(s, 'i' - 256, 30), memchr(s, 'i' - 256, 30)); 44 | 45 | // unseen characters 46 | /* 22 */ ASSERT_EQ_PTR(ft_memchr(s, 'z', 30), memchr(s, 'z', 30)); 47 | /* 23 */ ASSERT_EQ_PTR(ft_memchr(s, '~', 30), memchr(s, '~', 30)); 48 | 49 | // characters after' \0' 50 | /* 24 */ ASSERT_EQ_PTR(ft_memchr(s, 'a', 30), memchr(s, 'a', 30)); 51 | /* 25 */ ASSERT_EQ_PTR(ft_memchr(s, 'c', 30), memchr(s, 'c', 30)); 52 | /* 26 */ ASSERT_EQ_PTR(ft_memchr(s, 'd', 30), memchr(s, 'd', 30)); 53 | /* 27 */ ASSERT_EQ_PTR(ft_memchr(s, 'f', 30), memchr(s, 'f', 30)); 54 | /* 28 */ ASSERT_EQ_PTR(ft_memchr(s, 'g', 30), memchr(s, 'g', 30)); 55 | return (0); 56 | } 57 | -------------------------------------------------------------------------------- /includes/libassert.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libassert.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/13 07:52:22 by susami #+# #+# */ 9 | /* Updated: 2022/04/18 08:46:35 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBASSERT_H 14 | # define LIBASSERT_H 15 | # include 16 | # include 17 | # include 18 | void ASSERT_TRUE(bool actual, 19 | char *caller_file, const char *caller_func, int caller_line); 20 | void ASSERT_EQ_I(int actual, int expected, 21 | char *caller_file, const char *caller_func, int caller_line); 22 | void ASSERT_EQ_UI(unsigned int actual, unsigned int expected, 23 | char *caller_file, const char *caller_func, int caller_line); 24 | void ASSERT_EQ_L(long actual, long expected, 25 | char *caller_file, const char *caller_func, int caller_line); 26 | void ASSERT_EQ_UL(unsigned long actual, unsigned long expected, 27 | char *caller_file, const char *caller_func, int caller_line); 28 | void ASSERT_EQ_LL(long long actual, long long expected, 29 | char *caller_file, const char *caller_func, int caller_line); 30 | void ASSERT_EQ_ULL(unsigned long long actual, unsigned long long expected, 31 | char *caller_file, const char *caller_func, int caller_line); 32 | void ASSERT_EQ_SIZE(size_t actual, size_t expected, 33 | char *caller_file, const char *caller_func, int caller_line); 34 | void ASSERT_EQ_STR(char *actual, char *expected, 35 | char *caller_file, const char *caller_func, int caller_line); 36 | void ASSERT_EQ_MALLOC_SIZE(void *actual, void *expected, 37 | char *caller_file, const char *caller_func, int caller_line); 38 | void ASSERT_EQ_MEM(void *actual, void *expected, size_t size, 39 | char *caller_file, const char *caller_func, int caller_line); 40 | void ASSERT_EQ_PTR(void *actual, void *expected, 41 | char *caller_file, const char *caller_func, int caller_line); 42 | # define ASSERT_TRUE(x) ASSERT_TRUE(x, __FILE__,__func__,__LINE__) 43 | # define ASSERT_EQ_I(x, y) ASSERT_EQ_I(x, y, __FILE__,__func__,__LINE__) 44 | # define ASSERT_EQ_UI(x, y) ASSERT_EQ_UI(x, y, __FILE__,__func__,__LINE__) 45 | # define ASSERT_EQ_L(x, y) ASSERT_EQ_L(x, y, __FILE__,__func__,__LINE__) 46 | # define ASSERT_EQ_UL(x, y) ASSERT_EQ_UL(x, y, __FILE__,__func__,__LINE__) 47 | # define ASSERT_EQ_LL(x, y) ASSERT_EQ_LL(x, y, __FILE__,__func__,__LINE__) 48 | # define ASSERT_EQ_ULL(x, y) ASSERT_EQ_ULL(x, y, __FILE__,__func__,__LINE__) 49 | # define ASSERT_EQ_SIZE(x, y) ASSERT_EQ_SIZE(x, y, __FILE__,__func__,__LINE__) 50 | # define ASSERT_EQ_STR(x, y) ASSERT_EQ_STR(x, y, __FILE__,__func__,__LINE__) 51 | # define ASSERT_EQ_MALLOC_SIZE(x, y) ASSERT_EQ_MALLOC_SIZE(x, y, __FILE__,__func__,__LINE__) 52 | # define ASSERT_EQ_MEM(x, y, z) ASSERT_EQ_MEM(x, y, z, __FILE__,__func__,__LINE__) 53 | # define ASSERT_EQ_PTR(x, y) ASSERT_EQ_PTR(x, y, __FILE__,__func__,__LINE__) 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /libs/libassert/libassert.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libassert.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/13 07:52:22 by susami #+# #+# */ 9 | /* Updated: 2022/04/18 08:46:35 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBASSERT_H 14 | # define LIBASSERT_H 15 | # include 16 | # include 17 | # include 18 | void ASSERT_TRUE(bool actual, 19 | char *caller_file, const char *caller_func, int caller_line); 20 | void ASSERT_EQ_I(int actual, int expected, 21 | char *caller_file, const char *caller_func, int caller_line); 22 | void ASSERT_EQ_UI(unsigned int actual, unsigned int expected, 23 | char *caller_file, const char *caller_func, int caller_line); 24 | void ASSERT_EQ_L(long actual, long expected, 25 | char *caller_file, const char *caller_func, int caller_line); 26 | void ASSERT_EQ_UL(unsigned long actual, unsigned long expected, 27 | char *caller_file, const char *caller_func, int caller_line); 28 | void ASSERT_EQ_LL(long long actual, long long expected, 29 | char *caller_file, const char *caller_func, int caller_line); 30 | void ASSERT_EQ_ULL(unsigned long long actual, unsigned long long expected, 31 | char *caller_file, const char *caller_func, int caller_line); 32 | void ASSERT_EQ_SIZE(size_t actual, size_t expected, 33 | char *caller_file, const char *caller_func, int caller_line); 34 | void ASSERT_EQ_STR(char *actual, char *expected, 35 | char *caller_file, const char *caller_func, int caller_line); 36 | void ASSERT_EQ_MALLOC_SIZE(void *actual, void *expected, 37 | char *caller_file, const char *caller_func, int caller_line); 38 | void ASSERT_EQ_MEM(void *actual, void *expected, size_t size, 39 | char *caller_file, const char *caller_func, int caller_line); 40 | void ASSERT_EQ_PTR(void *actual, void *expected, 41 | char *caller_file, const char *caller_func, int caller_line); 42 | # define ASSERT_TRUE(x) ASSERT_TRUE(x, __FILE__,__func__,__LINE__) 43 | # define ASSERT_EQ_I(x, y) ASSERT_EQ_I(x, y, __FILE__,__func__,__LINE__) 44 | # define ASSERT_EQ_UI(x, y) ASSERT_EQ_UI(x, y, __FILE__,__func__,__LINE__) 45 | # define ASSERT_EQ_L(x, y) ASSERT_EQ_L(x, y, __FILE__,__func__,__LINE__) 46 | # define ASSERT_EQ_UL(x, y) ASSERT_EQ_UL(x, y, __FILE__,__func__,__LINE__) 47 | # define ASSERT_EQ_LL(x, y) ASSERT_EQ_LL(x, y, __FILE__,__func__,__LINE__) 48 | # define ASSERT_EQ_ULL(x, y) ASSERT_EQ_ULL(x, y, __FILE__,__func__,__LINE__) 49 | # define ASSERT_EQ_SIZE(x, y) ASSERT_EQ_SIZE(x, y, __FILE__,__func__,__LINE__) 50 | # define ASSERT_EQ_STR(x, y) ASSERT_EQ_STR(x, y, __FILE__,__func__,__LINE__) 51 | # define ASSERT_EQ_MALLOC_SIZE(x, y) ASSERT_EQ_MALLOC_SIZE(x, y, __FILE__,__func__,__LINE__) 52 | # define ASSERT_EQ_MEM(x, y, z) ASSERT_EQ_MEM(x, y, z, __FILE__,__func__,__LINE__) 53 | # define ASSERT_EQ_PTR(x, y) ASSERT_EQ_PTR(x, y, __FILE__,__func__,__LINE__) 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /srcs/test_ft_lstadd_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_lstadd_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 12:05:23 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:04:13 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | t_list *lst = NULL; 18 | t_list *elem1 = calloc(sizeof(t_list), 1); 19 | t_list *elem2 = calloc(sizeof(t_list), 1); 20 | t_list *elem3 = calloc(sizeof(t_list), 1); 21 | t_list *elem4 = calloc(sizeof(t_list), 1); 22 | t_list *elem5 = calloc(sizeof(t_list), 1); 23 | char *s1 = "hello"; 24 | char *s2 = "world"; 25 | char *s3 = "42!"; 26 | int val4 = 42; 27 | int val5 = -42; 28 | elem1->content = s1; 29 | elem2->content = s2; 30 | elem3->content = s3; 31 | elem4->content = &val4; 32 | elem5->content = &val5; 33 | 34 | 35 | /* Add back #1 */ 36 | ft_lstadd_back(&lst, elem1); 37 | /* 1 */ ASSERT_EQ_PTR(lst, elem1); 38 | /* 2 */ ASSERT_EQ_PTR(lst->content, s1); 39 | /* 3 */ ASSERT_EQ_PTR(lst->next, NULL); 40 | 41 | /* Add back #2 */ 42 | ft_lstadd_back(&lst, elem2); 43 | /* 4 */ ASSERT_EQ_PTR(lst, elem1); 44 | /* 5 */ ASSERT_EQ_PTR(lst->content, s1); 45 | /* 6 */ ASSERT_EQ_PTR(lst->next, elem2); 46 | /* 7 */ ASSERT_EQ_PTR(lst->next->content, s2); 47 | /* 8 */ ASSERT_EQ_PTR(lst->next->next, NULL); 48 | 49 | /* Add back #3 */ 50 | ft_lstadd_back(&lst, elem3); 51 | /* 9 */ ASSERT_EQ_PTR(lst, elem1); 52 | /* 10 */ ASSERT_EQ_PTR(lst->content, s1); 53 | /* 11 */ ASSERT_EQ_PTR(lst->next, elem2); 54 | /* 12 */ ASSERT_EQ_PTR(lst->next->content, s2); 55 | /* 13 */ ASSERT_EQ_PTR(lst->next->next, elem3); 56 | /* 14 */ ASSERT_EQ_PTR(lst->next->next->content, s3); 57 | /* 15 */ ASSERT_EQ_PTR(lst->next->next->next, NULL); 58 | 59 | /* Add back #4 */ 60 | ft_lstadd_back(&lst, elem4); 61 | /* 16 */ ASSERT_EQ_PTR(lst, elem1); 62 | /* 17 */ ASSERT_EQ_PTR(lst->content, s1); 63 | /* 18 */ ASSERT_EQ_PTR(lst->next, elem2); 64 | /* 19 */ ASSERT_EQ_PTR(lst->next->content, s2); 65 | /* 20 */ ASSERT_EQ_PTR(lst->next->next, elem3); 66 | /* 21 */ ASSERT_EQ_PTR(lst->next->next->content, s3); 67 | /* 22 */ ASSERT_EQ_PTR(lst->next->next->next, elem4); 68 | /* 23 */ ASSERT_EQ_PTR(lst->next->next->next->content, &val4); 69 | /* 24 */ ASSERT_EQ_PTR(lst->next->next->next->next, NULL); 70 | 71 | /* Add back #5 */ 72 | ft_lstadd_back(&lst, elem5); 73 | /* 25 */ ASSERT_EQ_PTR(lst, elem1); 74 | /* 26 */ ASSERT_EQ_PTR(lst->content, s1); 75 | /* 27 */ ASSERT_EQ_PTR(lst->next, elem2); 76 | /* 28 */ ASSERT_EQ_PTR(lst->next->content, s2); 77 | /* 29 */ ASSERT_EQ_PTR(lst->next->next, elem3); 78 | /* 30 */ ASSERT_EQ_PTR(lst->next->next->content, s3); 79 | /* 31 */ ASSERT_EQ_PTR(lst->next->next->next, elem4); 80 | /* 32 */ ASSERT_EQ_PTR(lst->next->next->next->content, &val4); 81 | /* 33 */ ASSERT_EQ_PTR(lst->next->next->next->next, elem5); 82 | /* 34 */ ASSERT_EQ_PTR(lst->next->next->next->next->content, &val5); 83 | /* 35 */ ASSERT_EQ_PTR(lst->next->next->next->next->next, NULL); 84 | return (0); 85 | } 86 | -------------------------------------------------------------------------------- /srcs/test_ft_lstadd_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_lstadd_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/19 11:47:15 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 10:04:58 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | t_list *lst = NULL; 18 | t_list *elem1 = calloc(sizeof(t_list), 1); 19 | t_list *elem2 = calloc(sizeof(t_list), 1); 20 | t_list *elem3 = calloc(sizeof(t_list), 1); 21 | t_list *elem4 = calloc(sizeof(t_list), 1); 22 | t_list *elem5 = calloc(sizeof(t_list), 1); 23 | char *s1 = "hello"; 24 | char *s2 = "world"; 25 | char *s3 = "42!"; 26 | int val4 = 42; 27 | int val5 = -42; 28 | elem1->content = s1; 29 | elem2->content = s2; 30 | elem3->content = s3; 31 | elem4->content = &val4; 32 | elem5->content = &val5; 33 | 34 | 35 | /* Add front #1 */ 36 | ft_lstadd_front(&lst, elem1); 37 | /* 1 */ ASSERT_EQ_PTR(lst, elem1); 38 | /* 2 */ ASSERT_EQ_PTR(lst->content, s1); 39 | /* 3 */ ASSERT_EQ_PTR(lst->next, NULL); 40 | 41 | /* Add front #2 */ 42 | ft_lstadd_front(&lst, elem2); 43 | /* 4 */ ASSERT_EQ_PTR(lst, elem2); 44 | /* 5 */ ASSERT_EQ_PTR(lst->content, s2); 45 | /* 6 */ ASSERT_EQ_PTR(lst->next, elem1); 46 | /* 7 */ ASSERT_EQ_PTR(lst->next->content, s1); 47 | /* 8 */ ASSERT_EQ_PTR(lst->next->next, NULL); 48 | 49 | /* Add front #3 */ 50 | ft_lstadd_front(&lst, elem3); 51 | /* 9 */ ASSERT_EQ_PTR(lst, elem3); 52 | /* 10 */ ASSERT_EQ_PTR(lst->content, s3); 53 | /* 11 */ ASSERT_EQ_PTR(lst->next, elem2); 54 | /* 12 */ ASSERT_EQ_PTR(lst->next->content, s2); 55 | /* 13 */ ASSERT_EQ_PTR(lst->next->next, elem1); 56 | /* 14 */ ASSERT_EQ_PTR(lst->next->next->content, s1); 57 | /* 15 */ ASSERT_EQ_PTR(lst->next->next->next, NULL); 58 | 59 | /* Add front #4 */ 60 | ft_lstadd_front(&lst, elem4); 61 | /* 16 */ ASSERT_EQ_PTR(lst, elem4); 62 | /* 17 */ ASSERT_EQ_PTR(lst->content, &val4); 63 | /* 18 */ ASSERT_EQ_PTR(lst->next, elem3); 64 | /* 19 */ ASSERT_EQ_PTR(lst->next->content, s3); 65 | /* 20 */ ASSERT_EQ_PTR(lst->next->next, elem2); 66 | /* 21 */ ASSERT_EQ_PTR(lst->next->next->content, s2); 67 | /* 22 */ ASSERT_EQ_PTR(lst->next->next->next, elem1); 68 | /* 23 */ ASSERT_EQ_PTR(lst->next->next->next->content, s1); 69 | /* 24 */ ASSERT_EQ_PTR(lst->next->next->next->next, NULL); 70 | 71 | /* Add front #5 */ 72 | ft_lstadd_front(&lst, elem5); 73 | /* 25 */ ASSERT_EQ_PTR(lst, elem5); 74 | /* 26 */ ASSERT_EQ_PTR(lst->content, &val5); 75 | /* 27 */ ASSERT_EQ_PTR(lst->next, elem4); 76 | /* 28 */ ASSERT_EQ_PTR(lst->next->content, &val4); 77 | /* 29 */ ASSERT_EQ_PTR(lst->next->next, elem3); 78 | /* 30 */ ASSERT_EQ_PTR(lst->next->next->content, s3); 79 | /* 31 */ ASSERT_EQ_PTR(lst->next->next->next, elem2); 80 | /* 32 */ ASSERT_EQ_PTR(lst->next->next->next->content, s2); 81 | /* 33 */ ASSERT_EQ_PTR(lst->next->next->next->next, elem1); 82 | /* 34 */ ASSERT_EQ_PTR(lst->next->next->next->next->content, s1); 83 | /* 35 */ ASSERT_EQ_PTR(lst->next->next->next->next->next, NULL); 84 | return (0); 85 | } 86 | -------------------------------------------------------------------------------- /srcs/test_ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* test_ft_aoti.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/15 11:05:54 by susami #+# #+# */ 9 | /* Updated: 2022/05/02 09:48:50 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tester.h" 14 | 15 | int main(void) 16 | { 17 | /* 1 */ ASSERT_EQ_I(ft_atoi(""), atoi("")); 18 | /* 2 */ ASSERT_EQ_I(ft_atoi("-"), atoi("-")); 19 | /* 3 */ ASSERT_EQ_I(ft_atoi("+"), atoi("+")); 20 | /* 4 */ ASSERT_EQ_I(ft_atoi("0"), atoi("0")); 21 | /* 5 */ ASSERT_EQ_I(ft_atoi("-0"), atoi("-0")); 22 | /* 6 */ ASSERT_EQ_I(ft_atoi("+0"), atoi("+0")); 23 | /* 7 */ ASSERT_EQ_I(ft_atoi("1"), atoi("1")); 24 | /* 8 */ ASSERT_EQ_I(ft_atoi("-1"), atoi("-1")); 25 | /* 9 */ ASSERT_EQ_I(ft_atoi("+1"), atoi("+1")); 26 | /* 10 */ ASSERT_EQ_I(ft_atoi("7"), atoi("7")); 27 | /* 11 */ ASSERT_EQ_I(ft_atoi("-7"), atoi("-7")); 28 | /* 12 */ ASSERT_EQ_I(ft_atoi("+7"), atoi("+7")); 29 | /* 13 */ ASSERT_EQ_I(ft_atoi("42"), atoi("42")); 30 | /* 14 */ ASSERT_EQ_I(ft_atoi("-42"), atoi("-42")); 31 | /* 15 */ ASSERT_EQ_I(ft_atoi("a"), atoi("a")); 32 | /* 16 */ ASSERT_EQ_I(ft_atoi("!"), atoi("!")); 33 | /* 17. INT_MAX */ ASSERT_EQ_I(ft_atoi("2147483647"), atoi("2147483647")); 34 | /* 18. INT_MIN */ ASSERT_EQ_I(ft_atoi("-2147483648"), atoi("-2147483648")); 35 | /* 19. UINT_MAX */ ASSERT_EQ_I(ft_atoi("4294967295"), atoi("4294967295")); 36 | /* 20. LONG_MAX */ ASSERT_EQ_I(ft_atoi("9223372036854775807"), atoi("9223372036854775807")); 37 | /* 21. LONG_MIN */ ASSERT_EQ_I(ft_atoi("-9223372036854775808"), atoi("-9223372036854775808")); 38 | /* 22. ULONG_MAX */ ASSERT_EQ_I(ft_atoi("18446744073709551615"), atoi("18446744073709551615")); 39 | /* 23. SIZE_MAX */ ASSERT_EQ_I(ft_atoi("18446744073709551615"), atoi("18446744073709551615")); 40 | 41 | /* 24. INT_MAX + 1 */ ASSERT_EQ_I(atoi("2147483648"), ft_atoi("2147483648")); 42 | /* 25. INT_MIN - 1 */ ASSERT_EQ_I(atoi("-2147483649"), ft_atoi("-2147483649")); 43 | /* 26. UINT_MAX + 1 */ ASSERT_EQ_I(atoi("4294967296"), ft_atoi("4294967296")); 44 | /* 27. LONG_MAX + 1 */ ASSERT_EQ_I(atoi("9223372036854775808"), ft_atoi("9223372036854775808")); 45 | /* 28. LONG_MIN - 1 */ ASSERT_EQ_I(atoi("-9223372036854775809"), ft_atoi("-9223372036854775809")); 46 | /* 29. ULONG_MAX + 1 */ ASSERT_EQ_I(atoi("18446744073709551616"), ft_atoi("18446744073709551616")); 47 | /* 30. SIZE_MAX + 1 */ ASSERT_EQ_I(atoi("18446744073709551616"), ft_atoi("18446744073709551616")); 48 | 49 | /* 31. INT_MAX - 1 */ ASSERT_EQ_I(atoi("2147483646"), ft_atoi("2147483646")); 50 | /* 32. INT_MIN + 1 */ ASSERT_EQ_I(atoi("-2147483647"), ft_atoi("-2147483647")); 51 | /* 33. UINT_MAX - 1 */ ASSERT_EQ_I(atoi("4294967294"), ft_atoi("4294967294")); 52 | /* 34. LONG_MAX - 1 */ ASSERT_EQ_I(atoi("9223372036854775806"), ft_atoi("9223372036854775806")); 53 | /* 35. LONG_MIN + 1 */ ASSERT_EQ_I(atoi("-9223372036854775807"), ft_atoi("-9223372036854775807")); 54 | /* 36. ULONG_MAX - 1 */ ASSERT_EQ_I(atoi("18446744073709551614"), ft_atoi("18446744073709551614")); 55 | /* 37. SIZE_MAX - 1 */ ASSERT_EQ_I(atoi("18446744073709551614"), ft_atoi("18446744073709551614")); 56 | 57 | /* 38. Many zeros 1*/ ASSERT_EQ_I(atoi("000000000000000000008"), ft_atoi("000000000000000000008")); 58 | /* 39. Many zeros 2*/ ASSERT_EQ_I(atoi("-000000000000000000008"), ft_atoi("-000000000000000000008")); 59 | /* 40. Many zeros 3*/ ASSERT_EQ_I(atoi("+000000000000000000008"), ft_atoi("+000000000000000000008")); 60 | return (0); 61 | } 62 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: susami +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/04/15 09:49:28 by susami #+# #+# # 9 | # Updated: 2022/06/03 13:17:15 by susami ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | LIBFT_DIR = ../ 14 | LIBFT = $(LIBFT_DIR)libft.a 15 | LIBFT_00 = $(LIBFT_DIR)libft00.a 16 | LIBFT_01 = $(LIBFT_DIR)libft01.a 17 | LIBFT_02 = $(LIBFT_DIR)libft02.a 18 | LIBASSERT_DIR = ./libs/libassert/ 19 | LIBASSERT = $(LIBASSERT_DIR)libassert.a 20 | LIBS = ./libs/*/*.a 21 | CC = gcc 22 | CFLAGS = -Wall -Wextra -Werror 23 | INCS = ./includes\ 24 | $(LIBFT_DIR)\ 25 | 26 | SRCS = srcs/*.c 27 | OBJS = $(SRCS:%.c=$(OUT_O_DIR)/%.o) 28 | OBJ_DIR = objs 29 | 30 | FUNCS_LIBFT00 = isalpha\ 31 | isdigit\ 32 | isalnum\ 33 | isascii\ 34 | isprint\ 35 | strlen\ 36 | memset\ 37 | bzero\ 38 | memcpy\ 39 | memmove\ 40 | strlcpy\ 41 | strlcat\ 42 | 43 | FUNCS_LIBFT01 = toupper\ 44 | tolower\ 45 | strchr\ 46 | strrchr\ 47 | strncmp\ 48 | memchr\ 49 | memcmp\ 50 | strnstr\ 51 | atoi\ 52 | 53 | FUNCS_LIBFT02_1 = calloc\ 54 | strdup\ 55 | 56 | FUNCS_LIBFT02_2 = substr\ 57 | strjoin\ 58 | strtrim\ 59 | split\ 60 | itoa\ 61 | 62 | FUNCS_LIBFT02 = $(FUNCS_LIBFT02_1)\ 63 | $(FUNCS_LIBFT02_2)\ 64 | 65 | FUNCS_PART1 = $(FUNCS_LIBFT00)\ 66 | $(FUNCS_LIBFT01)\ 67 | $(FUNCS_LIBFT02_1)\ 68 | 69 | FUNCS_PART2 = $(FUNCS_LIBFT02_2)\ 70 | strmapi\ 71 | striteri\ 72 | putchar_fd\ 73 | putstr_fd\ 74 | putendl_fd\ 75 | putnbr_fd\ 76 | 77 | FUNCS_BONUS = lstnew\ 78 | lstadd_front\ 79 | lstsize\ 80 | lstlast\ 81 | lstadd_back\ 82 | lstdelone\ 83 | lstclear\ 84 | lstiter\ 85 | lstmap\ 86 | 87 | FUNCS_EXTRA = strcmp\ 88 | 89 | RE_LIBFT00_TARG = $(addsuffix .re, $(FUNCS_LIBFT00)) 90 | RE_LIBFT01_TARG = $(addsuffix .re, $(FUNCS_LIBFT01)) 91 | RE_LIBFT02_TARG = $(addsuffix .re, $(FUNCS_LIBFT02)) 92 | 93 | SRCS_LIBFT00 = $(shell ls $(addprefix $(LIBFT_DIR)ft_, $(addsuffix .c, $(FUNCS_LIBFT00))) 2> /dev/null) 94 | SRCS_LIBFT01 = $(shell ls $(addprefix $(LIBFT_DIR)ft_, $(addsuffix .c, $(FUNCS_LIBFT01))) 2> /dev/null) 95 | SRCS_LIBFT02 = $(shell ls $(addprefix $(LIBFT_DIR)ft_, $(addsuffix .c, $(FUNCS_LIBFT02))) 2> /dev/null) 96 | 97 | OBJS_LIBFT00 = $(SRCS_LIBFT00:.c=.o) 98 | OBJS_LIBFT01 = $(SRCS_LIBFT01:.c=.o) 99 | OBJS_LIBFT02 = $(SRCS_LIBFT02:.c=.o) 100 | 101 | FUNCS = $(FUNCS_PART1) $(FUNCS_PART2) 102 | ERROR_LOG = error.log 103 | 104 | all: start_tests $(FUNCS) 105 | @find . -name "*.log" -size 0 -exec rm {} \; 106 | @[ ! -f $(ERROR_LOG) ] &&\ 107 | printf "\e[32m\n\n------------------------------------------------------------\ 108 | \n[MANDATORY PARTS] All tests passed successfully! Congratulations :D\n\e[m" ||\ 109 | printf "\e[31m\n\n------------------------------------------------------------\ 110 | \nSome tests failed. Please see error.log for more detailed information.\n\e[m" 111 | 112 | bonus: start_bonus_tests $(FUNCS_BONUS) 113 | @find . -name "*.log" -size 0 -exec rm {} \; 114 | @[ ! -f $(ERROR_LOG) ] &&\ 115 | printf "\e[32m\n\n------------------------------------------------------------\ 116 | \n[BONUS PARTS] All tests passed successfully! Congratulations :D\n\e[m" ||\ 117 | printf "\e[31m\n\n------------------------------------------------------------\ 118 | \nSome tests failed. Please see error.log for more detailed information.\n\e[m" 119 | 120 | extra: start_bonus_tests $(FUNCS_EXTRA) 121 | @find . -name "*.log" -size 0 -exec rm {} \; 122 | @[ ! -f $(ERROR_LOG) ] &&\ 123 | printf "\e[32m\n\n------------------------------------------------------------\ 124 | \n[EXTRA] All tests passed successfully! Congratulations :D\n\e[m" ||\ 125 | printf "\e[31m\n\n------------------------------------------------------------\ 126 | \nSome tests failed. Please see error.log for more detailed information.\n\e[m" 127 | 128 | libft-00: start_reloaded_tests $(RE_LIBFT00_TARG) 129 | @find . -name "*.log" -size 0 -exec rm {} \; 130 | @[ ! -f $(ERROR_LOG) ] &&\ 131 | printf "\e[32m\n\n------------------------------------------------------------\ 132 | \n[Libft-00] All tests passed successfully! Congratulations :D\n\e[m" ||\ 133 | printf "\e[31m\n\n------------------------------------------------------------\ 134 | \nSome tests failed. Please see error.log for more detailed information.\n\e[m" 135 | 136 | libft-01: start_reloaded_tests $(RE_LIBFT01_TARG) 137 | @find . -name "*.log" -size 0 -exec rm {} \; 138 | @[ ! -f $(ERROR_LOG) ] &&\ 139 | printf "\e[32m\n\n------------------------------------------------------------\ 140 | \n[Libft-01] All tests passed successfully! Congratulations :D\n\e[m" ||\ 141 | printf "\e[31m\n\n------------------------------------------------------------\ 142 | \nSome tests failed. Please see error.log for more detailed information.\n\e[m" 143 | 144 | libft-02: start_reloaded_tests $(RE_LIBFT02_TARG) 145 | @find . -name "*.log" -size 0 -exec rm {} \; 146 | @[ ! -f $(ERROR_LOG) ] &&\ 147 | printf "\e[32m\n\n------------------------------------------------------------\ 148 | \n[Libft-02] All tests passed successfully! Congratulations :D\n\e[m" ||\ 149 | printf "\e[31m\n\n------------------------------------------------------------\ 150 | \nSome tests failed. Please see error.log for more detailed information.\n\e[m" 151 | 152 | start_tests: 153 | @$(RM) $(ERROR_LOG) 154 | make -C $(LIBFT_DIR) 155 | make -C ./libs/libassert 156 | @#make -C $(LIBFT_DIR) bonus 157 | 158 | start_bonus_tests: 159 | @$(RM) $(ERROR_LOG) 160 | make -C $(LIBFT_DIR) bonus 161 | make -C ./libs/libassert 162 | 163 | start_reloaded_tests: 164 | @$(RM) $(ERROR_LOG) 165 | make -C ./libs/libassert 166 | 167 | $(LIBFT): 168 | make -C $(LIBFT_DIR) 169 | 170 | $(LIBFT_00): $(OBJS_LIBFT00) 171 | ar rc $@ $^ 172 | 173 | $(LIBFT_01): $(OBJS_LIBFT00) $(OBJS_LIBFT01) 174 | ar rc $@ $^ 175 | 176 | $(LIBFT_02): $(OBJS_LIBFT00) $(OBJS_LIBFT01) $(OBJS_LIBFT02) 177 | ar rc $@ $^ 178 | 179 | $(LIBASSERT): 180 | make -C ./libs/libassert 181 | 182 | $(OBJ_DIR)/%.o: %.c 183 | @mkdir -p $(OBJ_DIR) 184 | $(CC) -c $< $(LIBFT) -I $(INCS) -o $@ $(CFLAGS) 185 | 186 | clean: 187 | @$(RM) $(OUT_O_DIR)/*.o $(ERROR_LOG) 188 | 189 | fclean: clean 190 | @$(MAKE) -C ./libs/libassert re 191 | 192 | re: fclean all 193 | 194 | norm: 195 | @echo "------------------------------Checking restrict keyword usage------------------------------" 196 | cat $(LIBFT_DIR)*.c | egrep '\.c|restrict' | grep -B 1 'restrict' && printf "\e[31mYour implementation may contains unallowed restrict keyword.\n\e[m" || printf "\e[32mOK :D\n\e[m" 197 | @echo "------------------------------Checking included headers------------------------------" 198 | cat $(LIBFT_DIR)*.c | egrep '<*.h>|\.c' | grep -B 1 '<*.h>' || printf "\e[32mheader inclusion OK :D\n\e[m" 199 | @echo "------------------------------Checking static methods...------------------------------" 200 | nm $(LIBFT) -A | grep "T _" | sed -e 's/: .* T _.*//' | sed -e 's/..\/libft.a://' | uniq -c | grep -v ' 1 ' && printf "\e[31mNon static functions found in your imlementation!\n\e[m" || printf "\e[32mOK :D\n\e[m" 201 | @echo "------------------------------Checking unallowed methods------------------------------" 202 | nm $(LIBFT) -A | egrep "U _[a-z]" | egrep -v "U _ft_[a-z]" | sed -e 's/..\/libft.a://' 203 | @printf "\e[33mMake sure your implementation does not use unallowed standard functions.\n\e[m" 204 | @echo "------------------------------Checking norminette------------------------------" 205 | norminette $(LIBFT_DIR)*.c $(LIBFT_DIR)*.h | grep -v "OK!" || printf "\e[32mnorminette OK :D\n\e[m" 206 | 207 | norm00: $(LIBFT_00) 208 | make norm LIBFT=$< 209 | norm01: $(LIBFT_01) 210 | make norm LIBFT=$< 211 | norm02: $(LIBFT_02) 212 | make norm LIBFT=$< 213 | 214 | $(FUNCS) $(FUNCS_BONUS) $(FUNCS_EXTRA): $(LIBFT) $(LIBASSERT) 215 | @printf "ft_$@: " 216 | @-$(CC) srcs/test_ft_$@.c $(LIBFT) $(LIBS) $(addprefix -I , $(INCS)) -o a.out $(CFLAGS) 2>>$(ERROR_LOG) && ./a.out 2>>$(ERROR_LOG) && $(RM) a.out || printf "\e[31m[MISSING]\e[m" 217 | @printf "\n" 218 | 219 | $(RE_LIBFT00_TARG): $(LIBFT_00) $(LIBASSERT) 220 | @printf "ft_$(basename $@): " 221 | @-$(CC) srcs/test_ft_$(basename $@).c $(LIBFT_00) $(LIBS) $(addprefix -I , $(INCS)) -o a.out $(CFLAGS) 2>>$(ERROR_LOG) && ./a.out 2>>$(ERROR_LOG) && $(RM) a.out || printf "\e[31m[MISSING]\e[m" 222 | @printf "\n" 223 | 224 | $(RE_LIBFT01_TARG): $(LIBFT_01) $(LIBASSERT) 225 | @printf "ft_$(basename $@): " 226 | @-$(CC) srcs/test_ft_$(basename $@).c $(LIBFT_01) $(LIBS) $(addprefix -I , $(INCS)) -o a.out $(CFLAGS) 2>>$(ERROR_LOG) && ./a.out 2>>$(ERROR_LOG) && $(RM) a.out || printf "\e[31m[MISSING]\e[m" 227 | @printf "\n" 228 | 229 | $(RE_LIBFT02_TARG): $(LIBFT_02) $(LIBASSERT) 230 | @printf "ft_$(basename $@): " 231 | @-$(CC) srcs/test_ft_$(basename $@).c $(LIBFT_02) $(LIBS) $(addprefix -I , $(INCS)) -o a.out $(CFLAGS) 2>>$(ERROR_LOG) && ./a.out 2>>$(ERROR_LOG) && $(RM) a.out || printf "\e[31m[MISSING]\e[m" 232 | @printf "\n" 233 | 234 | .PHONY: all clean fclean re bonus norm test clone 235 | -------------------------------------------------------------------------------- /libs/libassert/libassert.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libassert.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: susami +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/04/13 17:34:09 by susami #+# #+# */ 9 | /* Updated: 2022/04/22 11:06:29 by susami ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #define ANSI_COLOR_RED "\x1b[1;31m" 19 | #define ANSI_COLOR_GREEN "\x1b[1;32m" 20 | #define ANSI_COLOR_YELLOW "\x1b[1;33m" 21 | #define ANSI_COLOR_BLUE "\x1b[1;34m" 22 | #define ANSI_COLOR_MAGENTA "\x1b[1;35m" 23 | #define ANSI_COLOR_CYAN "\x1b[1;36m" 24 | #define ANSI_COLOR_RESET "\x1b[0m" 25 | 26 | /* Function for printing out test index, OK/KO, errors */ 27 | static size_t counter = 0; 28 | static void start_test(void) 29 | { 30 | printf("%zu.", ++counter); 31 | fflush(stdout); 32 | } 33 | 34 | static void print_ok(void) 35 | { 36 | printf(ANSI_COLOR_GREEN "OK " ANSI_COLOR_RESET); 37 | fflush(stdout); 38 | } 39 | 40 | static void print_ko(void) 41 | { 42 | printf(ANSI_COLOR_RED "KO " ANSI_COLOR_RESET); 43 | fflush(stdout); 44 | } 45 | 46 | static void print_error(char *fmt, ...) 47 | { 48 | va_list args; 49 | va_start(args, fmt); 50 | //fprintf(stderr, ANSI_COLOR_RED); 51 | vfprintf(stderr, fmt, args); 52 | //fprintf(stderr, ANSI_COLOR_RESET); 53 | va_end(args); 54 | } 55 | 56 | /* Function for printing out memory as hex to stderr*/ 57 | static const char *g_base16 = "0123456789abcdef"; 58 | 59 | static void hexdump(void *p, size_t size) 60 | { 61 | unsigned char *ptr; 62 | size_t i; 63 | char c; 64 | 65 | ptr = (unsigned char *)p; 66 | i = 0; 67 | while (i < size) 68 | { 69 | c = *(ptr + i); 70 | print_error("%c%c", g_base16[(c >> 4) & 0x0f], g_base16[c & 0x0f]); 71 | i++; 72 | } 73 | } 74 | 75 | /* Assert functions for testing */ 76 | void ASSERT_TRUE(bool actual, 77 | char *caller_file, const char *caller_func, int caller_line) 78 | { 79 | start_test(); 80 | if (actual == false) 81 | { 82 | print_ko(); 83 | print_error("[test %zu] %s failed: ", __func__); 84 | print_error("func %s at file %s, line %d\n", 85 | caller_func, caller_file, caller_line); 86 | return ; 87 | } 88 | else 89 | print_ok(); 90 | } 91 | 92 | void ASSERT_EQ_I(int actual, int expected, 93 | char *caller_file, const char *caller_func, int caller_line) 94 | { 95 | start_test(); 96 | if (actual != expected) 97 | { 98 | print_ko(); 99 | print_error("[test %zu] %s failed: (\"%i\") is not equal to expected (\"%i\"). ", 100 | counter, __func__, actual, expected); 101 | print_error("func %s at file %s, line %d\n", 102 | caller_func, caller_file, caller_line); 103 | return ; 104 | } 105 | else 106 | print_ok(); 107 | } 108 | 109 | void ASSERT_EQ_UI(unsigned int actual, unsigned int expected, 110 | char *caller_file, const char *caller_func, int caller_line) 111 | { 112 | start_test(); 113 | if (actual != expected) 114 | { 115 | print_ko(); 116 | print_error("[test %zu] %s failed: (\"%u\") is not equal to expected (\"%u\"). ", 117 | __func__, actual, expected); 118 | print_error("func %s at file %s, line %d\n", 119 | caller_func, caller_file, caller_line); 120 | } 121 | else 122 | print_ok(); 123 | } 124 | 125 | void ASSERT_EQ_L(long actual, long expected, 126 | char *caller_file, const char *caller_func, int caller_line) 127 | { 128 | start_test(); 129 | if (actual != expected) 130 | { 131 | print_ko(); 132 | print_error("[test %zu] %s failed: (\"%li\") is not equal to expected (\"%li\"). ", 133 | counter, __func__, actual, expected); 134 | print_error("func %s at file %s, line %d\n", 135 | caller_func, caller_file, caller_line); 136 | } 137 | else 138 | print_ok(); 139 | } 140 | 141 | void ASSERT_EQ_UL(unsigned long actual, unsigned long expected, 142 | char *caller_file, const char *caller_func, int caller_line) 143 | { 144 | start_test(); 145 | if (actual != expected) 146 | { 147 | print_ko(); 148 | print_error("[test %zu] %s failed: (\"%lu\") is not equal to expected (\"%lu\"). ", 149 | counter, __func__, actual, expected); 150 | print_error("func %s at file %s, line %d\n", 151 | caller_func, caller_file, caller_line); 152 | } 153 | else 154 | print_ok(); 155 | } 156 | 157 | void ASSERT_EQ_LL(long long actual, long long expected, 158 | char *caller_file, const char *caller_func, int caller_line) 159 | { 160 | start_test(); 161 | if (actual != expected) 162 | { 163 | print_ko(); 164 | print_error("[test %zu] %s failed: (\"%lli\") is not equal to expected (\"%lli\"). ", 165 | counter, __func__, actual, expected); 166 | print_error("func %s at file %s, line %d\n", 167 | caller_func, caller_file, caller_line); 168 | } 169 | else 170 | print_ok(); 171 | } 172 | 173 | void ASSERT_EQ_ULL(unsigned long long actual, unsigned long long expected, 174 | char *caller_file, const char *caller_func, int caller_line) 175 | { 176 | start_test(); 177 | if (actual != expected) 178 | { 179 | print_ko(); 180 | print_error("[test %zu] %s failed: (\"%llu\") is not equal to expected (\"%llu\"). ", 181 | counter, __func__, actual, expected); 182 | print_error("func %s at file %s, line %d\n", 183 | caller_func, caller_file, caller_line); 184 | } 185 | else 186 | print_ok(); 187 | } 188 | 189 | void ASSERT_EQ_SIZE(size_t actual, size_t expected, 190 | char *caller_file, const char *caller_func, int caller_line) 191 | { 192 | start_test(); 193 | if (actual != expected) 194 | { 195 | print_ko(); 196 | print_error("[test %zu] %s failed: (\"%zu\") is not equal to expected (\"%zu\"). ", 197 | counter, __func__, actual, expected); 198 | print_error("func %s at file %s, line %d\n", 199 | caller_func, caller_file, caller_line); 200 | } 201 | else 202 | print_ok(); 203 | } 204 | 205 | void ASSERT_EQ_STR(char *actual, char *expected, 206 | char *caller_file, const char *caller_func, int caller_line) 207 | { 208 | start_test(); 209 | if (expected == NULL || actual == NULL) 210 | { 211 | if (expected != actual) 212 | { 213 | print_ko(); 214 | print_error("[test %zu] %s failed: \"%p\" is not equal to expected \"%p\"", counter, __func__, actual, expected); 215 | print_error("func %s at file %s, line %d\n", 216 | caller_func, caller_file, caller_line); 217 | } 218 | else 219 | print_ok(); 220 | return ; 221 | } 222 | 223 | if (strcmp(actual, expected) != 0) 224 | { 225 | print_ko(); 226 | print_error("[test %zu] %s failed: (\"%s\") is not equal to expected (\"%s\"). ", 227 | counter, __func__, actual, expected); 228 | print_error("func %s at file %s, line %d\n", 229 | caller_func, caller_file, caller_line); 230 | } 231 | else 232 | print_ok(); 233 | } 234 | 235 | void ASSERT_EQ_MALLOC_SIZE(void *actual, void *expected, 236 | char *caller_file, const char *caller_func, int caller_line) 237 | { 238 | start_test(); 239 | if (expected == NULL || actual == NULL) 240 | { 241 | if (expected != actual) 242 | { 243 | print_ko(); 244 | print_error("[test %zu] %s failed: \"%p\" is not equal to expected \"%p\"", counter, __func__, actual, expected); 245 | print_error("func %s at file %s, line %d\n", 246 | caller_func, caller_file, caller_line); 247 | } 248 | else 249 | print_ok(); 250 | return ; 251 | } 252 | 253 | if (malloc_size(actual) != malloc_size(expected)) 254 | { 255 | print_ko(); 256 | print_error("[test %zu] %s failed: malloc_size \"%i\" is not equal to expected \"%i\"\n", counter, __func__, malloc_size(actual), malloc_size(expected)); 257 | print_error("func %s at file %s, line %d\n", 258 | caller_func, caller_file, caller_line); 259 | } 260 | else 261 | print_ok(); 262 | } 263 | void ASSERT_EQ_MEM(void *actual, void *expected, size_t size, 264 | char *caller_file, const char *caller_func, int caller_line) 265 | { 266 | start_test(); 267 | if (expected == NULL || actual == NULL) 268 | { 269 | if (expected != actual) 270 | { 271 | print_ko(); 272 | print_error("[test %zu] %s failed: \"%p\" is not equal to expected \"%p\"", counter, __func__, actual, expected); 273 | print_error("func %s at file %s, line %d\n", 274 | caller_func, caller_file, caller_line); 275 | } 276 | else 277 | print_ok(); 278 | return ; 279 | } 280 | 281 | if (memcmp(actual, expected, size) != 0) 282 | { 283 | print_ko(); 284 | print_error("[test %zu] %s failed: hexdump (\"", counter, __func__); 285 | hexdump(actual, size); 286 | print_error("\") is not equal to expected (\""); 287 | hexdump(expected, size); 288 | print_error("\"). "); 289 | print_error("func %s at file %s, line %d\n", 290 | caller_func, caller_file, caller_line); 291 | } 292 | else 293 | print_ok(); 294 | } 295 | 296 | void ASSERT_EQ_PTR(void *actual, void *expected, 297 | char *caller_file, const char *caller_func, int caller_line) 298 | { 299 | start_test(); 300 | if (actual != expected) 301 | { 302 | print_ko(); 303 | print_error("[test %zu] %s failed: (\"%p\") is not equal to expected (\"%p\"). ", 304 | counter, __func__, actual, expected); 305 | print_error("func %s at file %s, line %d\n", 306 | caller_func, caller_file, caller_line); 307 | } 308 | else 309 | print_ok(); 310 | } 311 | --------------------------------------------------------------------------------