From 1d7727e9ff877f7ad4068ab768f99636bf72e8b4 Mon Sep 17 00:00:00 2001 From: starnakin Date: Thu, 29 Aug 2024 17:24:48 +0200 Subject: [PATCH] add: test --- test/test.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/test/test.c b/test/test.c index 5ce8e4f..7ae599c 100644 --- a/test/test.c +++ b/test/test.c @@ -2,7 +2,7 @@ #include "../include/libasm.h" #include "string.h" -void test_int(size_t expected_value, size_t value) +void test_size_t(size_t expected_value, size_t value) { if (expected_value != value) printf("[FAILED] %zu != %zu", expected_value, value); @@ -10,6 +10,14 @@ void test_int(size_t expected_value, size_t value) printf("[OK]"); } +void test_int(int expected_value, int value) +{ + if (expected_value != value) + printf("[FAILED] %d != %d", expected_value, value); + else + printf("[OK]"); +} + void test_str(const char *expected_value, const char *value) { if (strcmp(expected_value, value) == 0) @@ -18,14 +26,6 @@ void test_str(const char *expected_value, const char *value) printf("[OK]"); } -void test_int(size_t expected_value, size_t value) -{ - if (expected_value != value) - printf("[FAILED] %zu != %zu", expected_value, value); - else - printf("[OK]"); -} - void multiple_test_int(size_t (*normal_func)(const char*), size_t (*own_func)(const char*), const char **values) { for (size_t i = 0; values[i] != NULL; i++) @@ -36,6 +36,15 @@ void multiple_test_int(size_t (*normal_func)(const char*), size_t (*own_func)(co } } +void multiple_test_int_2(int (*normal_func)(const char *, const char *), int (*own_func)(const char *, const char *), const char *values[][2]) +{ + for (size_t i = 0; values[i][0] != NULL; i++) + { + printf("test: %s==%s", values[i][0], values[i][1]); + test_int(normal_func(values[i][0], values[i][1]), own_func(values[i][0], values[i][1])); + printf("\n"); + } +} int main() { @@ -43,7 +52,7 @@ int main() multiple_test_int(&strlen, ft_strlen, strlen_tests); - const char *strlen_tests[][2] = {{"bonjour", "bonjour"}, {"", ""}, {"bonjour", "salut"}, {"co\0fgf", "co\0fgf"}, {}, NULL}; + const char *strcmp_tests[][2] = {{"w", "z"}, {"bonjour", "bonjour"}, {"", ""}, {"bonjour", "salut"}, {"co\0fgf", "co\0fgf"}, NULL}; - multiple_test_int(&strlen, ft_strlen, strlen_tests); + multiple_test_int_2(&strcmp, ft_strcmp, strcmp_tests); } \ No newline at end of file