diff --git a/src/main.c b/src/main.c index 1c706f1..21a1ee5 100644 --- a/src/main.c +++ b/src/main.c @@ -110,7 +110,6 @@ int test_ht_basic() { ht_free(&test_ht); return 1; } - int test_ht_put() { int return_code; ht test_ht; @@ -123,7 +122,6 @@ int test_ht_put() { ht_free(&test_ht); return return_code; } - int test_ht_get() { int return_code; ht test_ht; @@ -136,7 +134,6 @@ int test_ht_get() { ht_free(&test_ht); return return_code; } - int test_ht_remove(){ int return_code; ht test_ht; @@ -151,7 +148,6 @@ int test_ht_remove(){ ht_free(&test_ht); return return_code; } - int test_ht_foreach(){ int return_code; int sum = 0; @@ -167,24 +163,47 @@ int test_ht_foreach(){ return return_code; } -void run_test(char* test_name, int (*test_func)()) { +int run_test(char* test_name, int (*test_func)()) { + int success = test_func(); printf("Running test %-15s . . . ", test_name); - printf("%s\n", test_func() ? "Passed" : "Failed"); + printf("%s\n", success ? "Passed" : "Failed"); + return success; } int main(int argc, char** argv){ - run_test("vec_basic", test_vec_basic); - run_test("vec_add", test_vec_add); - run_test("vec_remove", test_vec_remove); - run_test("vec_find", test_vec_find); - run_test("vec_foreach", test_vec_foreach); - run_test("vec_index", test_vec_index); + char* test_names[11] = { + "vec_basic", + "vec_add", + "vec_remove", + "vec_find", + "vec_foreach", + "vec_index", + "ht_basic", + "ht_put", + "ht_get", + "ht_remove", + "ht_foreach" + }; - run_test("ht_basic", test_ht_basic); - run_test("ht_put", test_ht_put); - run_test("ht_get", test_ht_get); - run_test("ht_remove", test_ht_remove); - run_test("ht_foreach", test_ht_foreach); - return EXIT_SUCCESS; + int (*test_functions[11])() = { + test_vec_basic, + test_vec_add, + test_vec_remove, + test_vec_find, + test_vec_foreach, + test_vec_index, + test_ht_basic, + test_ht_put, + test_ht_get, + test_ht_remove, + test_ht_foreach + }; + + int test_index = 0; + int result = 1; + for(; test_index < 11 && result; test_index++){ + result = run_test(test_names[test_index], test_functions[test_index]); + } + return result ? EXIT_SUCCESS : EXIT_FAILURE; }