test_game_restart

This commit is contained in:
Théophyl Hoguet committed 2021-11-10 18:13:18 +01:00
1 parent b6c8edee84
commit b64bf4ee3f
2 files changed
+28 -6

No files matched your search

+2
View File
@@ -5,6 +5,7 @@ enable_testing()
#nom du projet #nom du projet
project (game_text) project (game_text)
include(CTest)
#positionne la variable #positionne la variable
set(CMAKE_C_FLAGS "-std=c99 -g -Wall") set(CMAKE_C_FLAGS "-std=c99 -g -Wall")
@@ -25,5 +26,6 @@ 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_get_square ./game_test_thoguet game_get_square)
add_test(test_thoguet_default ./game_test_thoguet game_default) add_test(test_thoguet_default ./game_test_thoguet game_default)
add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_solution) add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_solution)
add_test(test_game_restart ./game_test_thoguet game_restart)
add_test(test_thperrier_dummy ./game_test_thperrier dummy) add_test(test_thperrier_dummy ./game_test_thperrier dummy)
+26 -6
View File
@@ -12,15 +12,28 @@ bool test_dummy(void){
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* ******* game_restart ******* */
bool test_game_restart(void){
game g = game_default_solution();
game g1 = game_default_solution();
game_restart(g);
assert(game_equal(g,g1));
return true;
game_delete(g);
game_delete(g1);
}
/* ********* game_new ********* */ /* ********* game_new ********* */
bool test_game_new(void){ bool test_game_new(void){
square tab[DEFAULT_SIZE*DEFAULT_SIZE]; square tab[DEFAULT_SIZE*DEFAULT_SIZE];
game g; game g;
for (int i = 0; i <= 128; i ++){ int tab2[] = {0,1,2,8,9,10,11,12,13,16,32};
for (int i = 0; i < 11; i ++){
g = NULL; g = NULL;
for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){
tab[j] = i; tab[j] = tab2[i];
} }
printf("%d\n",i); printf("%d\n",i);
g = game_new(tab); g = game_new(tab);
@@ -36,9 +49,10 @@ bool test_game_new(void){
bool test_game_print(void){ bool test_game_print(void){
game_print(NULL); game_print(NULL);
square tab[DEFAULT_SIZE*DEFAULT_SIZE]; square tab[DEFAULT_SIZE*DEFAULT_SIZE];
for (int i = 0; i <= 128; i ++){ int tab2[] = {0,1,2,8,9,10,11,12,13,16,32};
for (int i = 0; i < 11; i ++){
for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){
tab[j] = i; tab[j] = tab2[i];
} }
printf("%d\n",i); printf("%d\n",i);
game_print(game_new(tab)); game_print(game_new(tab));
@@ -51,15 +65,17 @@ bool test_game_print(void){
bool test_game_get_square(void){ bool test_game_get_square(void){
game g = game_new_empty(); game g = game_new_empty();
square tab[DEFAULT_SIZE*DEFAULT_SIZE]; square tab[DEFAULT_SIZE*DEFAULT_SIZE];
for (int i = 0; i <= 128; i ++){ int tab2[] = {0,1,2,8,9,10,11,12,13,16,32};
for (int i = 0; i < 11; i ++){
for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){ for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){
tab[j] = i; tab[j] = tab2[i];
g = game_new(tab); 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]); 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]); assert(game_get_square(g,j/(DEFAULT_SIZE),j-(j/(DEFAULT_SIZE))-(j/(DEFAULT_SIZE)*(DEFAULT_SIZE-1))) == tab[j]);
} }
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
game_delete(g);
} }
/* ******* game_default ******* */ /* ******* game_default ******* */
@@ -77,6 +93,7 @@ bool test_game_default(void){
assert(game_get_square(g,5,4) == S_BLACK2); assert(game_get_square(g,5,4) == S_BLACK2);
assert(game_get_square(g,6,4) == S_BLACKU); assert(game_get_square(g,6,4) == S_BLACKU);
return EXIT_SUCCESS; return EXIT_SUCCESS;
game_delete(g);
} }
/* *** game_default_solution *** */ /* *** game_default_solution *** */
@@ -106,6 +123,7 @@ bool test_game_default_solution(void){
assert(game_get_square(g,5,5) == (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)); assert(game_get_square(g,6,1) == (S_LIGHTBULB|F_LIGHTED));
return EXIT_SUCCESS; return EXIT_SUCCESS;
game_delete(g);
} }
/* ********** USAGE ********** */ /* ********** USAGE ********** */
@@ -134,6 +152,8 @@ int main(int argc, char * argv[]){
ok = test_game_default_solution(); ok = test_game_default_solution();
else if (strcmp("game_new", argv[1]) == 0) else if (strcmp("game_new", argv[1]) == 0)
ok = test_game_new(); ok = test_game_new();
else if (strcmp("game_restart", argv[1]) == 0)
ok = test_game_restart();
else if (strcmp("game_get_square", argv[1]) == 0) else if (strcmp("game_get_square", argv[1]) == 0)
ok = test_game_get_square(); ok = test_game_get_square();
else { else {