-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
252 lines (218 loc) · 6.37 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ftaffore <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/02/13 12:43:41 by ftaffore #+# #+# */
/* Updated: 2015/02/13 12:43:43 by ftaffore ### ########.fr */
/* */
/* ************************************************************************** */
# include "libfts.h"
# include <stdio.h>
# include <ctype.h>
# include <strings.h>
void test_bzero(void) {
char test1[10] = "0123456789";
char test2[10] = "0123456789";
bzero(test1, 10);
ft_bzero(test2, 10);
if (memcmp(test1, test2, 10) == 0)
{
printf("%c[1;32mSUCCESS bzero\n", 27);
} else {
printf("%c[1;31mFAIL bzero\n", 27);
}
printf("%c[1;34m------------------\n", 27);
}
void test_strcat(void) {
char test1[11] = "01234\0";
char test11[6] = "abcde\0";
char test2[11] = "01234\0";
char test22[6] = "abcde\0";
ft_strcat(test1, test11);
strcat(test2, test22);
if (memcmp(test1, test2, 11) == 0)
{
printf("%c[1;32mSUCCESS strcat\n", 27);
} else {
printf("%c[1;31mFAIL strcat\n", 27);
}
printf("%c[1;34m------------------\n", 27);
}
void test_puts(void) {
ft_puts("SUCCESS puts\n");
printf("%c[1;34m------------------\n", 27);
}
void test_isdigit(void) {
if (isdigit('a') == ft_isdigit('a') && \
isdigit('0') == ft_isdigit('0') && \
isdigit('9') == ft_isdigit('9') && \
isdigit('3') == ft_isdigit('3') && \
isdigit(5) == ft_isdigit(5))
{
printf("%c[1;32mSUCCESS isdigit\n", 27);
} else {
printf("%c[1;31mFAIL isdigit\n", 27);
}
printf("%c[1;34m------------------\n", 27);
}
void test_isalpha(void) {
if (isalpha('a') == ft_isalpha('a') && \
isalpha('A') == ft_isalpha('A') && \
isalpha('Z') == ft_isalpha('Z') && \
isalpha('c') == ft_isalpha('c') && \
isalpha('0') == ft_isalpha('0') && \
isalpha(8) == ft_isalpha(8) && \
isalpha('z') == ft_isalpha('z') && \
isalpha('B') == ft_isalpha('B'))
{
printf("%c[1;32mSUCCESS isalpha\n", 27);
} else {
printf("%c[1;31mFAIL isalpha\n", 27);
}
printf("%c[1;34m------------------\n", 27);
}
void test_isalnum(void) {
if (isalnum('9') == ft_isalnum('9') && \
isalnum('0') == ft_isalnum('0') && \
isalnum('a') == ft_isalnum('a') && \
isalnum('e') == ft_isalnum('e') && \
isalnum('z') == ft_isalnum('z') && \
isalnum(8) == ft_isalnum(8) && \
isalnum('Z') == ft_isalnum('Z') && \
isalnum('A') == ft_isalnum('A') && \
isalnum('B') == ft_isalnum('B'))
{
printf("%c[1;32mSUCCESS isalnum\n", 27);
} else {
printf("%c[1;31mFAIL isalnum\n", 27);
}
printf("%c[1;34m------------------\n", 27);
}
void test_isprint(void) {
if (isprint(0) == ft_isprint(0) && \
isprint('0') == ft_isprint('0') && \
isprint('a') == ft_isprint('a') && \
isprint(' ') == ft_isprint(' ') && \
isprint(127) == ft_isprint(127) && \
isprint(8) == ft_isprint(8))
{
printf("%c[1;32mSUCCESS isprint\n", 27);
} else {
printf("%c[1;31mFAIL isprint\n", 27);
}
printf("%c[1;34m------------------\n", 27);
}
void test_isascii(void) {
if (isascii(0) == ft_isascii(0) && \
isascii(-1) == ft_isascii(-1) && \
isascii('a') == ft_isascii('a') && \
isascii(' ') == ft_isascii(' ') && \
isascii(128) == ft_isascii(128) && \
isascii(354) == ft_isascii(354))
{
printf("%c[1;32mSUCCESS isascii\n", 27);
} else {
printf("%c[1;31mFAIL isascii\n", 27);
}
printf("%c[1;34m------------------\n", 27);
}
void test_toupper(void) {
if (toupper(0) == ft_toupper(0) && \
toupper(-1) == ft_toupper(-1) && \
toupper('a') == ft_toupper('a') && \
toupper(' ') == ft_toupper(' ') && \
toupper('Z') == ft_toupper('Z') && \
toupper('z') == ft_toupper('z'))
{
printf("%c[1;32mSUCCESS toupper\n", 27);
} else {
printf("%c[1;31mFAIL toupper\n", 27);
}
printf("%c[1;34m------------------\n", 27);
}
void test_tolower(void) {
if (tolower('B') == ft_tolower('B') && \
tolower('8') == ft_tolower('8') && \
tolower('a') == ft_tolower('a') && \
tolower(' ') == ft_tolower(' ') && \
tolower('Z') == ft_tolower('Z') && \
tolower('A') == ft_tolower('A'))
{
printf("%c[1;32mSUCCESS tolower\n", 27);
} else {
printf("%c[1;31mFAIL tolower\n", 27);
}
printf("%c[1;34m------------------", 27);
printf("%c[1;32m\n", 27);
}
void test_strlen(void) {
if (strlen("12345") == ft_strlen("12345") && \
strlen("1") == ft_strlen("1") && \
strlen("") == ft_strlen("") && \
strlen(" ") == ft_strlen(" ") && \
strlen("123456789") == ft_strlen("123456789") && \
strlen("A") == ft_strlen("A"))
{
printf("%c[1;32mSUCCESS strlen\n", 27);
} else {
printf("%c[1;31mFAIL strlen\n", 27);
}
printf("%c[1;34m------------------\n", 27);
}
void test_memset(void) {
char test1[11] = "0123456789\0";
char test2[11] = "0123456789\0";
if (memcmp(memset(test1, 'a', 5), ft_memset(test2, 'a', 5), 5) == 0 && \
memcmp(memset(test1, 'b', 10), ft_memset(test2, 'b', 10), 10) == 0)
{
printf("%c[1;32mSUCCESS memset\n", 27);
} else {
printf("%c[1;31mFAIL memset\n", 27);
}
printf("%c[1;34m------------------\n", 27);
}
void test_memcpy(void) {
char test1[11] = "0123456789\0";
char test11[11] = "abcde\0";
char test2[11] = "0123456789\0";
char test22[11] = "abcde\0";
if (memcmp(memcpy(test1, test11, 5), ft_memcpy(test2, test22, 5), 5) == 0)
{
printf("%c[1;32mSUCCESS memcpy\n", 27);
} else {
printf("%c[1;31mFAIL memcpy\n", 27);
}
printf("%c[1;34m------------------\n", 27);
}
void test_strdup(void) {
char test1[11] = "0123456789\0";
char *str;
str = ft_strdup(test1);
if ((void *)str != (void *)test1 && strcmp(str, test1) == 0)
{
printf("%c[1;32mSUCCESS strdup\n", 27);
} else {
printf("%c[1;31mFAIL strdup\n", 27);
}
printf("%c[1;34m------------------\n", 27);
}
int main() {
test_bzero();
test_strcat();
test_isdigit();
test_isalpha();
test_isalnum();
test_isprint();
test_isascii();
test_toupper();
test_tolower();
test_puts();
test_strlen();
test_memset();
test_memcpy();
test_strdup();
return (0);
}