Commit 173cc771a785cafc526e50587f938be1f7f2ce5b

Thomas de Grivel 2024-03-07T16:43:31

ratio_test

diff --git a/test/ratio_test.c b/test/ratio_test.c
index 11018cf..53a63fa 100644
--- a/test/ratio_test.c
+++ b/test/ratio_test.c
@@ -22,42 +22,40 @@
 #include "../libc3/ratio.h"
 #include "test.h"
 
-#define RATIO_TEST_INSPECT(test_numerator, test_denominator, expected_string) \
-do {                                                                 \
-  s_ratio ratio;                                                              \
-  s_str result;                                                      \
-  integer_init_u64(&ratio.numerator, test_numerator);                        \
-  integer_init_u64(&ratio.denominator, test_denominator);                    \
-  char context[100];                                                 \
-  sprintf(context, "ratio_inspect(%d/%d) -> expected: %s", test_numerator, test_denominator, expected_string); \
-  test_context(context);                                                      \
-  TEST_EQ(ratio_inspect(&ratio, &result), &result);                                    \
-  TEST_STRNCMP(result.ptr.p, expected_string, result.size);          \
-  ratio_clean(&ratio);                                                        \
-  str_clean(&result);                                                \
-  test_context(NULL);                                                \
+#define RATIO_TEST_INSPECT(test_num, test_den, expected)               \
+  do {                                                                 \
+  s_ratio ratio;                                                       \
+  s_str result;                                                        \
+  integer_init_u64(&ratio.numerator, test_num);                        \
+  integer_init_u64(&ratio.denominator, test_den);                      \
+  test_context("ratio_inspect(" # test_num "/" # test_den              \
+               ") -> " # expected);                                    \
+  TEST_EQ(ratio_inspect(&ratio, &result), &result);                    \
+  TEST_STRNCMP(result.ptr.p, expected, result.size);                   \
+  ratio_clean(&ratio);                                                 \
+  str_clean(&result);                                                  \
+  test_context(NULL);                                                  \
 } while (0)
 
-#define RATIO_TEST_PARSE(test_string, expected_numerator, expected_denominator) \
-do {                                                                            \
-  sw result_num;                                                                              \
-  sw result_den;                                                                              \
-  s_buf buf;                                                         \
-  s_ratio ratio;                                                     \
-  s_str str;                                                                    \
-  str_init_1(&str, NULL, test_string);                                    \
-  char context[100];                                                 \
-  sprintf(context, "buf_parse_ratio(%s) -> expected: %d/%d", test_string, expected_numerator, expected_denominator); \
-  test_context(context);                                             \
-  buf_init_str(&buf, false, &str);                                    \
-  TEST_ASSERT(buf_parse_ratio(&buf, &ratio) > 0);                         \
-  result_num = integer_to_sw(&ratio.numerator);                                 \
-  result_den = integer_to_sw(&ratio.denominator);                               \
-  TEST_EQ(result_num, expected_numerator);                                    \
-  TEST_EQ(result_den, expected_denominator);                                  \
-  str_clean(&str);                                                   \
-  ratio_clean(&ratio);                                               \
-  test_context(NULL);                                                \
+#define RATIO_TEST_PARSE(test, expected_num, expected_den)             \
+  do {                                                                 \
+    sw result_num;                                                     \
+    sw result_den;                                                     \
+    s_buf buf;                                                         \
+  s_ratio ratio;                                                       \
+  s_str str;                                                           \
+  str_init_1(&str, NULL, test);                                        \
+  test_context("buf_parse_ratio(" # test ") -> "                       \
+               # expected_num "/" # expected_den);                     \
+  buf_init_str(&buf, false, &str);                                     \
+  TEST_ASSERT(buf_parse_ratio(&buf, &ratio) > 0);                      \
+  result_num = integer_to_sw(&ratio.numerator);                        \
+  result_den = integer_to_sw(&ratio.denominator);                      \
+  TEST_EQ(result_num, expected_num);                                   \
+  TEST_EQ(result_den, expected_den);                                   \
+  str_clean(&str);                                                     \
+  ratio_clean(&ratio);                                                 \
+  test_context(NULL);                                                  \
 } while (0)
 
 TEST_CASE_PROTOTYPE(ratio_inspect);
@@ -93,4 +91,4 @@ TEST_CASE(ratio_parse)
     RATIO_TEST_PARSE("100/1", 100, 1);
     RATIO_TEST_PARSE("1000/1", 1000, 1);
 }
-TEST_CASE_END(ratio_parse)
\ No newline at end of file
+TEST_CASE_END(ratio_parse)