diff options
author | sanine <sanine.not@pm.me> | 2022-12-31 14:17:15 -0600 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-12-31 14:17:15 -0600 |
commit | c7bf6fcccd50ded889b7cfb853af51e7c5f28d45 (patch) | |
tree | eb39eabcef4f809bf8511118d3cdd631ddfb527d /tests/assertions.c | |
parent | 590b2997f93006112be93807b7e7a36d56d52809 (diff) |
add REQUIRE_EQF and REQUIRE_EQS
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!"; + } +} |