| 1 | #define lu_assert_msg(expr, ...) \ |
| 2 | if (!(expr)) { \ |
| 3 | fprintf(stdout, "Failure in file %s at line %i\n", __FILE__, __LINE__); \ |
| 4 | fprintf(stdout, ## __VA_ARGS__); \ |
| 5 | return; \ |
| 6 | } |
| 7 | |
| 8 | #define lu_assert(expr) \ |
| 9 | lu_assert_msg(expr, ""); |
| 10 | |
| 11 | /* OP may be any comparison operator. */ |
| 12 | |
| 13 | #define _lu_assert_int(X, OP, Y) do { \ |
| 14 | int _lu_x = (X); \ |
| 15 | int _lu_y = (Y); \ |
| 16 | lu_assert_msg(_lu_x OP _lu_y, \ |
| 17 | "Assertion '"#X#OP#Y"' failed: "#X"==%i, "#Y"==%i\n", \ |
| 18 | _lu_x, _lu_y); \ |
| 19 | } while (0) |
| 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) |
| 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 { \ |
| 28 | double _lu_x = (X); \ |
| 29 | double _lu_y = (Y); \ |
| 30 | lu_assert_msg(_lu_x OP _lu_y, \ |
| 31 | "Assertion '"#X#OP#Y"' failed: "#X"==%g, "#Y"==%g", \ |
| 32 | _lu_x, _lu_y); \ |
| 33 | } while (0) |
| 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) |
| 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) |