started ex3 TD5

This commit is contained in:
Theophyl Hoguet committed 2021-11-08 17:59:35 +01:00
1 parent d56c4722ce
commit 1e6908b3c0
2 files changed
+115

No files matched your search

+6
View File
@@ -16,5 +16,11 @@ add_executable(game_test_thoguet game_test_thoguet.c)
#les dépendances sont calculées automatiquement #les dépendances sont calculées automatiquement
target_link_libraries(game_text game) target_link_libraries(game_text game)
target_link_libraries(game_test_thoguet game)
add_library (game game.o game_aux.c) add_library (game game.o game_aux.c)
add_test(test_thoguet_dummy ./game_test_thoguet dummy) add_test(test_thoguet_dummy ./game_test_thoguet dummy)
add_test(test_thoguet_new ./game_test_thoguet game_new)
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_default ./game_test_thoguet game_default)
add_test(test_thoguet_game_default_solution ./game_test_thoguet game_default_solution)
+109
View File
@@ -2,6 +2,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include "game.h"
#include "game_aux.h"
/* ********** DUMMY ********** */ /* ********** DUMMY ********** */
@@ -9,6 +12,102 @@ bool test_dummy(void){
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/* ********* game_new ********* */
bool test_game_new(void){
square tab[DEFAULT_SIZE*DEFAULT_SIZE];
game g;
for (int i = 0; i <= 128; i ++){
g = NULL;
for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){
tab[j] = i;
}
printf("%d\n",i);
g = game_new(tab);
assert(g);
}
return EXIT_SUCCESS;
}
/* ******** game_print ******** */
// est ce qu'il faut faire avec un tab invalide ?
bool test_game_print(void){
game_print(NULL);
square tab[DEFAULT_SIZE*DEFAULT_SIZE];
for (int i = 0; i <= 128; i ++){
for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){
tab[j] = i;
}
printf("%d\n",i);
game_print(game_new(tab));
}
return EXIT_SUCCESS;
}
/* ******* game_get_square ******* */
bool test_game_get_square(void){
game g = game_new_empty();
square tab[DEFAULT_SIZE*DEFAULT_SIZE];
for (int i = 0; i <= 128; i ++){
for (int j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){
tab[j] = i;
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]);
assert(game_get_square(g,j/(DEFAULT_SIZE),j-(j/(DEFAULT_SIZE))-(j/(DEFAULT_SIZE)*(DEFAULT_SIZE-1))) == tab[j]);
}
}
return EXIT_SUCCESS;
}
/* ******* game_default ******* */
bool test_game_default(void){
game g = game_default();
//a verif aps sur
assert(g);
assert(game_get_square(g,0,2) == S_BLACK1);
assert(game_get_square(g,1,2) == S_BLACK2);
assert(game_get_square(g,2,5) == S_BLACKU);
assert(game_get_square(g,2,6) == S_BLACK2);
assert(game_get_square(g,4,0) == S_BLACK1);
assert(game_get_square(g,4,1) == S_BLACKU);
assert(game_get_square(g,5,4) == S_BLACK2);
assert(game_get_square(g,6,4) == S_BLACKU);
return EXIT_SUCCESS;
}
/* *** game_default_solution *** */
bool test_game_default_solution(void){
game g = game_default_solution();
//a verif aps sur
assert(g);
//default
assert(game_get_square(g,0,2) == S_BLACK1);
assert(game_get_square(g,1,2) == S_BLACK2);
assert(game_get_square(g,2,5) == S_BLACKU);
assert(game_get_square(g,2,6) == S_BLACK2);
assert(game_get_square(g,4,0) == S_BLACK1);
assert(game_get_square(g,4,1) == S_BLACKU);
assert(game_get_square(g,5,4) == S_BLACK2);
assert(game_get_square(g,6,4) == S_BLACKU);
//solution
assert(game_get_square(g,0,0) == (S_LIGHTBULB|F_LIGHTED));
assert(game_get_square(g,1,1) == (S_LIGHTBULB|F_LIGHTED));
assert(game_get_square(g,0,3) == (S_LIGHTBULB|F_LIGHTED));
assert(game_get_square(g,1,6) == (S_LIGHTBULB|F_LIGHTED));
assert(game_get_square(g,2,2) == (S_LIGHTBULB|F_LIGHTED));
assert(game_get_square(g,3,6) == (S_LIGHTBULB|F_LIGHTED));
assert(game_get_square(g,4,4) == (S_LIGHTBULB|F_LIGHTED));
assert(game_get_square(g,5,0) == (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));
return EXIT_SUCCESS;
}
/* ********** USAGE ********** */ /* ********** USAGE ********** */
int usage(int argc, char *argv[]) int usage(int argc, char *argv[])
@@ -27,6 +126,16 @@ int main(int argc, char * argv[]){
bool ok = false; bool ok = false;
if (strcmp("dummy", argv[1]) == 0) if (strcmp("dummy", argv[1]) == 0)
ok = test_dummy(); ok = test_dummy();
else if (strcmp("game_print", argv[1]) == 0)
ok = test_game_print();
else if (strcmp("game_default", argv[1]) == 0)
ok = test_game_default();
else if (strcmp("game_default_solution", argv[1]) == 0)
ok = test_game_default_solution();
else if (strcmp("game_new", argv[1]) == 0)
ok = test_game_new();
else if (strcmp("game_get_square", argv[1]) == 0)
ok = test_game_get_square();
else { else {
fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]); fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);