finish tests for strlen and makefile works
This commit is contained in:
45
test.c
Normal file
45
test.c
Normal file
@ -0,0 +1,45 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define OK "\033[32mOK\n\033[0m"
|
||||
#define KO "\033[31mKO\n\033[0m"
|
||||
|
||||
#define FNC_TEST(title, condition)\
|
||||
printf(title":\n");\
|
||||
if(test_strlen())\
|
||||
printf("RESULT: "OK);\
|
||||
else\
|
||||
printf(" RESULT: "KO);
|
||||
|
||||
#define TEST(title, condition) \
|
||||
printf("%s: ", title);\
|
||||
if(condition)\
|
||||
{\
|
||||
printf(OK);\
|
||||
passed++;\
|
||||
}\
|
||||
else \
|
||||
printf(KO);
|
||||
|
||||
size_t ft_strlen(char *str);
|
||||
|
||||
int test_strlen(void)
|
||||
{
|
||||
int nb_tests;
|
||||
int passed;
|
||||
|
||||
nb_tests = 3;
|
||||
passed = 0;
|
||||
|
||||
TEST("normal string", ft_strlen("hello") == 5);
|
||||
TEST("empty string", ft_strlen("") == 0);
|
||||
TEST("null pointer", ft_strlen(NULL) == 0);
|
||||
|
||||
return(nb_tests == passed);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FNC_TEST("ft_strlen", test_strlen());
|
||||
printf("\n\n");
|
||||
}
|
Reference in New Issue
Block a user