-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_striteri_test.c
48 lines (44 loc) · 1.69 KB
/
ft_striteri_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abenamar <abenamar@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/08 23:52:23 by abenamar #+# #+# */
/* Updated: 2022/12/28 22:02:53 by abenamar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft_test.h"
static void tolower_or_toupper(unsigned int i, char *c)
{
if (i % 2 == 0 && 'A' <= *c && *c <= 'Z')
*c += 32;
else if (i % 2 != 0 && 'a' <= *c && *c <= 'z')
*c -= 32;
}
void ft_striteri_test(void)
{
char *str;
printf(RESET "\nft_striteri\t");
str = strdup("");
ft_striteri(str, &tolower_or_toupper);
ft_assert(1, !strcmp(str, ""));
free(str);
str = strdup("a");
ft_striteri(str, &tolower_or_toupper);
ft_assert(2, !strcmp(str, "a"));
free(str);
str = strdup("A");
ft_striteri(str, &tolower_or_toupper);
ft_assert(3, !strcmp(str, "a"));
free(str);
str = strdup("test");
ft_striteri(str, &tolower_or_toupper);
ft_assert(4, !strcmp(str, "tEsT"));
free(str);
str = strdup("This is a test");
ft_striteri(str, &tolower_or_toupper);
ft_assert(5, !strcmp(str, "tHiS Is a tEsT"));
free(str);
}