-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
111 lines (74 loc) · 3.99 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
#include "is_number.h"
#include "assert.h"
#include <string.h>
#include <stdio.h>
#define BLEN 50
#define strsize(s) (sizeof(s)-1)
int main()
{
int test = 1;
int tests = 30;
int prepost = ALLOW_EMPTY_POST_DOT | ALLOW_EMPTY_PRE_DOT;
printf("1..%i\n", tests);
assert(is_number("number", strsize("number")) == 0);
printf("ok %i 'number' is NOT a number\n", test++);
assert(is_number("-1", strsize("-1")) == 1);
printf("ok %i '-1' is a number\n", test++);
assert(is_number("", strsize("")) == 0);
printf("ok %i '' is NOT a number\n", test++);
assert(is_number(" ", strsize(" ")) == 0);
printf("ok %i ' ' is NOT a number\n", test++);
assert(is_number("0", strsize("0")) == 1);
printf("ok %i '0' is a number\n", test++);
assert(is_number("1.0", strsize("1.0")) == 1);
printf("ok %i '1.0' is a number\n", test++);
assert(is_number("1..0", strsize("1..0")) == 0);
printf("ok %i '1..0' is NOT a number\n", test++);
assert(is_number("1.0.", strsize("1.0.")) == 0);
printf("ok %i '1.0.' is NOT a number\n", test++);
assert(is_number("10.0", strsize("10.0")) == 1);
printf("ok %i '10.0' is a number\n", test++);
assert(is_number_with("10.0", strsize("10.0"), ONLY_TEST_INT) == 0);
printf("ok %i '10.0' is NOT a number with ONLY_TEST_INT\n", test++);
assert(is_number_with(".0", strsize(".0"), ONLY_TEST_INT | ALLOW_EMPTY_PRE_DOT) == 0);
printf("ok %i '.0' is NOT a number with ONLY_TEST_INT | ALLOW_EMPTY_PRE_DOT\n", test++);
assert(is_number_with("0.", strsize("0."), ONLY_TEST_INT | ALLOW_EMPTY_POST_DOT) == 0);
printf("ok %i '0.' is NOT a number with ONLY_TEST_INT | ALLOW_EMPTY_POST_DOT\n", test++);
assert(is_number(" 10", strsize(" 10")) == 1);
printf("ok %i ' 10' is a number\n", test++);
assert(is_number("\t10", strsize("\t10")) == 1);
printf("ok %i '\\t10' is a number\n", test++);
assert(is_number(" 10 1", strsize(" 10 1") ) == 0);
printf("ok %i ' 10 1' is NOT a number\n", test++);
assert(is_number_with("\t10", strsize("\t10"), STRICT_WHITESPACE) == 0);
printf("ok %i '\\t10' is NOT a number with STRICT_WHITESPACE\n", test++);
assert(is_number_with(" 10", strsize(" 10"), STRICT_WHITESPACE) == 0);
printf("ok %i ' 10' is NOT a number with STRICT_WHITESPACE\n", test++);
assert(is_number_with("10 ", strsize("10 "), STRICT_WHITESPACE) == 0);
printf("ok %i '10 ' is NOT a number with STRICT_WHITESPACE\n", test++);
assert(is_number("1.", strsize("1.")) == 0);
printf("ok %i '1.' is NOT a number\n", test++);
assert(is_number_with("1.", strsize("1."), ALLOW_EMPTY_POST_DOT) == 1);
printf("ok %i '1.' is a number with ALLOW_EMPTY_POST_DOT\n", test++);
assert(is_number_with(".1", strsize(".1"), ALLOW_EMPTY_PRE_DOT) == 1);
printf("ok %i '.1' is a number with ALLOW_EMPTY_PRE_DOT\n", test++);
assert(is_number_with("-.1", strsize("-.1"), ALLOW_EMPTY_PRE_DOT) == 1);
printf("ok %i '-.1' is a number with ALLOW_EMPTY_PRE_DOT\n", test++);
assert(is_number_with(".", strsize("."), ALLOW_EMPTY_POST_DOT) == 0);
printf("ok %i '.' is NOT a number with ALLOW_EMPTY_POST_DOT\n", test++);
assert(is_number_with(".", strsize("."), ALLOW_EMPTY_PRE_DOT) == 0);
printf("ok %i '.' is NOT a number with ALLOW_EMPTY_PRE_DOT\n", test++);
assert(is_number_with(".", strsize("."), prepost) == 1);
printf("ok %i '.' is a number with ALLOW_EMPTY_{PRE,POST}_DOT\n", test++);
assert(is_number_with("-.", strsize("-."), ALLOW_EMPTY_POST_DOT) == 0);
printf("ok %i '-.' is NOT a number with ALLOW_EMPTY_POST_DOT\n", test++);
assert(is_number_with("-.", strsize("-."), prepost) == 1);
printf("ok %i '-.' is a number with ALLOW_EMPTY_{PRE,POST}_DOT\n", test++);
assert(is_number_with("-.1", strsize("-.1"), ALLOW_EMPTY_PRE_DOT) == 1);
printf("ok %i '-.1' is a number with ALLOW_EMPTY_PRE_DOT\n", test++);
assert(is_number("-", strsize("-")) == 0);
printf("ok %i '-' is NOT a number\n", test++);
assert(is_number_with("-", strsize("-"), prepost) == 0);
printf("ok %i '-' is NOT a number with PREPOST\n", test++);
return 0;
}