From 04576dc2a3f761eb041b808b56f13a58052e7655 Mon Sep 17 00:00:00 2001 From: Stefan Zabka Date: Sun, 24 May 2020 12:19:52 +0200 Subject: Moved back to 02_exercise --- 02_exercise/prompt_utils_test.c | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 02_exercise/prompt_utils_test.c (limited to '02_exercise/prompt_utils_test.c') diff --git a/02_exercise/prompt_utils_test.c b/02_exercise/prompt_utils_test.c new file mode 100644 index 0000000..1be6162 --- /dev/null +++ b/02_exercise/prompt_utils_test.c @@ -0,0 +1,45 @@ +#include "array.h" +#include "prompt_utils.h" +#include +#include +#include + +void test_get_separator_indices() { + char const *const test_str = "/This/is/a/test"; + size_t const *const result = get_separator_indices(test_str, '/'); + for (size_t i = 0; i < arrayLen(result); i++) { + printf("%ld : %s \n", result[i], test_str + result[i]); + } +} +void test_paths(char const *const from, char const *const to, + char const *const expected) { + size_t const *const result = get_separator_indices(from, '/'); + for (size_t i = 0; i < arrayLen(result); i++) { + printf("%ld : %s \n", result[i], from + result[i]); + } + size_t const *const result2 = get_separator_indices(to, '/'); + for (size_t i = 0; i < arrayLen(result2); i++) { + printf("%ld : %s \n", result2[i], to + result2[i]); + } + char const *const path = relative_path(from, to); + printf("The relative path of %s to %s is %s \n", from, to, path); + + assert(strcmp(path, expected) == 0); +} +void test_relative_path() { + test_paths("/Test", "/Test/a", "./a"); + test_paths("/abc/def/ghi", "/abc/def/ghi", "."); + test_paths("/Test", "/Test/a/asd", "./a/asd"); + test_paths("/Test/b/c", "/Test/b", ".."); + test_paths("/", "/Test/a/asd", "./Test/a/asd"); + test_paths("/Test/c", "/Test/b", "../b"); + test_paths("/B/C", "/", "../.."); +} + + +int main(void) { + test_relative_path(); + test_get_separator_indices(); + return 0; +} + -- cgit v1.2.3-54-g00ecf