The objective of this exercise is to let you practice and get familiar with the concepts of C pointers and arrays and a simple C unit test API. You should complete this exercise and test in a CSIL machine.
exchange, reverse_array,
match_add, match_action, and mat_mat_mult.
set_key_action and mat_vect_mult. Namely use mu_assert(), mu_run_test()
and mu_print_summary(). After calling a targeted function to be tested, you donot use your own result check to report a failed case. Instead, you use mu_assert() to detect and report an error due to the mismatch of expected results.
Files minunit.h and minunit.c define macro mu_assert
and two functions mu_run_test and mu_print_summary as
a very simple API for C unit tests. Their usage is illustated
in file exercise_test.c for testing functions set_key_action and mat_vect_mult implemented
in exercise.c.
You submit the above two files through gradescope.com under Assignment "Exercise 1" (available by Jan 10). You will be invited to join Piazza around Jan 8 Thursday. We will announce the GradeScope join code in Piazza before Jan 10
Proper use:
char * set_key_action_test(void){
char *key="del1";
int ret=set_key_action(NULL, key, del1);
mu_assert("Error in set_key_action with NULL value", ret == FAIL);
return NULL;
}
Notice that the above test includes one case. You may add another test for another case. The released sample includes the two cases in one test.
Improper design:
char * set_key_action_test(void){
char *key="del1";
int ret=set_key_action(NULL, key, del1);
if(ret==FAIL) {
printf(“Something is wrong\n”);
return NULL;
}
mu_assert("Error in set_key_action with NULL value", ret == FAIL);
return NULL;
}
Notice that even your own check finds there is an error, the minunit package (mu_run_test() and mu_print_summay()) does not catch this error and the summary printed would be wrong. Your unit test code should let the minunit package catch the error using mu_assert, count errors and report properly.