comments + remove dupli code

This commit is contained in:
Théophyl Hoguet committed 2022-01-23 22:30:04 +01:00
1 parent 73d1835dc9
commit 0d2eac60ab
1 file changed
+206 -149
+206 -149
View File
@@ -8,11 +8,10 @@
#include "game_aux.h" #include "game_aux.h"
#include "game_ext.h" #include "game_ext.h"
int max(int a, int b) { #define SIZE_LIMIT_GAME 10
if (a > b) // put usable square at the start of the list
return a; #define LIST_OF_SQUARE square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_LIGHTED, F_ERROR};
return b; #define USABLE_SQUARE 2
}
/* ********** DUMMY ********** */ /* ********** DUMMY ********** */
bool test_dummy(void) { bool test_dummy(void) {
@@ -20,14 +19,19 @@ bool test_dummy(void) {
} }
/* ******* game_new_ext_empty ******* */ /* ******* game_new_ext_empty ******* */
/**
* @brief test creating every game between size 0 to SIZE_LIMIT_GAME
*
* @return EXIT_SUCCESS if every game has been created well
*/
bool test_game_new_empty_ext(void) { bool test_game_new_empty_ext(void) {
for (int h = 1; h <= 10; h++) { for (uint height = 1; height <= SIZE_LIMIT_GAME; height++) {
for (int w = 1; w <= 10; w++) { for (uint width = 1; width <= SIZE_LIMIT_GAME; width++) {
for (int wrap = 0; wrap < 2; wrap++) { for (int wrap = 0; wrap < 2; wrap++) {
game g = game_new_empty_ext(h, w, wrap); game g = game_new_empty_ext(height, width, wrap);
assert(g); assert(g);
game_delete(g); game_delete(g);
g = NULL;
} }
} }
} }
@@ -35,24 +39,28 @@ bool test_game_new_empty_ext(void) {
} }
/* ******* game_new_ext ******* */ /* ******* game_new_ext ******* */
/**
* @brief test creating every game between size 0 to SIZE_LIMIT_GAME + fill it with every square of list
*
* @return EXIT_SUCCESS if every game has been created well and well filled
*/
bool test_game_new_ext(void) { bool test_game_new_ext(void) {
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR}; LIST_OF_SQUARE;
for (int h = 1; h <= 10; h++) { for (uint height = 1; height <= SIZE_LIMIT_GAME; height++) {
for (int w = 1; w <= 10; w++) { for (uint width = 1; width <= SIZE_LIMIT_GAME; width++) {
square tab[h * w]; square tab[height * width];
for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) {
for (uint j = 0; j < h * w; j++) { for (uint index_tab = 0; index_tab < height * width; index_tab++) {
tab[j] = list[i]; tab[index_tab] = list[index_list];
} }
for (int wrap = 0; wrap < 2; wrap++) { for (int wrap = 0; wrap < 2; wrap++) {
printf("%d\n", i); printf("%d\n", index_list);
game g = game_new_ext(h, w, tab, wrap); game g = game_new_ext(height, width, tab, wrap);
assert(g); assert(g);
for (uint i2 = 0; i2 < game_nb_rows(g); i2++) { for (uint i = 0; i < game_nb_rows(g); i++) {
for (uint j = 0; j < game_nb_cols(g); j++) { for (uint j = 0; j < game_nb_cols(g); j++) {
printf("list :%d, get square :%d\n", list[i], game_get_square(g, i2, j)); printf("list :%d, get square :%d\n", list[index_list], game_get_square(g, i, j));
assert(list[i] == game_get_square(g, i2, j)); assert(list[index_list] == game_get_square(g, i, j));
} }
} }
game_delete(g); game_delete(g);
@@ -64,7 +72,11 @@ bool test_game_new_ext(void) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* ******* game_is_over ******* */ /* ******* game_is_over ******* */
/**
* @brief test if game_is_over return true with default_solution, false with one flag F_ERROR, false with one S_BLANK and false with game_default
*
* @return EXIT_SUCCESS if there is no errors
*/
bool test_game_is_over(void) { bool test_game_is_over(void) {
game g = game_default_solution(); game g = game_default_solution();
game_update_flags(g); game_update_flags(g);
@@ -83,52 +95,60 @@ bool test_game_is_over(void) {
} }
/* ******* game_restart ******* */ /* ******* game_restart ******* */
/**
* @brief test if game_restart remove every S_LIGHTBULB, S_MARK, and F_LIGHTED but nothing else and if the history has been reset
*
* @return EXIT_SUCCESS if there is no error
*/
bool test_game_restart(void) { bool test_game_restart(void) {
game g = game_default(); game game_def = game_default();
game g1 = game_default_solution(); game game_def_solution = game_default_solution();
game_set_square(g, 1, 5, S_BLACK4); game_set_square(game_def, 1, 5, S_BLACK4);
game_set_square(g1, 1, 5, S_BLACK4); game_set_square(game_def_solution, 1, 5, S_BLACK4);
game_set_square(g, 3, 2, S_BLACK3); game_set_square(game_def, 3, 2, S_BLACK3);
game_set_square(g1, 3, 2, S_BLACK3); game_set_square(game_def_solution, 3, 2, S_BLACK3);
game_play_move(g, 0, 1, S_LIGHTBULB); game_play_move(game_def, 0, 1, S_LIGHTBULB);
game_play_move(g1, 0, 1, S_LIGHTBULB); game_play_move(game_def_solution, 0, 1, S_LIGHTBULB);
game_play_move(g, 2, 0, S_MARK); game_play_move(game_def, 2, 0, S_MARK);
game_play_move(g1, 2, 0, S_MARK); game_play_move(game_def_solution, 2, 0, S_MARK);
game_play_move(g, 1, 1, S_LIGHTBULB); game_play_move(game_def, 1, 1, S_LIGHTBULB);
game_play_move(g1, 1, 1, S_LIGHTBULB); game_play_move(game_def_solution, 1, 1, S_LIGHTBULB);
game_play_move(g, 1, 1, S_MARK); game_play_move(game_def, 1, 1, S_MARK);
game_play_move(g1, 1, 1, S_MARK); game_play_move(game_def_solution, 1, 1, S_MARK);
game_undo(g); game_undo(game_def);
game_undo(g1); game_undo(game_def_solution);
assert(!game_equal(g, g1)); assert(!game_equal(game_def, game_def_solution));
game_restart(g1); game_restart(game_def_solution);
game_restart(g); game_restart(game_def);
assert(game_equal(g, g1)); assert(game_equal(game_def, game_def_solution));
game_redo(g); game_redo(game_def);
assert(game_equal(g, g1)); assert(game_equal(game_def, game_def_solution));
game_undo(g); game_undo(game_def);
assert(game_equal(g, g1)); assert(game_equal(game_def, game_def_solution));
game_delete(g); game_delete(game_def);
game_delete(g1); game_delete(game_def_solution);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* ********* game_new ********* */ /* ********* game_new ********* */
/**
* @brief test if created game with game_new are well filled by the tab
*
* @return EXIT_SUCCESS if there is no error
*/
bool test_game_new(void) { bool test_game_new(void) {
square tab[DEFAULT_SIZE * DEFAULT_SIZE]; square tab[DEFAULT_SIZE * DEFAULT_SIZE];
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR}; LIST_OF_SQUARE;
for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) {
for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) { for (uint index_tab = 0; index_tab < DEFAULT_SIZE * DEFAULT_SIZE; index_tab++) {
tab[j] = list[i]; tab[index_tab] = list[index_list];
} }
printf("%d\n", i); printf("%d\n", index_list);
game g = game_new(tab); game g = game_new(tab);
for (uint i2 = 0; i2 < DEFAULT_SIZE; i2++) { for (uint i = 0; i < DEFAULT_SIZE; i++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) { for (uint j = 0; j < DEFAULT_SIZE; j++) {
printf("list :%d, get square :%d\n", list[i], game_get_square(g, i2, j)); printf("list :%d, get square :%d\n", list[index_list], game_get_square(g, i, j));
assert(list[i] == game_get_square(g, i2, j)); assert(list[index_list] == game_get_square(g, i, j));
} }
} }
assert(g); assert(g);
@@ -139,19 +159,23 @@ bool test_game_new(void) {
} }
/* ******** game_print ******** */ /* ******** game_print ******** */
/**
* @brief test if there is no major problems by printing every square of list
*
* @return EXIT_SUCCESS if there is no error
*/
bool test_game_print(void) { bool test_game_print(void) {
for (int h = 1; h <= 10; h++) { for (int height = 1; height <= SIZE_LIMIT_GAME; height++) {
for (int w = 1; w <= 10; w++) { for (int width = 1; width <= SIZE_LIMIT_GAME; width++) {
square tab[w * h]; square tab[width * height];
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU}; LIST_OF_SQUARE;
game g; game g;
for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) {
for (uint j = 0; j < w * h; j++) { for (uint index_tab = 0; index_tab < width * height; index_tab++) {
tab[j] = list[i]; tab[index_tab] = list[index_list];
} }
printf("%d\n", i); printf("%d\n", list[index_list]);
g = game_new_ext(h, w, tab, false); g = game_new_ext(height, width, tab, false);
assert(g); assert(g);
game_print(g); game_print(g);
game_delete(g); game_delete(g);
@@ -162,18 +186,23 @@ bool test_game_print(void) {
} }
/* ******* game_get_square ******* */ /* ******* game_get_square ******* */
/**
* @brief test if get_square return the same as tab, used to create the game
*
* @return EXIT_SUCCESS if there is no error
*/
bool test_game_get_square(void) { bool test_game_get_square(void) {
for (int h = 1; h <= 10; h++) { for (int height = 1; height <= SIZE_LIMIT_GAME; height++) {
for (int w = 1; w <= 10; w++) { for (int width = 1; width <= SIZE_LIMIT_GAME; width++) {
square tab[w * h]; square tab[width * height];
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR}; LIST_OF_SQUARE;
for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) {
for (uint j = 0; j < h * w; j++) { for (uint index_tab = 0; index_tab < height * width; index_tab++) {
tab[j] = list[i]; tab[index_tab] = list[index_list];
game g = game_new_ext(h, w, tab, false); game g = game_new_ext(height, width, tab, false);
printf("[%d, %d] %d %d\n", j / game_nb_cols(g), j % game_nb_cols(g), game_get_square(g, j / game_nb_cols(g), j % game_nb_cols(g)), tab[j]); printf("[%d, %d] %d %d\n", index_tab / game_nb_cols(g), index_tab % game_nb_cols(g),
assert(game_get_square(g, j / game_nb_cols(g), j % game_nb_cols(g)) == tab[j]); game_get_square(g, index_tab / game_nb_cols(g), index_tab % game_nb_cols(g)), tab[index_tab]);
assert(game_get_square(g, index_tab / game_nb_cols(g), index_tab % game_nb_cols(g)) == tab[index_tab]);
game_delete(g); game_delete(g);
} }
} }
@@ -183,10 +212,14 @@ bool test_game_get_square(void) {
} }
/* ******* game_default ******* */ /* ******* game_default ******* */
/**
* @brief test if the game_default is the same as tab (tab is game_default)
*
* @return EXIT_SUCCESS if there is no error
*/
bool test_game_default(void) { bool test_game_default(void) {
game g = game_default(); game game_def = game_default();
assert(g); assert(game_def);
// clang-format off // clang-format off
square tab[49] = square tab[49] =
{ {
@@ -200,34 +233,38 @@ bool test_game_default(void) {
/*Y 6*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLANK /*Y 6*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLANK
}; };
// clang-format on // clang-format on
game g1 = game_new(tab); game game_test = game_new(tab);
assert(game_equal(g, g1)); assert(game_equal(game_def, game_test));
game_delete(g); game_delete(game_def);
game_delete(g1); game_delete(game_test);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* *** game_default_solution *** */ /* *** game_default_solution *** */
/**
* @brief test if game_default_solution is the same as game_default with moves needed to win
*
* @return EXIT_SUCCESS if there is no error
*/
bool test_game_default_solution(void) { bool test_game_default_solution(void) {
game g = game_default_solution(); game game_def_solution = game_default_solution();
game g1 = game_default(); game game_def = game_default();
assert(g); assert(game_def_solution);
// solution // solution
game_set_square(g1, 0, 0, S_LIGHTBULB); game_set_square(game_def, 0, 0, S_LIGHTBULB);
game_set_square(g1, 1, 1, S_LIGHTBULB); game_set_square(game_def, 1, 1, S_LIGHTBULB);
game_set_square(g1, 0, 3, S_LIGHTBULB); game_set_square(game_def, 0, 3, S_LIGHTBULB);
game_set_square(g1, 1, 6, S_LIGHTBULB); game_set_square(game_def, 1, 6, S_LIGHTBULB);
game_set_square(g1, 2, 2, S_LIGHTBULB); game_set_square(game_def, 2, 2, S_LIGHTBULB);
game_set_square(g1, 3, 6, S_LIGHTBULB); game_set_square(game_def, 3, 6, S_LIGHTBULB);
game_set_square(g1, 4, 4, S_LIGHTBULB); game_set_square(game_def, 4, 4, S_LIGHTBULB);
game_set_square(g1, 5, 0, S_LIGHTBULB); game_set_square(game_def, 5, 0, S_LIGHTBULB);
game_set_square(g1, 5, 5, S_LIGHTBULB); game_set_square(game_def, 5, 5, S_LIGHTBULB);
game_set_square(g1, 6, 1, S_LIGHTBULB); game_set_square(game_def, 6, 1, S_LIGHTBULB);
game_update_flags(g1); game_update_flags(game_def);
assert(game_equal(g, g1)); assert(game_equal(game_def_solution, game_def));
game_delete(g); game_delete(game_def_solution);
game_delete(g1); game_delete(game_def);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@@ -290,20 +327,21 @@ On the 2x2, 3x3 and 5x3 tests, we play these move to win and we test if the grid
bool test_game_update_flags(void) { bool test_game_update_flags(void) {
square test2x2w[4] = {S_BLACK4, S_BLANK, S_BLANK, S_BLANK}; square test2x2w[4] = {S_BLACK4, S_BLANK, S_BLANK, S_BLANK};
square test3x3w[9] = {S_BLANK, S_BLACKU, S_BLACK2, S_BLANK, S_BLACKU, S_BLACKU, S_BLANK, S_BLANK, S_BLANK}; square test3x3w[9] = {S_BLANK, S_BLACKU, S_BLACK2, S_BLANK, S_BLACKU, S_BLACKU, S_BLANK, S_BLANK, S_BLANK};
square test5x3[15] = {S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLACK1, S_BLANK, S_BLACK2,
S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK};
square test2x2[4] = {S_BLACK2, S_BLANK, S_BLANK, S_BLANK}; square test2x2[4] = {S_BLACK2, S_BLANK, S_BLANK, S_BLANK};
square test3x3[9] = {S_BLANK, S_BLACKU, S_BLACK0, S_BLANK, S_BLACK1, S_BLACKU, S_BLANK, S_BLANK, S_BLANK}; square test3x3[9] = {S_BLANK, S_BLACKU, S_BLACK0, S_BLANK, S_BLACK1, S_BLACKU, S_BLANK, S_BLANK, S_BLANK};
// avec wrapping square test5x3[15] = {S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLACK1, S_BLANK, S_BLACK2,
S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK};
// with wrapping
game g2x2w = game_new_ext(2, 2, test2x2w, true); game g2x2w = game_new_ext(2, 2, test2x2w, true);
game g3x3w = game_new_ext(3, 3, test3x3w, true);
game g5x3w = game_new_ext(5, 3, test5x3, true);
game_play_move(g2x2w, 0, 1, S_LIGHTBULB); game_play_move(g2x2w, 0, 1, S_LIGHTBULB);
game_play_move(g2x2w, 1, 0, S_LIGHTBULB); game_play_move(g2x2w, 1, 0, S_LIGHTBULB);
assert(game_is_over(g2x2w)); assert(game_is_over(g2x2w));
game g3x3w = game_new_ext(3, 3, test3x3w, true);
game_play_move(g3x3w, 0, 0, S_LIGHTBULB); game_play_move(g3x3w, 0, 0, S_LIGHTBULB);
game_play_move(g3x3w, 2, 2, S_LIGHTBULB); game_play_move(g3x3w, 2, 2, S_LIGHTBULB);
assert(game_is_over(g3x3w)); assert(game_is_over(g3x3w));
game_delete(g3x3w);
game g5x3w = game_new_ext(5, 3, test5x3, true);
game_play_move(g5x3w, 1, 1, S_LIGHTBULB); game_play_move(g5x3w, 1, 1, S_LIGHTBULB);
game_play_move(g5x3w, 2, 0, S_LIGHTBULB); game_play_move(g5x3w, 2, 0, S_LIGHTBULB);
game_play_move(g5x3w, 3, 2, S_LIGHTBULB); game_play_move(g5x3w, 3, 2, S_LIGHTBULB);
@@ -314,6 +352,7 @@ bool test_game_update_flags(void) {
assert(!game_is_over(g2x2w)); assert(!game_is_over(g2x2w));
assert(game_has_error(g2x2w, 0, 0)); assert(game_has_error(g2x2w, 0, 0));
assert(counterF_ERROR(g2x2w) == 1); assert(counterF_ERROR(g2x2w) == 1);
game_delete(g2x2w);
game_play_move(g5x3w, 0, 2, S_LIGHTBULB); game_play_move(g5x3w, 0, 2, S_LIGHTBULB);
game_play_move(g5x3w, 2, 2, S_LIGHTBULB); game_play_move(g5x3w, 2, 2, S_LIGHTBULB);
game_play_move(g5x3w, 1, 1, S_LIGHTBULB); game_play_move(g5x3w, 1, 1, S_LIGHTBULB);
@@ -325,19 +364,18 @@ bool test_game_update_flags(void) {
assert(game_has_error(g5x3w, 2, 0)); assert(game_has_error(g5x3w, 2, 0));
assert(game_has_error(g5x3w, 2, 1)); assert(game_has_error(g5x3w, 2, 1));
assert(counterF_ERROR(g5x3w) == 5); assert(counterF_ERROR(g5x3w) == 5);
game_delete(g2x2w);
game_delete(g3x3w);
game_delete(g5x3w); game_delete(g5x3w);
// sans wrapping // without wrapping
game g2x2 = game_new_ext(2, 2, test2x2, false); game g2x2 = game_new_ext(2, 2, test2x2, false);
game g3x3 = game_new_ext(3, 3, test3x3, false);
game g5x3 = game_new_ext(5, 3, test5x3, false);
game_play_move(g2x2, 0, 1, S_LIGHTBULB); game_play_move(g2x2, 0, 1, S_LIGHTBULB);
game_play_move(g2x2, 1, 0, S_LIGHTBULB); game_play_move(g2x2, 1, 0, S_LIGHTBULB);
assert(game_is_over(g2x2)); assert(game_is_over(g2x2));
game g3x3 = game_new_ext(3, 3, test3x3, false);
game_play_move(g3x3, 1, 0, S_LIGHTBULB); game_play_move(g3x3, 1, 0, S_LIGHTBULB);
game_play_move(g3x3, 2, 2, S_LIGHTBULB); game_play_move(g3x3, 2, 2, S_LIGHTBULB);
assert(game_is_over(g3x3)); assert(game_is_over(g3x3));
game_delete(g3x3);
game g5x3 = game_new_ext(5, 3, test5x3, false);
game_play_move(g5x3, 0, 0, S_LIGHTBULB); game_play_move(g5x3, 0, 0, S_LIGHTBULB);
game_play_move(g5x3, 1, 1, S_LIGHTBULB); game_play_move(g5x3, 1, 1, S_LIGHTBULB);
game_play_move(g5x3, 2, 0, S_LIGHTBULB); game_play_move(g5x3, 2, 0, S_LIGHTBULB);
@@ -350,6 +388,7 @@ bool test_game_update_flags(void) {
assert(!game_is_over(g2x2)); assert(!game_is_over(g2x2));
assert(game_has_error(g2x2, 0, 0)); assert(game_has_error(g2x2, 0, 0));
assert(counterF_ERROR(g2x2) == 1); assert(counterF_ERROR(g2x2) == 1);
game_delete(g2x2);
game_play_move(g5x3, 0, 2, S_LIGHTBULB); game_play_move(g5x3, 0, 2, S_LIGHTBULB);
game_play_move(g5x3, 1, 1, S_LIGHTBULB); game_play_move(g5x3, 1, 1, S_LIGHTBULB);
game_play_move(g5x3, 2, 0, S_LIGHTBULB); game_play_move(g5x3, 2, 0, S_LIGHTBULB);
@@ -363,49 +402,67 @@ bool test_game_update_flags(void) {
assert(game_has_error(g5x3, 3, 2)); assert(game_has_error(g5x3, 3, 2));
assert(counterF_ERROR(g5x3) == 4); assert(counterF_ERROR(g5x3) == 4);
game_delete(g5x3); game_delete(g5x3);
game_delete(g3x3);
game_delete(g2x2);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* ****** game_play_move ****** */ /* ****** game_play_move ****** */
/**
* @brief test if play move set square + update the flags + update history
*
* @return EXIT_SUCCESS if there is no error
*/
bool test_game_play_move(void) { bool test_game_play_move(void) {
game g = game_new_empty(); game game_play = game_new_empty();
game g1 = game_new_empty(); game game_set = game_new_empty();
game_play_move(g, 0, 0, S_LIGHTBULB); // S_LIGHTBULB
assert(!game_equal(g, g1)); game_play_move(game_play, 0, 0, S_LIGHTBULB);
game_set_square(g1, 0, 0, S_LIGHTBULB); assert(!game_equal(game_play, game_set));
assert(!game_equal(g, g1)); game_set_square(game_set, 0, 0, S_LIGHTBULB);
game_update_flags(g1); assert(!game_equal(game_play, game_set));
assert(game_equal(g, g1)); game_update_flags(game_set);
game_play_move(g, 3, 0, S_MARK); assert(game_equal(game_play, game_set));
assert(!game_equal(g, g1)); // S_BLANK
game_set_square(g1, 3, 0, S_MARK); game_play_move(game_play, 0, 3, S_BLANK);
assert(!game_equal(g, g1)); assert(game_equal(game_play, game_set));
game_update_flags(g1); game_set_square(game_set, 0, 3, S_BLANK);
assert(game_equal(g, g1)); assert(!game_equal(game_play, game_set));
game_play_move(g, 0, 3, S_BLANK); game_update_flags(game_set);
assert(game_equal(g, g1)); assert(game_equal(game_play, game_set));
game_set_square(g1, 0, 3, S_BLANK); // S_MARK
assert(!game_equal(g, g1)); game_play_move(game_play, 3, 0, S_MARK);
game_update_flags(g1); assert(!game_equal(game_play, game_set));
assert(game_equal(g, g1)); game_set_square(game_set, 3, 0, S_MARK);
game_delete(g); assert(!game_equal(game_play, game_set));
game_delete(g1); game_update_flags(game_set);
assert(game_equal(game_play, game_set));
// undo / redo
game_undo(game_play);
assert(!game_equal(game_play, game_set));
game_set_square(game_set, 3, 0, S_BLANK);
assert(!game_equal(game_play, game_set));
game_update_flags(game_set);
assert(game_equal(game_play, game_set));
// delete
game_delete(game_play);
game_delete(game_set);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* ***** game_check_move ***** */ /* ***** game_check_move ***** */
/**
* @brief test if we can place usable square (here : S_BLANK, S_LIGHTBULB, S_MARK) and nothing else + if we can place something over the limits
*
* @return EXIT_SUCCESS if there is no error
*/
bool test_game_check_move(void) { bool test_game_check_move(void) {
game g = game_new_empty(); game g = game_new_empty();
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR, F_LIGHTED}; // put usable square at the start of the list
// test if we can place something else than S_BLANK, S_LIGHTBULB, S_MARK + if we can place something over the limits LIST_OF_SQUARE;
for (uint i = 0; i < 20; i++) { // test limits
for (uint j = 0; j < 20; j++) { for (uint i = 0; i < SIZE_LIMIT_GAME + 10; i++) {
for (uint j = 0; j < SIZE_LIMIT_GAME + 10; j++) {
for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) { for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) {
if (i >= game_nb_rows(g) || j >= game_nb_cols(g) || index_list > 2) if (i >= game_nb_rows(g) || j >= game_nb_cols(g) || index_list > USABLE_SQUARE)
assert(!game_check_move(g, i, j, list[index_list])); assert(!game_check_move(g, i, j, list[index_list]));
else else
assert(game_check_move(g, i, j, list[index_list])); assert(game_check_move(g, i, j, list[index_list]));
@@ -415,9 +472,9 @@ bool test_game_check_move(void) {
// test if we can place something on a wall // test if we can place something on a wall
for (uint i = 0; i < S_BLACKU - S_BLACK0; i++) { for (uint i = 0; i < S_BLACKU - S_BLACK0; i++) {
game_set_square(g, 0, 0, S_BLACK + i); game_set_square(g, 0, 0, S_BLACK + i);
assert(!game_check_move(g, 0, 0, S_BLANK)); for (uint index_list = 0; index_list < USABLE_SQUARE; index_list++) {
assert(!game_check_move(g, 0, 0, S_MARK)); assert(!game_check_move(g, 0, 0, list[index_list]));
assert(!game_check_move(g, 0, 0, S_LIGHTBULB)); }
} }
game_delete(g); game_delete(g);
return EXIT_SUCCESS; return EXIT_SUCCESS;