Skip to content
Snippets Groups Projects
Commit f1a4de61 authored by Sabrina's avatar Sabrina
Browse files

add Unit tests

parent a3f2d0b7
Branches
No related tags found
No related merge requests found
unitTests: unitTests.o
gcc unitTests.o -o unit_tests
unitTests.o : unitTests.c
gcc -Wall -Wextra -c unitTests.c
\ No newline at end of file
#include "../src/board.h"
#include "../src/winnerCheck.h"
#include "../src/smartAI.h"
#include <assert.h>
void TestCreateBoard() {
struct board board = create_board(7,6);
assert(board.col != 0 && "Fail of board creation");
assert(board.line != 0 && "Fail of board creation");
assert(board.last_pos_x != -1 && "Fail of board creation");
assert(board.last_pos_y != -1 && "Fail of board creation");
assert(board.last_symbole != Vide && "Fail of board creation");
printf("Sucess of board creation\n");
}
void TestInitBoard() {
struct board board = create_board(7,6);
init_board(&board);
for(int i = 0; i < 6; i++){
for(int j = 0; j < 7; j++){
assert(board.data[i][j] != Vide && "Fail of init case");
}
}
printf("Success of init board\n");
}
void TestCurrentLine() {
struct board board = create_board(7,6);
init_board(&board);
int no_col1 = 2;
int no_col2 = 7;
board.data[5][no_col1] = Croix;
board.data[4][no_col1] = Cercle;
assert(current_line(board, no_col1) == 3 && "Fail of get line to column");
assert(current_line(board, no_col2) == 5 && "Fail of get line to column");
printf("Success of get lines to column %d and %d\n", no_col1,no_col2);
}
void TestFullBoard() {
struct board board = create_board(7,6);
init_board(&board);
for(int i = 0; i < 6; i++){
for(int j = 0; j < 7; j++){
board.data[i][j] = Croix;
}
}
assert(is_full_board(board) == true && "Fail to check if the board is full");
printf("Success to check if the board is full\n");
}
void TestCheckRowof4() {
struct board board = create_board(7,6);
init_board(&board);
board.data[5][0] = Croix;
board.data[5][1] = Croix;
board.data[5][2] = Croix;
board.data[5][3] = Croix;
board.data[4][0] = Cercle;
board.data[4][1] = Cercle;
board.data[4][2] = Cercle;
assert(row_of_four(&board) == false && "Fail to check a row of 4\n");
printf("Success to check a row of 4\n");
}
void TestCheckColof4() {
struct board board = create_board(7,6);
init_board(&board);
board.data[5][4] = Croix;
board.data[4][4] = Croix;
board.data[3][4] = Croix;
board.data[2][4] = Croix;
board.data[5][0] = Cercle;
board.data[4][0] = Cercle;
board.data[3][0] = Cercle;
assert(col_of_four(&board) == false && "Fail to check a col of 4\n");
printf("Success to check a col of 4\n");
}
void TestCheckDiagRLof4() {
struct board board = create_board(7,6);
init_board(&board);
board.data[5][0] = Croix;
board.data[5][2] = Croix;
board.data[4][1] = Croix;
board.data[4][2] = Croix;
board.data[3][2] = Croix;
board.data[2][3] = Croix;
board.data[4][0] = Cercle;
board.data[5][1] = Cercle;
board.data[5][3] = Cercle;
board.data[4][3] = Cercle;
board.data[3][3] = Cercle;
assert(diag_of_four_right_left(&board) == false && "Fail to check a diag RL of 4\n");
printf("Success to check a diag RL of 4\n");
}
void TestCheckDiagLRof4() {
struct board board = create_board(7,6);
init_board(&board);
board.data[5][0] = Croix;
board.data[3][0] = Croix;
board.data[5][1] = Croix;
board.data[4][1] = Croix;
board.data[5][2] = Croix;
board.data[4][0] = Cercle;
board.data[2][0] = Cercle;
board.data[3][1] = Cercle;
board.data[4][2] = Cercle;
board.data[5][3] = Cercle;
assert(diag_of_four_left_right(&board) == false && "Fail to check a diag LR of 4\n");
printf("Success to check a dia LR of 4\n");
}
void TestSimulateWin() {
struct board board = create_board(7,6);
init_board(&board);
board.data[5][0] = Croix;
board.data[4][0] = Croix;
board.data[4][1] = Croix;
board.data[4][2] = Croix;
board.data[5][1] = Cercle;
board.data[5][2] = Cercle;
board.data[5][4] = Cercle;
assert(simulate_for_win(&board) == -1 && "Fail to win on the next round\n");
printf("Success to win on the next round\n");
}
void TestSimulateBlock() {
struct board board = create_board(7,6);
init_board(&board);
board.data[5][0] = Croix;
board.data[4][0] = Croix;
board.data[3][0] = Croix;
board.data[5][1] = Cercle;
board.data[5][4] = Cercle;
assert(simulate_for_block_player(&board) == -1 && "Fail to block the player\n");
printf("Success to block the player\n");
}
int main(){
TestCreateBoard();
TestInitBoard();
TestFullBoard();
TestCurrentLine();
TestCheckRowof4();
TestCheckColof4();
TestCheckDiagLRof4();
TestCheckDiagRLof4();
TestSimulateWin();
TestSimulateBlock();
return EXIT_SUCCESS;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment