diff --git a/game_examples.c b/game_examples.c index febe04e..abe734c 100644 --- a/game_examples.c +++ b/game_examples.c @@ -212,7 +212,7 @@ square sol_5x3w_squares[] = { /* GAME SAVE (V3) */ /* ************************************************************************** */ -char game_default_str[] = { +char default_str[] = { '7', ' ', '7', ' ', '0', '\n', // \n 'b', 'b', '1', 'b', 'b', 'b', 'b', '\n', // ...\n 'b', 'b', '2', 'b', 'b', 'b', 'b', '\n', // ...\n @@ -222,4 +222,24 @@ char game_default_str[] = { 'b', 'b', 'b', 'b', '2', 'b', 'b', '\n', // ...\n 'b', 'b', 'b', 'b', 'w', 'b', 'b', '\n' // ...\n }; + +char ext_5x3w_str[] = { + '5', ' ', '3', ' ', '1', '\n', // \n + 'b', 'b', 'b', '\n', // ...\n + 'w', 'b', '1', '\n', // ...\n + 'b', '2', 'b', '\n', // ...\n + 'b', 'b', 'b', '\n', // ...\n + 'b', 'b', 'b', '\n' // ...\n +}; + +char other_str[] = { + '7', ' ', '7', ' ', '0', '\n', // \n + '*', 'b', '1', 'b', 'b', 'b', 'b', '\n', // ...\n + 'b', 'b', '2', 'b', 'b', 'b', 'b', '\n', // ...\n + 'b', 'b', 'b', 'b', 'b', 'w', '2', '\n', // ...\n + '*', 'b', 'b', 'b', 'b', 'b', 'b', '\n', // ...\n + '1', 'w', 'b', 'b', 'b', 'b', 'b', '\n', // ...\n + 'b', 'b', 'b', 'b', '2', 'b', 'b', '\n', // ...\n + 'b', 'b', 'b', 'b', 'w', 'b', '-', '\n' // ...\n +}; /* ************************************************************************** */ \ No newline at end of file diff --git a/game_examples.h b/game_examples.h index 89ccf51..52d792c 100644 --- a/game_examples.h +++ b/game_examples.h @@ -32,6 +32,8 @@ extern square ext_2x2w_squares[]; extern square sol_2x2w_squares[]; // V3 -extern char game_default_str[]; +extern char default_str[]; +extern char ext_5x3w_str[]; +extern char other_str[]; #endif // __GAME_EXAMPLES_H__ diff --git a/game_test.c b/game_test.c index af17cb2..1cc9f11 100644 --- a/game_test.c +++ b/game_test.c @@ -21,10 +21,11 @@ #define USABLE_SQUARE 2 -#define NB_CHAR_SAVED_FILE_INFO 6 +#define NB_CHAR_SAVED_FILE_FIRST_LINE 6 // ' '' ''\n' /* ********** game_get_black_number ********** */ bool test_game_get_black_number(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -54,6 +55,7 @@ bool test_game_get_black_number(bool whoami, char** name) { /* ********** game_is_black ********** */ bool test_game_is_black(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -86,6 +88,7 @@ bool test_game_is_black(bool whoami, char** name) { /* ********** game_is_lightbulb ********** */ bool test_game_is_lightbulb(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -115,6 +118,7 @@ bool test_game_is_lightbulb(bool whoami, char** name) { /* ********** game_is_blank ********** */ bool test_game_is_blank(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -144,6 +148,7 @@ bool test_game_is_blank(bool whoami, char** name) { /* ********** game_delete ********** */ bool test_game_delete(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -157,6 +162,7 @@ bool test_game_delete(bool whoami, char** name) { /* ********** game_equal ********** */ bool test_equal_ext(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -193,6 +199,7 @@ bool test_equal_ext(bool whoami, char** name) { } bool test_equal(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -222,6 +229,7 @@ bool test_equal(bool whoami, char** name) { /* ********** game_new_empty ********** */ bool test_game_new_empty(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -242,6 +250,7 @@ bool test_game_new_empty(bool whoami, char** name) { /* ********** game_copy ********** */ bool test_game_copy(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -275,6 +284,7 @@ bool test_game_copy(bool whoami, char** name) { /* ********** game_undo ********** */ bool test_game_undo(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -308,6 +318,7 @@ bool test_game_undo(bool whoami, char** name) { /* ********** game_redo ********** */ bool test_game_redo(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -347,6 +358,7 @@ bool test_game_redo(bool whoami, char** name) { * @return true if every game has been created well */ bool test_game_new_empty_ext(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -371,6 +383,7 @@ bool test_game_new_empty_ext(bool whoami, char** name) { * @return true if every game has been created well and well filled */ bool test_game_new_ext(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -409,6 +422,7 @@ bool test_game_new_ext(bool whoami, char** name) { * @return true if there is no errors */ bool test_game_is_over(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -436,6 +450,7 @@ bool test_game_is_over(bool whoami, char** name) { * @return true if there is no error */ bool test_game_restart(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -476,6 +491,7 @@ bool test_game_restart(bool whoami, char** name) { * @return true if there is no error */ bool test_game_new(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -508,6 +524,7 @@ bool test_game_new(bool whoami, char** name) { * @return true if there is no error */ bool test_game_print(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -539,6 +556,7 @@ bool test_game_print(bool whoami, char** name) { * @return true if there is no error */ bool test_game_get_square(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -569,6 +587,7 @@ bool test_game_get_square(bool whoami, char** name) { * @return true if there is no error */ bool test_game_default(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -602,6 +621,7 @@ bool test_game_default(bool whoami, char** name) { * @return true if there is no error */ bool test_game_default_solution(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -684,6 +704,7 @@ On the 2x2, 3x3 and 5x3 tests, we play these move to win and we test if the grid (5x3) */ bool test_game_update_flags(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -774,6 +795,7 @@ bool test_game_update_flags(bool whoami, char** name) { * @return true if there is no error */ bool test_game_play_move(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -805,6 +827,7 @@ bool test_game_play_move(bool whoami, char** name) { * @return true if there is no error */ bool test_game_check_move(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -836,6 +859,7 @@ bool test_game_check_move(bool whoami, char** name) { /* ************** game_set_square ************** */ bool test_game_set_square(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -862,6 +886,7 @@ bool test_game_set_square(bool whoami, char** name) { /* ************** game_get_state ************** */ bool test_game_get_state(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -888,6 +913,7 @@ bool test_game_get_state(bool whoami, char** name) { /* ************** game_get_flags ************** */ bool test_game_get_flags(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -911,6 +937,7 @@ bool test_game_get_flags(bool whoami, char** name) { /* ************** game_is_marked ************** */ bool test_game_is_marked(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -934,6 +961,7 @@ bool test_game_is_marked(bool whoami, char** name) { /* ************** game_is_lighted ************** */ bool test_game_is_lighted(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -957,6 +985,7 @@ bool test_game_is_lighted(bool whoami, char** name) { /* ************** game_has_error ************** */ bool test_game_has_error(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -980,6 +1009,7 @@ bool test_game_has_error(bool whoami, char** name) { /* ************** game_nb_rows ************** */ bool test_game_nb_rows(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -995,6 +1025,7 @@ bool test_game_nb_rows(bool whoami, char** name) { /* ************** game_nb_cols ************** */ bool test_game_nb_cols(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -1010,6 +1041,7 @@ bool test_game_nb_cols(bool whoami, char** name) { /* ************** game_is_wrapping ************** */ bool test_game_is_wrapping(bool whoami, char** name) { + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; @@ -1034,21 +1066,51 @@ bool test_game_is_wrapping(bool whoami, char** name) { /* ***** game_save ***** */ bool test_game_save(bool whoami, char** name) { - // if whoami is true return in name the name of the function + // if whoami is true return in name (second parms) the name of the function if (whoami) { *name = (char*)__func__; return false; } game gdefault = game_default(); game_save(gdefault, "gdefault.txt"); + // try to open the created save file FILE* f_gdefault = fopen("gdefault.txt", "r"); assert(f_gdefault); - char char_to_test = '?'; - for (uint index_gdefault_str = 0; index_gdefault_str < game_nb_cols(gdefault) * game_nb_rows(gdefault) + NB_CHAR_SAVED_FILE_INFO + game_nb_rows(gdefault); - index_gdefault_str++) { - char_to_test = fgetc(f_gdefault); - assert(char_to_test == game_default_str[index_gdefault_str]); + // explore default_str and test if each char of the saved file == char of default_str + for (uint index_default_str = 0; + index_default_str < game_nb_cols(gdefault) * game_nb_rows(gdefault) + NB_CHAR_SAVED_FILE_FIRST_LINE + game_nb_rows(gdefault); index_default_str++) { + int char_to_test = fgetc(f_gdefault); + assert(char_to_test != -1); + assert((char)char_to_test == default_str[index_default_str]); } + game_delete(gdefault); + fclose(f_gdefault); + // do the same as gdefault but with ext_5x3w_squares + game g5x3w = game_new_ext(5, 3, ext_5x3w_squares, true); + game_save(g5x3w, "g5x3w.txt"); + FILE* file_g5x3w = fopen("g5x3w.txt", "r"); + assert(file_g5x3w); + for (uint index_ext_5x3w_str = 0; index_ext_5x3w_str < game_nb_cols(g5x3w) * game_nb_rows(g5x3w) + NB_CHAR_SAVED_FILE_FIRST_LINE + game_nb_rows(g5x3w); + index_ext_5x3w_str++) { + int char_to_test = fgetc(file_g5x3w); + assert(char_to_test != -1); + assert((char)char_to_test == ext_5x3w_str[index_ext_5x3w_str]); + } + game_delete(g5x3w); + fclose(file_g5x3w); + // do the same as gdefault but with other_squares + game gother = game_new(other_squares); + game_save(gother, "gother.txt"); + FILE* file_gother = fopen("gother.txt", "r"); + assert(file_gother); + for (uint index_other_str = 0; index_other_str < game_nb_cols(gother) * game_nb_rows(gother) + NB_CHAR_SAVED_FILE_FIRST_LINE + game_nb_rows(gother); + index_other_str++) { + int char_to_test = fgetc(file_gother); + assert(char_to_test != -1); + assert((char)char_to_test == other_str[index_other_str]); + } + game_delete(gother); + fclose(file_gother); return true; }