-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.h
More file actions
40 lines (36 loc) · 907 Bytes
/
test.h
File metadata and controls
40 lines (36 loc) · 907 Bytes
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
/*a Defines
*/
#define EPSILON (1E-10)
#define STR(x) #x
#define STRINGIFY(x) STR(x)
#define WHERE ( __FILE__ STRINGIFY(__LINE__) )
/*a Test infrastructure
*/
static int failures=0;
static void
assert(int should_be_true, const char *where, const char *error_fmt, va_list ap)
{
char buffer[256];
if (!should_be_true) {
vsnprintf(buffer, sizeof(buffer), error_fmt, ap);
printf("Failure at %s: %s\n", where, buffer);
failures++;
}
}
static void
assert(int should_be_true, const char *where, const char *error_fmt, ...)
{
va_list ap;
va_start(ap, error_fmt);
assert(should_be_true, where, error_fmt, ap);
va_end(ap);
}
static void
assert_dbeq(double a, double b, const char *where, const char *error_fmt, ...)
{
va_list ap;
va_start(ap, error_fmt);
double diff = fabs(a-b);
assert(diff<EPSILON, where, error_fmt, ap);
va_end(ap);
}