void test_moves_left(){ int i, j; assert_true(validMovesLeft(g_board)==1); for(i=0; i < cols; ++i){ for(j=0; j< rows; ++j){ assert_true(validMovesLeft(g_board)==1); makeMove(g_board, i); } } assert_true(validMovesLeft(g_board)==0); }
/* Make sure that the function returns false IFF there are no moves left */ void test_validMovesLeft() { board_type *board = createBoard(X, Y); CU_ASSERT_TRUE(validMovesLeft(board)); board->lm = X * Y + LM_INIT; CU_ASSERT_FALSE(validMovesLeft(board)); free(board); }
//helper function to simulate winning moves void winning_move(int* moves, int expected_winner){ int i = 0; while((winnerIs(g_board) == 0) && validMovesLeft(g_board)){ if(getCurrentPlayer(g_board) == PLAYER_ONE){ makeMove(g_board, moves[i]); ++i; } else { makeMove(g_board, getReasonedMove(g_board)); } } assert_int_equal(expected_winner, winnerIs(g_board)); /* * assert_true(winnerIs(g_board) == 0); makeMove(g_board, 0); //player one moves makeMove(g_board, 1); //player two moves assert_true(winnerIs(g_board) == 0); makeMove(g_board, 0); //player one moves makeMove(g_board, 2); //player two moves assert_true(winnerIs(g_board) == 0); makeMove(g_board, 0); //player one moves makeMove(g_board, 3); //player two moves assert_true(winnerIs(g_board) == 0); makeMove(g_board, 0); //player one moves makeMove(g_board, 3); //player two moves assert_int_equal(expected_winner, winnerIs(g_board)); */ }
/* Make sure that makeMove, validMovesLeft and undoMove work correctly in a * 'normal' situation. */ void test_moves_properly() { board_type *board = createBoard(X, Y); int i, j; for(i = 0; i < X; i++) { for(j = 0; j < Y; j++) { makeMove(board, i); } } CU_ASSERT_FALSE(validMovesLeft(board)); CU_ASSERT_EQUAL(board->lm, (X * Y) + LM_INIT); for(i = 0; i < X; i++) { for(j = 0; j < Y; j++) { undoMove(board); } } CU_ASSERT_EQUAL(board->lm, LM_INIT); CU_ASSERT_TRUE(validMovesLeft(board)); free(board); }