diff --git a/CMakeLists.txt b/CMakeLists.txt index 6351697..851db44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,5 +16,11 @@ add_executable(game_test_thoguet game_test_thoguet.c) #les dépendances sont calculées automatiquement target_link_libraries(game_text game) +target_link_libraries(game_test_thoguet game) add_library (game game.o game_aux.c) add_test(test_thoguet_dummy ./game_test_thoguet dummy) +add_test(test_thoguet_new ./game_test_thoguet game_new) +add_test(test_thoguet_game_print ./game_test_thoguet game_print) +add_test(test_thoguet_get_square ./game_test_thoguet game_get_square) +add_test(test_thoguet_default ./game_test_thoguet game_default) +add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_solution) diff --git a/game_test_thoguet.c b/game_test_thoguet.c index fe1470f..b9f68c5 100644 --- a/game_test_thoguet.c +++ b/game_test_thoguet.c @@ -2,6 +2,9 @@ #include #include #include +#include +#include "game.h" +#include "game_aux.h" /* ********** DUMMY ********** */ @@ -9,6 +12,102 @@ bool test_dummy(void){ return EXIT_SUCCESS; } +/* ********* game_new ********* */ + +bool test_game_new(void){ + square tab[DEFAULT_SIZE*DEFAULT_SIZE]; + game g; + for (int i = 0; i <= 128; i ++){ + g = NULL; + for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ + tab[j] = i; + } + printf("%d\n",i); + g = game_new(tab); + assert(g); + } + return EXIT_SUCCESS; +} + +/* ******** game_print ******** */ + +// est ce qu'il faut faire avec un tab invalide ? + +bool test_game_print(void){ + game_print(NULL); + square tab[DEFAULT_SIZE*DEFAULT_SIZE]; + for (int i = 0; i <= 128; i ++){ + for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ + tab[j] = i; + } + printf("%d\n",i); + game_print(game_new(tab)); + } + return EXIT_SUCCESS; +} + +/* ******* game_get_square ******* */ + +bool test_game_get_square(void){ + game g = game_new_empty(); + square tab[DEFAULT_SIZE*DEFAULT_SIZE]; + for (int i = 0; i <= 128; i ++){ + for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ + tab[j] = i; + g = game_new(tab); + printf("[%d, %d] %d %d\n",j/(DEFAULT_SIZE),j-(j/(DEFAULT_SIZE))-(j/(DEFAULT_SIZE)*(DEFAULT_SIZE-1)),game_get_square(g,j/(DEFAULT_SIZE),j-(j/(DEFAULT_SIZE))-(j/(DEFAULT_SIZE)*(DEFAULT_SIZE-1))),tab[j]); + assert(game_get_square(g,j/(DEFAULT_SIZE),j-(j/(DEFAULT_SIZE))-(j/(DEFAULT_SIZE)*(DEFAULT_SIZE-1))) == tab[j]); + } + } + return EXIT_SUCCESS; +} + +/* ******* game_default ******* */ + +bool test_game_default(void){ + game g = game_default(); + //a verif aps sur + assert(g); + assert(game_get_square(g,0,2) == S_BLACK1); + assert(game_get_square(g,1,2) == S_BLACK2); + assert(game_get_square(g,2,5) == S_BLACKU); + assert(game_get_square(g,2,6) == S_BLACK2); + assert(game_get_square(g,4,0) == S_BLACK1); + assert(game_get_square(g,4,1) == S_BLACKU); + assert(game_get_square(g,5,4) == S_BLACK2); + assert(game_get_square(g,6,4) == S_BLACKU); + return EXIT_SUCCESS; +} + +/* *** game_default_solution *** */ + +bool test_game_default_solution(void){ + game g = game_default_solution(); + //a verif aps sur + assert(g); + //default + assert(game_get_square(g,0,2) == S_BLACK1); + assert(game_get_square(g,1,2) == S_BLACK2); + assert(game_get_square(g,2,5) == S_BLACKU); + assert(game_get_square(g,2,6) == S_BLACK2); + assert(game_get_square(g,4,0) == S_BLACK1); + assert(game_get_square(g,4,1) == S_BLACKU); + assert(game_get_square(g,5,4) == S_BLACK2); + assert(game_get_square(g,6,4) == S_BLACKU); + //solution + assert(game_get_square(g,0,0) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,1,1) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,0,3) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,1,6) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,2,2) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,3,6) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,4,4) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,5,0) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,5,5) == (S_LIGHTBULB|F_LIGHTED)); + assert(game_get_square(g,6,1) == (S_LIGHTBULB|F_LIGHTED)); + return EXIT_SUCCESS; +} + /* ********** USAGE ********** */ int usage(int argc, char *argv[]) @@ -27,6 +126,16 @@ int main(int argc, char * argv[]){ bool ok = false; if (strcmp("dummy", argv[1]) == 0) ok = test_dummy(); + else if (strcmp("game_print", argv[1]) == 0) + ok = test_game_print(); + else if (strcmp("game_default", argv[1]) == 0) + ok = test_game_default(); + else if (strcmp("game_default_solution", argv[1]) == 0) + ok = test_game_default_solution(); + else if (strcmp("game_new", argv[1]) == 0) + ok = test_game_new(); + else if (strcmp("game_get_square", argv[1]) == 0) + ok = test_game_get_square(); else { fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); exit(EXIT_FAILURE);