From 60c3363fa13e84d1eec23d7651afa239170dfba2 Mon Sep 17 00:00:00 2001 From: Nathan Nunes Date: Tue, 16 Nov 2021 16:30:36 +0100 Subject: [PATCH] =?UTF-8?q?deuxi=C3=A8me=20=C3=A9bauche?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + README.md | 2 +- game_test_nnunes.c | 125 ++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 114 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0421e75..53cabad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,3 +47,4 @@ add_test(test_nnunes_game_get_state ./game_test_nnunes game_get_state) add_test(test_nnunes_game_get_flags ./game_test_nnunes game_get_flags) add_test(test_nnunes_game_is_marked ./game_test_nnunes game_is_marked) add_test(test_nnunes_game_is_lighted ./game_test_nnunes game_is_lighted) +add_test(test_nnunes_game_has_error ./gametest_nnunes game_has_error) diff --git a/README.md b/README.md index 8eda52f..58638d7 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Projet Techno | [game_get_black_number](./game_test_thperrier.c#L?) | [int game_get_black_number(cgame g, uint i, uint j)](./game.h#L204-214) | @thperrier | | | | [game_is_marked](./game_test_nnunes.c#L?) | [bool game_is_marked(cgame g, uint i, uint j)](./game.h#L216-226) | @nnunes | | | | [game_is_lighted](./game_test_nnunes.c#L?) | [bool game_is_lighted(cgame g, uint i, uint j)](./game.h#L228-238) | @nnunes | | | -| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | | | +| [game_has_error](./game_test_nnunes.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | | | | [game_check_move](./game_test_nnunes.c#L?) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @nnunes | | | | [game_play_move](./game_test_nnunes.c#L?) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @nnunes | | | | [game_update_flags](./game_test_thoguet.c#L144-410) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | done but not sure if it test every case | | diff --git a/game_test_nnunes.c b/game_test_nnunes.c index 4e0e2c9..b836233 100644 --- a/game_test_nnunes.c +++ b/game_test_nnunes.c @@ -69,16 +69,96 @@ bool test_game_set_square(void){ game_delete(g); return false; } - game_set_square(g, 0, 0, S_F_LIGHTED); - if (game_get_square(g, 0, 0) != F_LIGHTED){ - game_delete(g); - return false; - } - game_set_square(g, 0, 0, F_ERROR); - if (game_get_square(g, 0, 0) != F_ERROR){ + game_set_square(g, 0, 0, S_LIGHTBULB|F_ERROR); + if (game_get_square(g, 0, 0) != S_LIGHTBULB|F_ERROR){ game_delete(g); return false; } + game_set_square(g, 0, 0, S_BLANK|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLANK|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK|F_ERROR); + if (game_get_square(g, 0, 0) != S_MARK|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACK|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK0|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACK0|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK1|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACK1|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK2|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACK2|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK3|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACK3|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACK4|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACK4|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACKU|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACKU|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_LIGHTBULB|F_LIGHTED); + if (game_get_square(g, 0, 0) != S_LIGHTBULB|F_LIGHTED){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLANK|F_LIGHTED); + if (game_get_square(g, 0, 0) != S_BLANK|F_LIGHTED){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK|F_LIGHTED); + if (game_get_square(g, 0, 0) != S_MARK|F_LIGHTED){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACKU|F_LIGHTED); + if (game_get_square(g, 0, 0) != S_BLACKU|F_LIGHTED){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_LIGHTBULB|F_LIGHTED|F_ERROR); + if (game_get_square(g, 0, 0) != S_LIGHTBULB|F_LIGHTED|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLANK|F_LIGHTED|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLANK|F_LIGHTED|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_MARK|F_LIGHTED|F_ERROR); + if (game_get_square(g, 0, 0) != S_MARK|F_LIGHTED|F_ERROR){ + game_delete(g); + return false; + } + game_set_square(g, 0, 0, S_BLACKU|F_LIGHTED|F_ERROR); + if (game_get_square(g, 0, 0) != S_BLACKU|F_LIGHTED|F_ERROR){ + game_delete(g); + return false; + } game_delete(g); return true; } @@ -143,16 +223,21 @@ bool test_game_get_state(void){ /* ************** game_get_flags ************** */ bool test_game_get_flags(void){ game g = game_new_empty(); - game_set_square(g, 0, 0, S_F_LIGHTED); + game_set_square(g, 0, 0, S_BLANK|F_LIGHTED); if (game_get_flags(g, 0, 0) != F_LIGHTED){ game_delete(g); return false; } - game_set_square(g, 0, 0, F_ERROR); + game_set_square(g, 0, 0, S_BLANK|F_ERROR); if (game_get_flags(g, 0, 0) != F_ERROR){ game_delete(g); return false; } + game_set_square(g, 0, 0, S_BLANK|F_ERROR|F_LIGHTED); + if (game_get_flags(g, 0, 0) != (F_ERROR|F_LIGHTED)){ + game_delete(g); + return false; + } game_delete(g); return true; } @@ -172,7 +257,7 @@ bool test_game_is_marked(void){ /* ************** game_is_lighted ************** */ bool test_game_is_marked(void){ game g = game_new_empty(); - game_set_square(g, 0, 0, F_LIGHTED); + game_set_square(g, 0, 0, S_BLANK|F_LIGHTED); if ((game_get_square(g, 0, 0) == F_LIGHTED) && game_is_lighted(g, 0, 0)){ game_delete(g); return true; @@ -181,14 +266,28 @@ bool test_game_is_marked(void){ return false; } +/* ************** game_has_error ************** */ +bool test_game_has_error(void){ + for(int i=0; i < DEFAULT_SIZE; i++){ + for(int j=0; j < DEFAULT_SIZE; j++){ + if((game_get_flags(g, i, j) == F_ERROR)||(game_get_flags(g, i, j) == F_ERROR|F_LIGHTED) && (game_has_error(g, i, j) == false)){ + game_delete(g); + return false; + } + } + } + game_delete(g); + return true; +} + int main(int argc, char * argv[]){ if (argc != 2){ usage(argc, argv); } fprintf(stderr, "=> Start test \"%s\"\n", argv[1]); - bool ok = false; + bool success = false; if (strcmp("dummy", argv[1]) == 0) - ok = test_dummy(); + success = test_dummy(); else if (strcmp("game_get_square", argv[1]) == 0){ success = test_game_get_square(); } @@ -208,7 +307,7 @@ int main(int argc, char * argv[]){ fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); exit(EXIT_FAILURE); } - if (!ok){ + if (!success){ fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]); return EXIT_SUCCESS; }