edit game_is_black + game_get_black_number

This commit is contained in:
Thibault Perrier committed 2022-01-19 11:31:00 +01:00
1 parent 2d76a0fb32
commit c66ad4e22c
1 file changed
+32 -87
+32 -87
View File
@@ -15,31 +15,19 @@ bool test_dummy() {
/* ********** game_get_black_number ********** */ /* ********** game_get_black_number ********** */
bool test_game_get_black_number() { bool test_game_get_black_number() {
square tab_square[] = {S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4};
game g = game_new_empty(); game g = game_new_empty();
game_set_square(g, 0, 0, S_BLACK0); for (int i = 0; i < DEFAULT_SIZE; i++) {
if (game_get_black_number(g, 0, 0) != 0) { for (int j = 0; j < DEFAULT_SIZE; j++) {
game_delete(g); // check for each case given in tab_square if the function return the expected result
return false; for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) {
} game_set_square(g, i, j, tab_square[tab_index]);
game_set_square(g, 0, 0, S_BLACK1); if (game_get_black_number(g, i, j) != tab_index) {
if (game_get_black_number(g, 0, 0) != 1) { game_delete(g);
game_delete(g); return false;
return false; }
} }
game_set_square(g, 0, 0, S_BLACK2); }
if (game_get_black_number(g, 0, 0) != 2) {
game_delete(g);
return false;
}
game_set_square(g, 0, 0, S_BLACK3);
if (game_get_black_number(g, 0, 0) != 3) {
game_delete(g);
return false;
}
game_set_square(g, 0, 0, S_BLACK4);
if (game_get_black_number(g, 0, 0) != 4) {
game_delete(g);
return false;
} }
game_delete(g); game_delete(g);
return true; return true;
@@ -47,71 +35,28 @@ bool test_game_get_black_number() {
/* ********** game_is_black ********** */ /* ********** game_is_black ********** */
bool test_game_is_black() { bool test_game_is_black() {
square tab_square[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU};
game g = game_new_empty(); game g = game_new_empty();
if (game_is_black(g, 0, 0)) { for (int i = 0; i < DEFAULT_SIZE; i++) {
game_delete(g); for (int j = 0; j < DEFAULT_SIZE; j++) {
return false; // check for each case given in tab_square if the function return the expected result
} for (int tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) {
game_set_square(g, 0, 0, S_BLACKU); game_set_square(g, i, j, tab_square[tab_index]);
if (!((game_get_square(g, 0, 0) == S_BLACKU) && game_is_black(g, 0, 0))) { if (tab_square[tab_index] <= S_MARK) {
game_delete(g); if (game_is_black(g, i, j)) {
return false; game_delete(g);
} return false;
game_set_square(g, 0, 0, S_BLACK0); }
if (!((game_get_square(g, 0, 0) == S_BLACK0) && game_is_black(g, 0, 0))) { } else {
game_delete(g); if (!((game_get_square(g, i, j) == tab_square[tab_index]) && game_is_black(g, i, j))) {
return false; game_delete(g);
} return false;
game_set_square(g, 0, 0, S_BLACK1); }
if (!((game_get_square(g, 0, 0) == S_BLACK1) && game_is_black(g, 0, 0))) { }
game_delete(g); }
return false; }
}
game_set_square(g, 0, 0, S_BLACK2);
if (!((game_get_square(g, 0, 0) == S_BLACK2) && game_is_black(g, 0, 0))) {
game_delete(g);
return false;
}
game_set_square(g, 0, 0, S_BLACK3);
if (!((game_get_square(g, 0, 0) == S_BLACK3) && game_is_black(g, 0, 0))) {
game_delete(g);
return false;
}
game_set_square(g, 0, 0, S_BLACK4);
if (!((game_get_square(g, 0, 0) == S_BLACK4) && game_is_black(g, 0, 0))) {
game_delete(g);
return false;
}
game_set_square(g, 0, 0, S_MARK);
if ((game_get_square(g, 0, 0) == S_MARK) && game_is_black(g, 0, 0)) {
game_delete(g);
return false;
}
game_set_square(g, 0, 0, S_MARK);
if ((game_get_square(g, 0, 0) == S_MARK) && game_is_black(g, 0, 0)) {
game_delete(g);
return false;
}
game_set_square(g, 0, 0, S_LIGHTBULB);
if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_black(g, 0, 0)) {
game_delete(g);
return false;
}
game_set_square(g, 0, 0, S_LIGHTBULB);
if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_black(g, 0, 0)) {
game_delete(g);
return false;
}
game_set_square(g, 0, 0, F_ERROR);
if ((game_get_square(g, 0, 0) == F_ERROR) && game_is_black(g, 0, 0)) {
game_delete(g);
return false;
}
game_set_square(g, 0, 0, F_LIGHTED);
if ((game_get_square(g, 0, 0) == F_LIGHTED) && game_is_black(g, 0, 0)) {
game_delete(g);
return false;
} }
game_delete(g); game_delete(g);
return true; return true;
} }