Add check if all tests passed.

This commit is contained in:
Danila Fedorin 2016-12-21 14:44:39 -08:00
parent 281f49d5e5
commit d41a085bcd

View File

@ -110,7 +110,6 @@ int test_ht_basic() {
ht_free(&test_ht); ht_free(&test_ht);
return 1; return 1;
} }
int test_ht_put() { int test_ht_put() {
int return_code; int return_code;
ht test_ht; ht test_ht;
@ -123,7 +122,6 @@ int test_ht_put() {
ht_free(&test_ht); ht_free(&test_ht);
return return_code; return return_code;
} }
int test_ht_get() { int test_ht_get() {
int return_code; int return_code;
ht test_ht; ht test_ht;
@ -136,7 +134,6 @@ int test_ht_get() {
ht_free(&test_ht); ht_free(&test_ht);
return return_code; return return_code;
} }
int test_ht_remove(){ int test_ht_remove(){
int return_code; int return_code;
ht test_ht; ht test_ht;
@ -151,7 +148,6 @@ int test_ht_remove(){
ht_free(&test_ht); ht_free(&test_ht);
return return_code; return return_code;
} }
int test_ht_foreach(){ int test_ht_foreach(){
int return_code; int return_code;
int sum = 0; int sum = 0;
@ -167,24 +163,47 @@ int test_ht_foreach(){
return return_code; 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("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){ int main(int argc, char** argv){
run_test("vec_basic", test_vec_basic); char* test_names[11] = {
run_test("vec_add", test_vec_add); "vec_basic",
run_test("vec_remove", test_vec_remove); "vec_add",
run_test("vec_find", test_vec_find); "vec_remove",
run_test("vec_foreach", test_vec_foreach); "vec_find",
run_test("vec_index", test_vec_index); "vec_foreach",
"vec_index",
"ht_basic",
"ht_put",
"ht_get",
"ht_remove",
"ht_foreach"
};
run_test("ht_basic", test_ht_basic); int (*test_functions[11])() = {
run_test("ht_put", test_ht_put); test_vec_basic,
run_test("ht_get", test_ht_get); test_vec_add,
run_test("ht_remove", test_ht_remove); test_vec_remove,
run_test("ht_foreach", test_ht_foreach); test_vec_find,
return EXIT_SUCCESS; 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;
} }