diff --git a/UnitTests/Makefile b/UnitTests/Makefile index 69f006efe087fc2139162d3f5813401c84d48742..8087f362efd06f29e9de96e49e6491df344467a8 100644 --- a/UnitTests/Makefile +++ b/UnitTests/Makefile @@ -1,6 +1,11 @@ -unitTests: unitTests.o - gcc unitTests.o -o unit_tests +SRC = unitTests.c \ + ../src/board.c \ + ../src/winnerCheck.c \ + ../src/smartAI.c -unitTests.o : unitTests.c - gcc -Wall -Wextra -c unitTests.c \ No newline at end of file +unit_tests: $(SRC:.c=.o) + gcc $(SRC:.c=.o) -o unit_tests + +unittests.o: unitTests.c + gcc -Wall -Wextra -c unitTests -o unittests \ No newline at end of file diff --git a/UnitTests/unitTests.c b/UnitTests/unitTests.c index 0dac56e4e352e41b956b34a764aa1e249a75e144..0b8994b2514b022e0de8a9021cb151c65b679135 100644 --- a/UnitTests/unitTests.c +++ b/UnitTests/unitTests.c @@ -5,12 +5,12 @@ 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"); + assert(board.col != 0 && "Fail to board creation"); + assert(board.line != 0 && "Fail to board creation"); + assert(board.last_pos_x == -1 && "Fail to board creation"); + assert(board.last_pos_y == -1 && "Fail to board creation"); + assert(board.last_symbole == Vide && "Fail to board creation"); + printf("Sucess to board creation\n"); } void TestInitBoard() { @@ -18,28 +18,29 @@ void TestInitBoard() { 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"); + assert(board.data[i][j] == Vide && "Fail to init case"); } } - printf("Success of init board\n"); + printf("Success to init board\n"); } void TestCurrentLine() { struct board board = create_board(7,6); init_board(&board); int no_col1 = 2; - int no_col2 = 7; + int no_col2 = 6; 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); + assert(current_line(board, no_col1) == 3 && "Fail to get line to column"); + assert(current_line(board, no_col2) == 5 && "Fail to get line to column"); + printf("Success to get lines to column %d and %d\n", no_col1,no_col2); } void TestFullBoard() { struct board board = create_board(7,6); init_board(&board); + assert(is_full_board(board) == false && "Fail to check if the board is full"); for(int i = 0; i < 6; i++){ for(int j = 0; j < 7; j++){ board.data[i][j] = Croix; @@ -49,20 +50,6 @@ void TestFullBoard() { 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); @@ -73,7 +60,7 @@ void TestCheckColof4() { 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"); + assert(col_of_four(&board) == true && "Fail to check a col of 4\n"); printf("Success to check a col of 4\n"); } @@ -91,7 +78,7 @@ void TestCheckDiagRLof4() { 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"); + assert(diag_of_four_right_left(&board) == true && "Fail to check a diag RL of 4\n"); printf("Success to check a diag RL of 4\n"); } @@ -108,7 +95,7 @@ void TestCheckDiagLRof4() { 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"); + assert(diag_of_four_left_right(&board) == true && "Fail to check a diag LR of 4\n"); printf("Success to check a dia LR of 4\n"); } @@ -122,7 +109,7 @@ void TestSimulateWin() { 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"); + assert(simulate_for_win(&board) != -1 && "Fail to win on the next round\n"); printf("Success to win on the next round\n"); } @@ -135,16 +122,15 @@ void TestSimulateBlock() { 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"); + 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(); + TestFullBoard(); TestCheckColof4(); TestCheckDiagLRof4(); TestCheckDiagRLof4(); diff --git a/UnitTests/unit_tests b/UnitTests/unit_tests new file mode 100755 index 0000000000000000000000000000000000000000..dc34154bdc69eb95c020d1dde49bf94d15a0eec1 Binary files /dev/null and b/UnitTests/unit_tests differ