From 1b62e92bcc18762a8e4a2e9e4dc322705bfb7eec Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 4 Jan 2023 19:12:53 -0600 Subject: add kai_text_to_longs() --- src/util/util.test.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/util/util.test.c') diff --git a/src/util/util.test.c b/src/util/util.test.c index 26aa3d1..6288039 100644 --- a/src/util/util.test.c +++ b/src/util/util.test.c @@ -91,5 +91,42 @@ LILY_TEST("convert string to real array with fewer conversions than expected") #include LILY_PUSH_TEST() +LILY_TEST("convert string to int array") +{ + /* the lucas numbers 4 u math fans out there */ + const char *str = "2 1 3 4 7"; + long array[5]; + int conv = kai_text_to_longs(array, str, 5); + + CHECK_EQ(conv, 5, "%d"); + + CHECK_EQ(array[0], 2, "%d"); + CHECK_EQ(array[1], 1, "%d"); + CHECK_EQ(array[2], 3, "%d"); + CHECK_EQ(array[3], 4, "%d"); + CHECK_EQ(array[4], 7, "%d"); +} +#include LILY_PUSH_TEST() + + +LILY_TEST("convert string to int array with fewer conversions than expected") +{ + const char *str = "2 1"; + long array[5]; + int conv = kai_text_to_longs(array, str, 5); + + CHECK_EQ(conv, 2, "%d"); + + CHECK_EQ(array[0], 2, "%d"); + CHECK_EQ(array[1], 1, "%d"); + CHECK_EQ(array[2], 0, "%d"); + CHECK_EQ(array[3], 0, "%d"); + CHECK_EQ(array[4], 0, "%d"); +} +#include LILY_PUSH_TEST() + + + + #define LILY_FILE_END #include LILY_REGISTER_TESTS() -- cgit v1.2.1