diff options
Diffstat (limited to 'tests/assertions.c')
-rw-r--r-- | tests/assertions.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/assertions.c b/tests/assertions.c index e79ae44..6951f58 100644 --- a/tests/assertions.c +++ b/tests/assertions.c @@ -229,3 +229,77 @@ const char * test_REQUIRE_EQ() return "test function did not longjump!"; } } + + +void f_test_REQUIRE_EQF() +{ + lily_set_epsilon(0.2); + REQUIRE_EQF(0.5, 0.0, "%0.1f"); + REQUIRE_EQF(0.5, 0.4, "%0.1f"); +} + +const char * test_REQUIRE_EQF() +{ + lily_g.HEAD.next = NULL; + lily_g.TAIL = &(lily_g.HEAD); + lily_g.failed = 0; + int test_failed = setjmp(lily_g.env); + + if (test_failed) { + if (lily_g.HEAD.next == NULL) + return "REQUIRE_EQF did not append any failure message"; + + if (lily_g.HEAD.next->next != NULL) + return "REQUIRE_EQF appended more than one message"; + + if (strcmp( + lily_g.HEAD.next->msg, + "REQUIRE failed: 0.5 == 0.0\n 0.5 = 0.5\n 0.0 = 0.0\n epsilon: 0.200000" + ) != 0) + return "incorrect message"; + + lily_msg_destroy(lily_g.HEAD.next); + return 0; + } + else { + f_test_REQUIRE_EQF(); + return "test continued to run!"; + } +} + + +void f_test_REQUIRE_EQS() +{ + const char *a = "hi"; + const char *b = "bye"; + REQUIRE_EQS(a, b); + REQUIRE_EQS("hi hi"+3, a); +} +const char * test_REQUIRE_EQS() +{ + lily_g.HEAD.next = NULL; + lily_g.TAIL = &(lily_g.HEAD); + lily_g.failed = 0; + int test_failed = setjmp(lily_g.env); + + if (test_failed) { + if (lily_g.HEAD.next == NULL) + return "REQUIRE_EQS did not append any failure message"; + + if (lily_g.HEAD.next->next != NULL) + return "REQUIRE_EQS appended more than one message"; + + if (strcmp( + lily_g.HEAD.next->msg, + "REQUIRE failed: a == b\n a = \"hi\"\n b = \"bye\"" + ) != 0) + return "incorrect message"; + + lily_msg_destroy(lily_g.HEAD.next); + return 0; + } + else { + f_test_REQUIRE_EQS(); + return "test continued to run!"; + } +} |