-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ctype.c
More file actions
224 lines (182 loc) · 3.74 KB
/
Copy pathtest_ctype.c
File metadata and controls
224 lines (182 loc) · 3.74 KB
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
#include "stdio.h"
#include "ctype.h"
#include "testy/test.h"
//
static void test_islower()
{
SUITE("islower");
TEST(TRUE == islower('a'));
TEST(TRUE == islower('z'));
TEST(FALSE == islower('A'));
TEST(FALSE == islower('Z'));
TEST(FALSE == islower('1'));
}
//
static void test_isupper()
{
SUITE("islower");
TEST(TRUE == isupper('A'));
TEST(TRUE == isupper('Z'));
TEST(FALSE == isupper('a'));
TEST(FALSE == isupper('z'));
TEST(FALSE == isupper('1'));
}
//
static void test_isalpha()
{
SUITE("isalpha");
TEST(TRUE == isalpha('A'));
TEST(TRUE == isalpha('a'));
TEST(TRUE == isalpha('Z'));
TEST(TRUE == isalpha('a'));
TEST(FALSE == isalpha('0'));
TEST(FALSE == isalpha('9'));
TEST(FALSE == isalpha('-'));
}
//
static void test_isdigit()
{
SUITE("isdigit");
TEST(TRUE == isdigit('0'));
TEST(TRUE == isdigit('9'));
TEST(FALSE == isdigit('A'));
TEST(FALSE == isdigit('a'));
TEST(FALSE == isdigit('Z'));
TEST(FALSE == isdigit('a'));
}
//
static void test_isalnum()
{
SUITE("isalnum");
TEST(TRUE == isalnum('0'));
TEST(TRUE == isalnum('9'));
TEST(TRUE == isalnum('A'));
TEST(TRUE == isalnum('a'));
TEST(TRUE == isalnum('Z'));
TEST(TRUE == isalnum('a'));
TEST(FALSE == isalnum('-'));
TEST(FALSE == isalnum('@'));
TEST(FALSE == isalnum('&'));
}
//
static void test_tolower()
{
SUITE("tolower");
TEST('a' == tolower('A'));
TEST('z' == tolower('Z'));
TEST('a' == tolower('a'));
TEST('z' == tolower('z'));
TEST('0' == tolower('0'));
TEST('9' == tolower('9'));
TEST('@' == tolower('@'));
}
//
static void test_toupper()
{
SUITE("toupper");
TEST('A' == toupper('A'));
TEST('Z' == toupper('Z'));
TEST('A' == toupper('a'));
TEST('Z' == toupper('z'));
TEST('0' == toupper('0'));
TEST('9' == toupper('9'));
TEST('@' == toupper('@'));
}
//
static void test_isspace()
{
SUITE("isspace");
TEST(TRUE == isspace(' '));
TEST(TRUE == isspace('\f'));
TEST(TRUE == isspace('\t'));
TEST(TRUE == isspace('\n'));
TEST(TRUE == isspace('\r'));
TEST(FALSE == isspace('a'));
TEST(FALSE == isspace('0'));
}
//
static void test_isprint()
{
SUITE("isprint");
TEST(TRUE == isprint(' '));
TEST(TRUE == isprint('A'));
TEST(TRUE == isprint('~'));
TEST(FALSE == isprint('\t'));
TEST(FALSE == isprint('\n'));
TEST(FALSE == isprint(127)); // DEL
}
//
static void test_isgraph()
{
SUITE("isgraph");
TEST(TRUE == isgraph('A'));
TEST(TRUE == isgraph('!'));
TEST(TRUE == isgraph('~'));
TEST(FALSE == isgraph(' ')); // space excluded
TEST(FALSE == isgraph('\t'));
TEST(FALSE == isgraph(127));
}
//
static void test_ispunct()
{
SUITE("ispunct");
TEST(TRUE == ispunct('!'));
TEST(TRUE == ispunct('.'));
TEST(TRUE == ispunct('@'));
TEST(FALSE == ispunct('A'));
TEST(FALSE == ispunct('9'));
TEST(FALSE == ispunct(' '));
}
//
static void test_isxdigit()
{
SUITE("isxdigit");
TEST(TRUE == isxdigit('0'));
TEST(TRUE == isxdigit('9'));
TEST(TRUE == isxdigit('a'));
TEST(TRUE == isxdigit('f'));
TEST(TRUE == isxdigit('A'));
TEST(TRUE == isxdigit('F'));
TEST(FALSE == isxdigit('g'));
TEST(FALSE == isxdigit('G'));
TEST(FALSE == isxdigit('z'));
}
//
static void test_iscntrl()
{
SUITE("iscntrl");
TEST(TRUE == iscntrl('\0'));
TEST(TRUE == iscntrl('\t'));
TEST(TRUE == iscntrl('\n'));
TEST(TRUE == iscntrl(127)); // DEL
TEST(FALSE == iscntrl(' '));
TEST(FALSE == iscntrl('A'));
}
//
static void test_isblank()
{
SUITE("isblank");
TEST(TRUE == isblank(' '));
TEST(TRUE == isblank('\t'));
TEST(FALSE == isblank('\n'));
TEST(FALSE == isblank('A'));
TEST(FALSE == isblank('0'));
}
//
void test_ctype()
{
test_islower();
test_isupper();
test_isalpha();
test_isdigit();
test_isalnum();
test_tolower();
test_toupper();
test_isspace();
test_isprint();
test_isgraph();
test_ispunct();
test_isxdigit();
test_iscntrl();
test_isblank();
}