#include <stdbool.h>
Go to the source code of this file.
|
#define | TEST_EQUAL_EPSILON 0.1 |
|
#define | TEST_ERROR_DELTA_PERCENT 5 |
|
#define | TEST(NAME, BODY) |
|
#define | ASSERT(BOOL, OK, ERR) test_assert(T, OK, ERR, BOOL) |
|
#define | ASSERT_OK(BOOL, LABEL) ASSERT(BOOL, LABEL " is okay", LABEL " is not okay") |
|
#define | ASSERT_EQ(GOT, WANT, GOT_LABEL, WANT_LABEL) test_assert_equal(T, GOT_LABEL, WANT_LABEL, GOT, WANT) |
|
#define | ASSERT_IN_ERROR(GOT, WANT, GOT_LABEL, WANT_LABEL) test_assert_within_error(T, GOT_LABEL, WANT_LABEL, GOT, WANT) |
|
|
test_t * | test_start (const char *name) |
|
void | test_end (test_t *t) |
|
void | test_assert (test_t *t, const char *pass_message, const char *fail_message, bool passes) |
|
void | test_assert_equal (test_t *t, const char *a_label, const char *b_label, float a, float b) |
|
void | test_assert_within_error (test_t *t, const char *actual_label, const char *expected_label, float actual, float expected) |
|
◆ ASSERT
#define ASSERT |
( |
|
BOOL, |
|
|
|
OK, |
|
|
|
ERR |
|
) |
| test_assert(T, OK, ERR, BOOL) |
◆ ASSERT_EQ
#define ASSERT_EQ |
( |
|
GOT, |
|
|
|
WANT, |
|
|
|
GOT_LABEL, |
|
|
|
WANT_LABEL |
|
) |
| test_assert_equal(T, GOT_LABEL, WANT_LABEL, GOT, WANT) |
◆ ASSERT_IN_ERROR
#define ASSERT_IN_ERROR |
( |
|
GOT, |
|
|
|
WANT, |
|
|
|
GOT_LABEL, |
|
|
|
WANT_LABEL |
|
) |
| test_assert_within_error(T, GOT_LABEL, WANT_LABEL, GOT, WANT) |
◆ ASSERT_OK
#define ASSERT_OK |
( |
|
BOOL, |
|
|
|
LABEL |
|
) |
| ASSERT(BOOL, LABEL " is okay", LABEL " is not okay") |
◆ TEST
#define TEST |
( |
|
NAME, |
|
|
|
BODY |
|
) |
| |
Value: { \
}
test_t * test_start(const char *name)
Definition at line 19 of file test.h.
◆ TEST_EQUAL_EPSILON
#define TEST_EQUAL_EPSILON 0.1 |
Definition at line 7 of file test.h.
◆ TEST_ERROR_DELTA_PERCENT
#define TEST_ERROR_DELTA_PERCENT 5 |
◆ test_assert()
void test_assert |
( |
test_t * |
t, |
|
|
const char * |
pass_message, |
|
|
const char * |
fail_message, |
|
|
bool |
passes |
|
) |
| |
Definition at line 33 of file test.c.
34 {
35 if (passes) {
37 } else {
39 }
40
42}
◆ test_assert_equal()
void test_assert_equal |
( |
test_t * |
t, |
|
|
const char * |
a_label, |
|
|
const char * |
b_label, |
|
|
float |
a, |
|
|
float |
b |
|
) |
| |
Definition at line 44 of file test.c.
45 {
47 if (passes) {
48 printf(
TEST_OK "%s %s = %s (%f = %f)\n", t->
name, a_label, b_label, a, b);
49 } else {
50 printf(
TEST_ERR "%s %s ≠ %s (%f ≠ %f)\n", t->
name, a_label, b_label, a, b);
51 }
52
54}
#define TEST_EQUAL_EPSILON
◆ test_assert_within_error()
void test_assert_within_error |
( |
test_t * |
t, |
|
|
const char * |
actual_label, |
|
|
const char * |
expected_label, |
|
|
float |
actual, |
|
|
float |
expected |
|
) |
| |
Definition at line 56 of file test.c.
58 {
59 float percent_error = (actual - expected) / expected * 100;
61 if (passes) {
62 printf(
TEST_OK "%s %s ≈ %s (%f ≈ %f)\n", t->
name, actual_label,
63 expected_label, actual, expected);
64 } else {
65 printf(
TEST_ERR "%s %s ≠ %s (%f ≠ %f)\n", t->
name, actual_label,
66 expected_label, actual, expected);
67 }
68
70}
#define TEST_ERROR_DELTA_PERCENT
◆ test_end()
Definition at line 22 of file test.c.
22 {
25 } else {
27 }
28
29
30 free(t);
31}
◆ test_start()
test_t * test_start |
( |
const char * |
name | ) |
|
Definition at line 9 of file test.c.
9 {
11 assert(t != NULL);
12
13
16
18
19 return t;
20}