remove warning + inconsistencies (close #7)

This commit is contained in:
nessar committed 2022-02-11 16:46:47 +01:00
1 parent 822a39d3e8
commit a40d30e095
7 files changed
+48 -47

No files matched your search

+11 -11
View File
@@ -12,8 +12,8 @@
game game_new(square* squares) {
game g = game_new_empty();
for (int i = 0; i < game_nb_rows(g); i++) {
for (int j = 0; j < game_nb_cols(g); j++) {
for (uint i = 0; i < game_nb_rows(g); i++) {
for (uint j = 0; j < game_nb_cols(g); j++) {
g->tab_cell[i][j] = squares[game_nb_cols(g) * i + j];
}
}
@@ -36,12 +36,12 @@ game game_new_empty(void) {
if (g->tab_cell == NULL) {
memoryError();
}
for (int i = 0; i < game_nb_rows(g); i++) {
for (uint i = 0; i < game_nb_rows(g); i++) {
g->tab_cell[i] = (square*)malloc(sizeof(square) * game_nb_cols(g));
if (g->tab_cell[i] == NULL) {
memoryError();
}
for (int j = 0; j < game_nb_cols(g); j++) {
for (uint j = 0; j < game_nb_cols(g); j++) {
g->tab_cell[i][j] = S_BLANK;
}
}
@@ -52,8 +52,8 @@ game game_new_empty(void) {
game game_copy(cgame g1) {
game g2 = game_new_empty_ext(g1->height, g1->width, g1->wrapping);
for (int i = 0; i < g2->height; i++) {
for (int j = 0; j < g2->width; j++) {
for (uint i = 0; i < g2->height; i++) {
for (uint j = 0; j < g2->width; j++) {
g2->tab_cell[i][j] = g1->tab_cell[i][j];
}
}
@@ -68,8 +68,8 @@ bool game_equal(cgame g1, cgame g2) {
if (g1->height != g2->height || g1->width != g2->width || g1->wrapping != g2->wrapping)
return false;
// check each cell and seek any difference between g1 and g2
for (int i = 0; i < g1->height; i++) {
for (int j = 0; j < g1->width; j++) {
for (uint i = 0; i < g1->height; i++) {
for (uint j = 0; j < g1->width; j++) {
if (g1->tab_cell[i][j] != g2->tab_cell[i][j]) {
return false;
}
@@ -80,7 +80,7 @@ bool game_equal(cgame g1, cgame g2) {
void game_delete(game g) {
// free each tab of tab_cell
for (int i = 0; i < game_nb_rows(g); i++) {
for (uint i = 0; i < game_nb_rows(g); i++) {
free(g->tab_cell[i]);
g->tab_cell[i] = NULL;
}
@@ -203,7 +203,7 @@ void update_flags_lightbulb(game g, uint i, uint j) {
for (uint index_tab = 0; index_tab < sizeof(tab) / sizeof(tab[0]); index_tab += 2) {
// big if to check if INORMAL and JNORMAL are correct or if wrapping is true and IWRAPPING and JWRAPPING are not the initial case
if (/* test if both tab are not 0*/ tab[index_tab] != tab[index_tab + 1] &&
(/* normal check */ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) ||
(/* normal check */ (JNORMAL < game_nb_cols(g) && INORMAL < game_nb_rows(g)) ||
/* wrapping check + not the inital case*/ (game_is_wrapping(g) && !(IWRAPPING == i && JWRAPPING == j)))) {
if (game_is_black(g, IWRAPPING, JWRAPPING)) {
tab[index_tab] = 0;
@@ -226,7 +226,7 @@ void update_flags_walls(game g, uint i, uint j) {
int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1};
for (uint index_tab = 0; index_tab < (sizeof(tab) / sizeof(tab[0])); index_tab += 2) {
uint gap_position = 1;
if (/* normal check*/ (JNORMAL >= 0 && JNORMAL < game_nb_cols(g) && INORMAL >= 0 && INORMAL < game_nb_rows(g)) ||
if (/* normal check*/ (JNORMAL < game_nb_cols(g) && INORMAL < game_nb_rows(g)) ||
/*wrapping check*/ (game_is_wrapping(g) &&
/*not the same case*/ !(IWRAPPING == i && JWRAPPING == j))) {
if (game_is_lightbulb(g, IWRAPPING, JWRAPPING))
+3 -3
View File
@@ -5,8 +5,8 @@
game game_new_ext(uint nb_rows, uint nb_cols, square* squares, bool wrapping) {
game g = game_new_empty_ext(nb_rows, nb_cols, wrapping);
for (int i = 0; i < game_nb_rows(g); i++) {
for (int j = 0; j < game_nb_cols(g); j++) {
for (uint i = 0; i < game_nb_rows(g); i++) {
for (uint j = 0; j < game_nb_cols(g); j++) {
g->tab_cell[i][j] = squares[game_nb_cols(g) * i + j];
}
}
@@ -33,7 +33,7 @@ game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) {
exit(EXIT_FAILURE);
}
// alloc each tab of tab_cell
for (int i = 0; i < game_nb_rows(g); i++) {
for (uint i = 0; i < game_nb_rows(g); i++) {
g->tab_cell[i] = (square*)calloc(game_nb_cols(g), sizeof(square));
if (g->tab_cell[i] == NULL) {
fprintf(stderr, "not enough memory\n");
+2 -2
View File
@@ -12,7 +12,7 @@ bool test_dummy(void) {
return true;
}
void usage(int argc, char* argv[]) {
void usage(char* argv[]) {
fprintf(stderr, "Usage: %s <testname> [<...>]\n", argv[0]);
exit(EXIT_FAILURE);
}
@@ -181,7 +181,7 @@ bool test_game_is_wrapping(void) {
int main(int argc, char* argv[]) {
if (argc != 2) {
usage(argc, argv);
usage(argv);
}
fprintf(stderr, "=> Start test \"%s\"\n", argv[1]);
bool success = false;
+6 -6
View File
@@ -197,8 +197,8 @@ bool test_game_print(bool whoami, char** name) {
*name = (char*)__func__;
return false;
}
for (int height = 1; height <= SIZE_LIMIT_GAME; height++) {
for (int width = 1; width <= SIZE_LIMIT_GAME; width++) {
for (uint height = 1; height <= SIZE_LIMIT_GAME; height++) {
for (uint width = 1; width <= SIZE_LIMIT_GAME; width++) {
square tab[width * height];
square list[] = LIST_OF_SQUARE;
game g;
@@ -228,8 +228,8 @@ bool test_game_get_square(bool whoami, char** name) {
*name = (char*)__func__;
return false;
}
for (int height = 1; height <= SIZE_LIMIT_GAME; height++) {
for (int width = 1; width <= SIZE_LIMIT_GAME; width++) {
for (uint height = 1; height <= SIZE_LIMIT_GAME; height++) {
for (uint width = 1; width <= SIZE_LIMIT_GAME; width++) {
square tab[width * height];
square list[] = LIST_OF_SQUARE;
for (uint index_list = 0; index_list < sizeof(list) / sizeof(list[0]); index_list++) {
@@ -586,7 +586,7 @@ bool test_game_save(bool whoami, char** name) {
/* ********** USAGE ********** */
int usage(int argc, char* argv[]) {
int usage(char* argv[]) {
fprintf(stderr, "Usage: %s <testname> [<...>]\n", argv[0]);
exit(EXIT_FAILURE);
}
@@ -609,7 +609,7 @@ int main(int argc, char* argv[]) {
tab_fct_name[index_tab_fct] = tab_fct_name[index_tab_fct] + 5; // remove the test_ from the functions's name
}
if (argc != 2) {
usage(argc, argv);
usage(argv);
}
fprintf(stderr, "=> Start test \"%s\"\n", argv[1]);
bool test_success = true;
+19 -19
View File
@@ -19,17 +19,17 @@ bool test_dummy() {
bool test_game_get_black_number() {
square tab_square[] = TAB_SQUARE;
game g = game_new_empty();
for (int i = 0; i < game_nb_rows(g); i++) {
for (int j = 0; j < game_nb_cols(g); j++) {
for (uint i = 0; i < game_nb_rows(g); i++) {
for (uint j = 0; j < game_nb_cols(g); j++) {
// 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++) {
for (uint tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) {
game_set_square(g, i, j, tab_square[tab_index]);
if (tab_square[tab_index] == S_BLACKU) {
if (game_get_black_number(g, i, j) != -1) {
game_delete(g);
return false;
}
} else if (tab_square[tab_index] > S_MARK && game_get_black_number(g, i, j) != tab_square[tab_index] - S_BLACK) {
} else if (tab_square[tab_index] > S_MARK && (uint)game_get_black_number(g, i, j) != tab_square[tab_index] - S_BLACK) {
game_delete(g);
return false;
}
@@ -44,10 +44,10 @@ bool test_game_get_black_number() {
bool test_game_is_black() {
square tab_square[] = TAB_SQUARE;
game g = game_new_empty();
for (int i = 0; i < game_nb_rows(g); i++) {
for (int j = 0; j < game_nb_cols(g); j++) {
for (uint i = 0; i < game_nb_rows(g); i++) {
for (uint j = 0; j < game_nb_cols(g); j++) {
// 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++) {
for (uint tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) {
game_set_square(g, i, j, tab_square[tab_index]);
if (tab_square[tab_index] <= S_MARK) {
if (game_is_black(g, i, j)) {
@@ -72,10 +72,10 @@ bool test_game_is_black() {
bool test_game_is_lightbulb() {
square tab_square[] = TAB_SQUARE;
game g = game_new_empty();
for (int i = 0; i < game_nb_rows(g); i++) {
for (int j = 0; j < game_nb_cols(g); j++) {
for (uint i = 0; i < game_nb_rows(g); i++) {
for (uint j = 0; j < game_nb_cols(g); j++) {
// 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++) {
for (uint tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) {
game_set_square(g, i, j, tab_square[tab_index]);
if (tab_square[tab_index] == S_LIGHTBULB) {
if (!game_is_lightbulb(g, i, j)) {
@@ -102,10 +102,10 @@ bool test_game_is_blank() {
game_delete(g);
return false;
}
for (int i = 0; i < game_nb_rows(g); i++) {
for (int j = 0; j < game_nb_cols(g); j++) {
for (uint i = 0; i < game_nb_rows(g); i++) {
for (uint j = 0; j < game_nb_cols(g); j++) {
// 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++) {
for (uint tab_index = 0; tab_index < (sizeof(tab_square) / sizeof(tab_square[0])); tab_index++) {
game_set_square(g, i, j, tab_square[tab_index]);
if (game_is_blank(g, i, j)) {
game_delete(g);
@@ -188,8 +188,8 @@ int test_equal(void) {
bool test_game_new_empty() {
game g = game_new_empty();
// check if each square is a S_BLANK
for (int i = 0; i < game_nb_rows(g); i++) {
for (int j = 0; j < game_nb_cols(g); j++) {
for (uint i = 0; i < game_nb_rows(g); i++) {
for (uint j = 0; j < game_nb_cols(g); j++) {
if (game_get_square(g, i, j) != S_BLANK) {
game_delete(g);
return false;
@@ -206,8 +206,8 @@ bool test_game_copy() {
uint index_tab = 0;
for (int wrap = 0; wrap < 2 /*we only need to test two versions (with and without wrapping)*/; wrap++) {
game g1 = game_new_empty_ext(DEFAULT_SIZE, DEFAULT_SIZE, wrap);
for (int i = 0; i < game_nb_rows(g1); i++) {
for (int j = 0; j < game_nb_cols(g1); j++) {
for (uint i = 0; i < game_nb_rows(g1); i++) {
for (uint j = 0; j < game_nb_cols(g1); j++) {
// check if index_tab reach end of tab
if (index_tab == sizeof(tab_square) / sizeof(tab_square[0])) {
index_tab = 0;
@@ -289,7 +289,7 @@ bool test_game_redo() {
}
/* ********** usage ********** */
void usage(int argc, char* argv[]) {
void usage(char* argv[]) {
fprintf(stderr, "Usage: %s <testname>\n", argv[0]);
exit(EXIT_FAILURE);
}
@@ -297,7 +297,7 @@ void usage(int argc, char* argv[]) {
int main(int argc, char* argv[]) {
bool success = false;
if (argc != 2) {
usage(argc, argv);
usage(argv);
} else if (strcmp("dummy", argv[1]) == 0) {
success = test_dummy();
} else if (strcmp("game_new_empty", argv[1]) == 0) {
+4 -4
View File
@@ -22,8 +22,8 @@ bool checkerrors(cgame g, char* stringError) {
uint index_taberr = 0;
// initialize stringError
stringError[0] = '\0';
for (int i = 0; i < game_nb_rows(g); i++) {
for (int j = 0; j < game_nb_cols(g); j++) {
for (uint i = 0; i < game_nb_rows(g); i++) {
for (uint j = 0; j < game_nb_cols(g); j++) {
// check each case
if (game_has_error(g, i, j)) {
// if error append stringError with coordinate of the error,
@@ -77,7 +77,7 @@ void printhelp(void) {
printf("b <i> <j> : Place une case vide ( ) à la position (<i>,<j>).\n");
}
void usage(int argc, char* argv[]) {
void usage(char* argv[]) {
printf("Usage : %s => Joue la partie par défaut\n", argv[0]);
exit(EXIT_FAILURE);
}
@@ -88,7 +88,7 @@ int main(int argc, char* argv[]) {
// Create new game
g = game_default();
else
usage(argc, argv);
usage(argv);
// init string for errors
char stringError[game_nb_rows(g) * game_nb_cols(g) * NBCHARERR];
char c;
+3 -2
View File
@@ -188,8 +188,9 @@ void history_delete_entire_history(history h) {
if (history_is_empty(h))
return;
if (history_is_empty(history_prev(h)))
return history_free(history_delete_all_after(h, h));
return history_delete_entire_history(history_prev(h));
history_free(history_delete_all_after(h, h));
else
history_delete_entire_history(history_prev(h));
}
history history_copy(history h) {