Skip to content

Latest commit

 

History

History
834 lines (831 loc) · 23.2 KB

tests_description.org

File metadata and controls

834 lines (831 loc) · 23.2 KB

Libft tests description

Mandatory part

ft_isalnum

int ft_isalnum(int c);

ft_isalpha

int ft_isalpha(int c);

ft_isascii

int ft_isascii(int c);

ft_isdigit

int ft_isdigit(int c);

ft_isprint

int ft_isprint(int c);

ft_strlen

size_t ft_strlen(const char *s);

ft_memset

void    *ft_memset(void *s, int c, size_t n);

ft_bzero

void    ft_bzero(void *s, size_t n);

ft_memcpy

void    *ft_memcpy(void *dest, const void *src, size_t n);

Basic input

Basic use of the function.

Smaller n

Normal input but with n < strlen(input).

n = 0

Normal input but with n = 0.

destination & source the same

dst & src pointing on same address.

NULL destination

dst set to NULL. Behavior on ubuntu: crash.

NULL source

src set to NULL. Behavior on ubuntu: crash.

Both destination & source NULL

dst & src set to NULL. Behavior on ubuntu: crash.

ft_memmove

void    *ft_memmove(void *dest, const void *src, size_t n);

Basic input

Basic use of the function.

destination & source the same

dst & src pointing on same address.

Overlapping : destination lower than source

dst address set to a lower address than src but with an overlapping size.

Overlapping : source lower than destination

src address set to a lower address than dst but with an overlapping size.

Smaller n

Normal input but with n < strlen(input).

n = 0

Normal input but with n = 0.

NULL destination

dst set to NULL. Behavior on ubuntu: crash.

NULL source

src set to NULL. Behavior on ubuntu: crash.

Both destination & source NULL

dst & src set to NULL. Behavior on ubuntu: crash.

ft_strlcpy

size_t  ft_strlcpy(char *dst, const char *src, size_t size);

Basic input

Basic use of the function. Behavior: copies size-1 bytes from src to dst + \0. Return value: length of src.

Smaller size

Size smaller than src. Behavior: copies size-1 bytes from src to dst + \0. Return value: length of src.

Bigger size

Size bigger than src. Behavior: copies only strlen(src) bytes from src to dst. Return value: length of src.

Size zero

size = 0. Behavior: doesn’t copy anything. Return value: length of src.

NULL dst

dst set to NULL. Behavior: CRASH.

NULL src

src set to NULL. Behavior: CRASH.

NULL dst & src

dst & src set to NULL. Behavior: CRASH.

ft_strlcat

size_t  ft_strlcat(char *dst, const char *src, size_t size);

Basic input

Basic use of function. Behavior: Copies size - len(dst) - 1 bytes from src to end of dst + \0. Return value: Initial length of dst + length of src.

Smaller size

Size smaller than final buffer. Behavior: Copies size - len(dst) - 1 bytes from src to end of dst + \0 (Truncation). Return value: Initial length of dst + length of src if size >= len(dst) else size + length of src.

Smaller small size

Size smaller than len(dst). Behavior: Doesn’t copy anything. Return value: size + length of src.

Bigger size

Size bigger than strlen(dst) + strlen(src). Behavior: Does the copy but stops at \0 of src. Return value: Initial length of dst + length of src.

Size zero

Size = 0. Behavior: Doesn’t copy anything. Return value: Length of src (same calculation than if size < len(dst)).

NULL dst

dst set to NULL. Behavior: CRASH. Return value: /

NULL dst & size zero

dst set to NULL and size set to zero. Behavior: Doesn’t copy anything. (NO CRASH). Return value: length of src.

NULL src

src set to NULL. Behavior: CRASH. Return value: /

NULL dst & src

dst & src set to NULL. Behavior: CRASH. Return value: /

ft_toupper

int ft_toupper(int c);

basic inputs (all unsigned char)

ft_tolower

int ft_tolower(int c);

basic inputs (all unsigned char)

ft_strchr

Basic inputs (c in s)

multiple c in s

no c in s

c set to ‘\0’

s set to NULL

ft_strrchr

Basic inputs (c in s)

multiple c in s

no c in s

c set to ‘\0’

s set to NULL

ft_strncmp

int ft_strncmp(const char *s1, const char *s2, size_t n);

Basic inputs s1 == s2

s1 & s2 the same. Return value: 0

Basic inputs s1 != s2, n = len(s1) (s1 < s2)

s1 & s2 different, s1 less than s2 Return value: negative (s1[i] - s2[i])

Basic inputs s1 != s2, n = len(s1) (s1 > s2)

s1 & s2 different, s1 greater than s2 Return value: positive (s1[i] - s2[i])

len s1 < len s2

s1 & s2 the same until ‘\0’ in s1. n set to length of s2. Return value: negative (0 - s2[i])

len s1 > len s2

s1 & s2 the same until ‘\0’ in s2. n set to length of s1. Return value: positive (s1[i] - 0)

Smaller n

n smaller than the 2 lengths. Return value: difference between nth char of the 2 strings.

Bigger n

n bigger than the 2 lengths. Return value: difference between last char of the smaller string and equivalent char of the other.

n = 0

n set to zero. Return value: 0

not unsigned char inside strings

Insertion of values not initially unsigned char to test that the function casts to unsigned char. Return value: diff as usual.

NULL s1, n > 0

s1 set to NULL with n > 0. Return value: / (CRASH)

NULL s2, n > 0

s2 set to NULL with n > 0. Return value: / (CRASH)

NULL s1 & s2, n > 0

s1 & s2 set to NULL with n > 0. Return value: / (CRASH)

NULL s1 & s2, n = 0

s1 & s2 set to NULL with n > 0. Return value: 0 (NO CRASH)

ft_memchr

void    *ft_memchr(const void *s, int c, size_t n);

Basic with c in s

Normal use of the function with c placed in s. Return value: pointer to first instance of c in s.

multiple c in s

Normal use of the function, c has multiple instances in s. Return value: pointer to first instance of c in s.

c not in s

Normal use of the function, c not in s. Return value: NULL.

c not unsigned char

Test the function with a non unsigned char value in c (present in s). Return value: pointer to instance of c in s (only if c and s[i] are cast to unsigned char).

c set to ‘\0’

Search for ‘\0’ (‘\0’ is also put in s). Return value: pointer to ‘\0’ in s.

Smaller n

Normal inputs but n smaller than s. Return value: pointer to first instance of c but tests at most n bytes.

s set to NULL with n > 0

s set to NULL. Return value: / (CRASH).

s set to NULL with n = 0

s set to NULL and n to zero. Return value: NULL.

ft_memcmp

int ft_memcmp(const void *s1, const void *s2, size_t n);

Basic, s1 == s2

Basic use of the function, s1 and s2 beeing equal and n = len(s1). Return value: 0.

Basic, s1 != s2 1

Basic use of the function, s1 and s2 differs (s1 < s2) and n = len(s1). Return value: negative (s1[i] - s2[i]).

Basic, s1 != s2 2

Basic use of the function, s1 and s2 differs (s1 > s2) and n = len(s1). Return value: positive (s1[i] - s2[i]).

byte zero in both strings

Both strings contain multiple ‘\0’ inside and then a byte is different (s1 > s2). Return value: positive.

n = 0

n set to zero. Return value: 0.

s1 not unsigned char

s1 value set to an integer bigger than unsigned char. Return value: Same as usual if values are casted to unsigned char.

s2 not unsigned char

s2 value set to an integer bigger than unsigned char. Return value: Same as usual if values are casted to unsigned char.

NULL s1, n > 0

s1 set to NULL and n > 0. Return value: / (CRASH)

NULL s2, n > 0

s2 set to NULL and n > 0. Return value: / (CRASH)

NULL s1 & s2, n > 0

s1 & s2 set to NULL, n > 0. Return value: / (CRASH)

NULL s1 & s2, n = 0

s1 & s2 set to NULL, n = 0. Return value: 0.

ft_strnstr

char    *ft_strnstr(const char *big, const char *little, size_t len);

Basic inputs

string little contained in big and len = len(big). Return value: pointer to first char of first occurrence of little in big.

little not in big

string little not contained in big. Return value: NULL.

len = len(little)

len set len(little). len is contained in big but only after len. Return value: NULL.

Smaller len

little contained in big but after len. Return value: NULL.

Bigger len

little not contained in big and len > len(big). Return value: NULL.

len = 0

len set to zero. Return value: NULL.

big empty

big set to an empty string. Return value: NULL.

little empty

little set to an empty string. Return value: big.

big & little empty

little & big set to an empty string. Return value: pointer to big.

NULL big, len > 0

big set to NULL. Return value: / (CRASH)

NULL big, len = 0

big set to NULL. Return value: NULL.

NULL little, len > 0

little set to NULL. Return value: / (CRASH)

NULL little, len = 0

little set to NULL. Return value: / (CRASH)

NULL big & little, len > 0

big & little set to NULL with len > 0. Return value: / (CRASH)

NULL big & little, len = 0

big & little set to NULL with len = 0. Return value: / (CRASH)

ft_atoi

int ft_atoi(const char *nptr);

Basic input

Simple number passed. Return value: integer version of number in nptr.

negative integer

Negative number passed. Return value: integer version of number in nptr.

Normal number with positive sign

Normal number with positive sign before. Return value: integer version of number in nptr.

Multiple signs

Normal number with more than one signs before. Return value: 0.

Whitespaces before sign

Normal number with multiple whitespaces before sign. Return value: integer version of number in nptr.

Whitespaces after sign

Normal number with multiple whitespaces after sign. Return value: 0.

Whitespace in number

Normal number with whitespaces after some numbers. Return value: integer version of number before whitespaces.

Int min

Minimum integer passed. Return value: integer version of number in nptr.

Int max

Maximum integer passed. Return value: integer version of number in nptr.

Greater than int max

Number greater than int max passed. Return value: equivalent value of number converted to int (bits).

Greater than unsigned int max

Number greater than unsigned int max passed. Return value: -1

Empty nptr

nptr set to empty string. Return value: 0.

NULL nptr

nptr set to NULL. Return value: / (CRASH)

ft_calloc

void    *ft_calloc(size_t nmemb, size_t size);

normal allocation

Try to free memory allocated by ft_calloc with normal inputs. Behavior: Allocation & initialization of memory. Return value: pointer to memory.

check size

Normal values passed and size asked to malloc compared to right value. Behavior: Allocation & initialization of memory. Return value: pointer to memory.

malloc protection

Make malloc fail. Behavior: No allocation. Return value: NULL.

zero

nmemb & size set to 0. Behavior: No allocation. Return value: unique pointer value that can be passed to free().

Size too big

Too big size passed to ft_calloc. Behavior: No allocation. Return value: NULL for too big number (ULONG_MAX for ex.) and a pointer for int overflow.

ft_strdup

char    *ft_strdup(const char *s);

basic input

Normal c string passed. Behavior: s copied in new pointer allocated. Return value: pointer to s.

malloc fail

Make malloc fail. Behavior: s not copied because function stops after malloc fail. Return value: NULL.

s empty

s allocated but empty string. Behavior: empty string copied. Return value: pointer to s.

NULL s

s set to NULL. Behavior: CRASH Return value: / (CRASH)

ft_substr

char    *ft_substr(char const *s, unsigned int start, size_t len);

Basic inputs

Basic inputs passed to the function. Behavior: copies string s from index start with length len. Return value: the substring.

all string

start set to 0 & len set to strlen(s). Behavior: copies string s from index start with length len. Return value: the substring (same string as s).

Bigger len

Same inputs but with len > strlen(s) - start. Behavior: copies string s from index start with length = length of s from start to ‘\0’. Return value: the substring.

len zero

len set to 0. Behavior: Copies empty string (copy = len - 1, last character beeing ‘\0’). Return value: the substring (empty string).

start > strlen(s)

start set to a greater number than strlen(s). Behavior: Creates empty string. Return value: the substring (empty string).

start = strlen(s)

start set to strlen(s). Behavior: Creates empty string. Return value: the substring (empty string).

s empty

s set to an empty string (start = 0 & len = 1) Behavior: Copies empty string. Return value: the substring (empty string).

NULL s

s set to NULL. Behavior: No copy. Return value: NULL.

malloc fail

Make malloc fail. Behavior: No copy. Return value: NULL.

ft_strjoin

char    *ft_strjoin(char const *s1, char const *s2);

Basic inputs

s1 & s2 set to differents strings. Behavior: allocation of a new string in which s1 + s2 are copied. Return value: the new string.

malloc fail

make malloc fail. Behavior: No copy. Return value: NULL.

empty s1

s1 set to an empty string. Behavior: allocation of a new string in which s1 + s2 are copied (so only s2). Return value: the new string (=s2).

empty s2

s2 set to an empty string. Behavior: allocation of a new string in which s1 + s2 are copied (so only s1). Return value: the new string (=s1).

empty s1 & s2

s1 & s2 set to empty strings. Behavior: allocation of a new string in which s1 + s2 are copied (so ‘\0’). Return value: the new string (=’\0’).

NULL s1

s1 set to NULL. Behavior: Nothing. Return value: NULL.

NULL s2

s2 set to NULL. Behavior: Nothing. Return value: NULL.

NULL s1 & s2

s1 & s2 set to NULL. Behavior: Nothing. Return value: NULL.

ft_strtrim

char    *ft_strtrim(char const *s1, char const *set);

Basic inputs

Basic inputs passed to the function. Behavior: s1 is trimmed and returned. Return value: trimmed s1 (copy).

Characters in middle of s1

Characters of set only in the string (not at beginning or end). Behavior: s1 is not modified. Return value: s1 (copy).

No character of set in s1

No character of set present in s1. Behavior: s1 is not modified. Return value: s1 (copy).

Only characters of set in s1

s1 contains only characters from set. Behavior: empty string copied. Return value: empty string.

empty set

set set to an empty string. Behavior: s1 is not modified. Return value: s1 (copy).

emtpy s1

s1 set to an empty string. Behavior: s1 is not modified. Return value: s1 (copy).

malloc fail

Make malloc fail. Behavior: Nothing. Return value: NULL.

NULL s1

s1 set to NULL. Behavior: Nothing. Return value: NULL.

NULL set

set set to NULL. Behavior: Nothing. Return value: NULL.

NULL s1 & set

s1 & set set to NULL. Behavior: Nothing. Return value: NULL.

ft_split

char    **ft_split(char const *s, char c);

Basic inputs

s set to a string containing multiple times c. Behavior: s is split. Return value: array of new strings.

c before & after string

s set to a string containing multiple times c plus before and after the string. Behavior: s is split. Return value: array of new strings (no empty string).

no c in string

s set to a string not containing c. Behavior: s is split (only one string). Return value: array of new string.

zero c

c set to zero (‘\0’). Behavior: s is split (only one string). Return value: array of new string.

empty s

s set to an empty string. Behavior: s is split (only one string). Return value: array of new string.

malloc fail

Make malloc fail. Behavior: Nothing. Return value: NULL.

NULL s

s set to NULL. Behavior: Nothing. Return value: NULL.

ft_itoa

char    *ft_itoa(int n);

Basic inputs

n set to a positive number. Return value: string representing the integer.

Negative n

n set to a negative number. Return value: string representing the integer.

Maximum int

n set to maximum int. Return value: string representing the integer.

Minimum int

n set to minimum int. Return value: string representing the integer.

n zero

n set to zero. Return value: string representing the integer.

malloc fail

Make malloc fail. Return value: NULL.

ft_strmapi

char    *ft_strmapi(char const *s, char (*f)(unsigned int, char));

The test function passed to strmapi will be a rot47 function.

Basic inputs

s set to a normal string, f a rot47 function. Behavior: s modified by f. Return value: the new string.

empty s

s set to an empty string. Behavior: s modified by f (nothing). Return value: the new string (empty).

NULL s

s set to NULL. Behavior: Nothing. Return value: NULL.

NULL f

f set to NULL. Behavior: Nothing. Return value: NULL.

malloc fail

Make malloc fail Behavior: Nothing. Return value: NULL.

ft_striteri

void    ft_striteri(char *s, void (*f)(unsigned int, char*));

The test function passed to striteri will be a rot47 function.

Basic inputs

s set to a normal string, f a rot47 function. Behavior: s modified by f.

empty s

s set to an empty string. Behavior: s modified by f (nothing).

NULL s

s set to NULL. Behavior: Nothing.

NULL f

f set to NULL. Behavior: Nothing.

ft_putchar_fd

void    ft_putchar_fd(char c, int fd);

Basic

fd set to a pipe fd (stdout & stderr closed) and c to a regular char. Behavior: writes c to fd.

ft_putstr_fd

void    ft_putstr_fd(char *s, int fd);

Basic

fd set to a pipe fd (stdout & stderr closed) and s to a regular string. Behavior: writes string s to fd.

empty s

fd set to a pipe fd (stdout & stderr closed) and s to an empty string. Behavior: writes (empty) s to fd.

NULL s

fd set to a pipe fd (stdout & stderr closed) and s to NULL. Behavior: Nothing.

ft_putendl_fd

void    ft_putendl_fd(char *s, int fd);

Basic

fd set to a pipe fd (stdout & stderr closed) and s to a regular string. Behavior: writes string s (with ‘\n’) to fd.

multiple newlines

fd set to a pipe fd (stdout & stderr closed) and s to a string terminated by multiple newlines. Behavior: writes string s (with ‘\n’) to fd.

empty s

fd set to a pipe fd (stdout & stderr closed) and s to an empty string. Behavior: writes s (only ‘\n’) to fd.

NULL s

fd set to a pipe fd (stdout & stderr closed) and s to NULL. Behavior: Nothing.

ft_putnbr_fd

void    ft_putnbr_fd(int n, int fd);

Basic

fd set to a pipe fd (stdout & stderr closed) and n to positive number. Behavior: converts n to a string and then writes it to fd.

negative n

fd set to a pipe fd (stdout & stderr closed) and n to negative number. Behavior: converts n to a string and then writes it to fd.

int min

fd set to a pipe fd (stdout & stderr closed) and n to minimum integer. Behavior: converts n to a string and then writes it to fd.

int max

fd set to a pipe fd (stdout & stderr closed) and n to maximum integer. Behavior: converts n to a string and then writes it to fd.

n zero

fd set to a pipe fd (stdout & stderr closed) and n to zero. Behavior: converts n to a string and then writes it to fd.

Bonus part

ft_lstnew

t_list  *ft_lstnew(void *content);

Basic input

content set to a basic string. Behavior: A node containing the string as content is allocated. Return value: The new node.

NULL content

content set to NULL. Behavior: A node containing NULL as content is allocated. Return value: The new node.

malloc fail

Make malloc fail. Behavior: Tries to allocate memory. Return value: NULL.

ft_lstadd_front

void    ft_lstadd_front(t_list **lst, t_list *new);

Basic input

Creation of 2 nodes then call of the function. Behavior: The lst param becomes new, with next set to old lst.

NULL lst

lst set to NULL. Behavior: Nothing.

lst containing NULL

lst pointing to a NULL address. Behavior: pointer of lst set to new.

NULL new

new set to NULL. Behavior: Nothing.

NULL lst & new

lst & new set to NULL. Behavior: Nothing.

ft_lstsize

int ft_lstsize(t_list *lst);

Basic input

lst set to a list of multiple nodes. Return value: The size of lst.

NULL lst

lst set to NULL. Return value: Zero.

ft_lstlast

t_list  *ft_lstlast(t_list *lst);

Basic input

lst set to a list of multiple nodes. Return value: The last node of the list.

NULL lst

lst set to NULL. Return value: NULL.

ft_lastadd_back

void    ft_lstadd_back(t_list **lst, t_list *new);

Basic input

Creation of 2 nodes then call of the function. Behavior: The next element of lst is set to new.

NULL lst

lst set to NULL. Behavior: lst set to new.

NULL pointer lst

lst points to NULL. Behavior: lst set to new.

NULL new

new set to NULL. Behavior: Nothing.

NULL lst & new

lst & new set to NULL. Behavior: Nothing.

ft_lstdelone

void    ft_lstdelone(t_list *lst, void (*del)(void *));

Basic inputs

lst set to a node containing a 2D array of ints, del to appropriate function to free the content. Behavior: the content is freed using del and then the node is freed.

NULL lst

lst set to NULL. Behavior: Nothing.

NULL del

del set to NULL. Behavior: Nothing.

ft_lstclear

void    ft_lstclear(t_list **lst, void (*del)(void *));

Basic inputs

lst set to a list of multiple nodes of 2D arrays of int, del to appropriate function to free the content. Behavior: every node is freed after the content. The lst is then set to NULL.

NULL lst

lst set to NULL. Behavior: Nothing.

NULL pointer lst

lst set to pointer to NULL. Behavior: Nothing.

NULL del

del set to NULL. Behavior: Nothing.

ft_lstiter

void    ft_lstiter(t_list *lst, void (*f)(void *));

Basic inputs

lst set to a list of multiple nodes containing a string, f to a rot47 function. Behavior: Iterates on lst and applies f on the content of each node.

NULL lst

lst set to NULL. Behavior: Nothing.

NULL f

f set to NULL. Behavior: Nothing.

ft_lstmap

t_list   *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));

Basic inputs

lst set to a list of multiple nodes, each containing a string. f a rot47 function. del to the corresponding delete function. Behavior: Creation of a new list. Return value: The new list.

malloc fail

Same parameters but make malloc fail. Behavior: Nothing. Return value: NULL.

third malloc fail

Same parameters but make the third malloc fail. Behavior: Tries to create the new list but third malloc fails, so the del function is called on each node of the new list & everything is freed (the new list). Return value: NULL.

NULL lst

lst set to NULL. Behavior: Nothing. Return value: NULL.

NULL f

f set to NULL. Behavior: Nothing. Return value: NULL.

NULL del

del set to NULL. Behavior: Nothing. Return value: NULL.