Commit | Line | Data |
---|---|---|
a7868768 | 1 | #define lu_assert_msg(expr, ...) \ |
e45132ac BA |
2 | if (!(expr)) { \ |
3 | fprintf(stdout, "Failure in file %s at line %i\n", __FILE__, __LINE__); \ | |
4 | fprintf(stdout, ## __VA_ARGS__); \ | |
5 | return; \ | |
6 | } | |
a7868768 BA |
7 | |
8 | #define lu_assert(expr) \ | |
e45132ac | 9 | lu_assert_msg(expr, ""); |
a7868768 | 10 | |
0261c3b6 | 11 | /* OP may be any comparison operator. */ |
a7868768 BA |
12 | |
13 | #define _lu_assert_int(X, OP, Y) do { \ | |
e45132ac BA |
14 | int _lu_x = (X); \ |
15 | int _lu_y = (Y); \ | |
16 | lu_assert_msg(_lu_x OP _lu_y, \ | |
1ff641f9 BA |
17 | "Assertion '"#X#OP#Y"' failed: "#X"==%i, "#Y"==%i\n", \ |
18 | _lu_x, _lu_y); \ | |
a7868768 | 19 | } while (0) |
1ff641f9 BA |
20 | #define lu_assert_int_eq(X, Y) _lu_assert_int(X, ==, Y) |
21 | #define lu_assert_int_ne(X, Y) _lu_assert_int(X, !=, Y) | |
a7868768 BA |
22 | #define lu_assert_int_lt(X, Y) _lu_assert_int(X, <, Y) |
23 | #define lu_assert_int_le(X, Y) _lu_assert_int(X, <=, Y) | |
24 | #define lu_assert_int_gt(X, Y) _lu_assert_int(X, >, Y) | |
25 | #define lu_assert_int_ge(X, Y) _lu_assert_int(X, >=, Y) | |
26 | ||
27 | #define _lu_assert_dbl(X, OP, Y) do { \ | |
e45132ac BA |
28 | double _lu_x = (X); \ |
29 | double _lu_y = (Y); \ | |
30 | lu_assert_msg(_lu_x OP _lu_y, \ | |
1ff641f9 BA |
31 | "Assertion '"#X#OP#Y"' failed: "#X"==%g, "#Y"==%g", \ |
32 | _lu_x, _lu_y); \ | |
a7868768 | 33 | } while (0) |
1ff641f9 BA |
34 | #define lu_assert_dbl_eq(X, Y) _lu_assert_dbl(X, ==, Y) |
35 | #define lu_assert_dbl_ne(X, Y) _lu_assert_dbl(X, !=, Y) | |
a7868768 BA |
36 | #define lu_assert_dbl_lt(X, Y) _lu_assert_dbl(X, <, Y) |
37 | #define lu_assert_dbl_le(X, Y) _lu_assert_dbl(X, <=, Y) | |
38 | #define lu_assert_dbl_gt(X, Y) _lu_assert_dbl(X, >, Y) | |
39 | #define lu_assert_dbl_ge(X, Y) _lu_assert_dbl(X, >=, Y) |