Browse Source

refactoring : Funktionsname gekürzt,Kommentare gelöscht und hinzugefügt

remotes/origin/homan
fdai7892 11 months ago
parent
commit
6aa0f8033c
  1. 8
      src/main/duellist-spielesammlung-projekt.c
  2. 4
      src/main/duellist-spielesammlung-projekt.h
  3. 8
      src/test/test_duellist_spielesammlung_projekt.c

8
src/main/duellist-spielesammlung-projekt.c

@ -12,7 +12,7 @@ int checkAge(int age) {
return age >= MIN_AGE ? 1 : 0; return age >= MIN_AGE ? 1 : 0;
} }
// Funktion zur Initialisierung des Zufallsgenerators mit Rückgabewert
int initializeRandomGenerator() { int initializeRandomGenerator() {
srand(time(NULL)); srand(time(NULL));
return 1; // Erfolgreich initialisiert return 1; // Erfolgreich initialisiert
@ -68,11 +68,11 @@ GameResult makeMove(TicTacToeGame* game, int row, int col) {
return result; return result;
} }
Player getCurrentPlayer(const TicTacToeGame * game) {
Player CurrentPlayer(const TicTacToeGame * game) {
return game->currentPlayer; return game->currentPlayer;
} }
int getNumberOfMoves(const TicTacToeGame* game) {
int NumberOfMoves(const TicTacToeGame* game) {
int moves = 0; int moves = 0;
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) { for (int j = 0; j < 3; ++j) {
@ -83,7 +83,7 @@ int getNumberOfMoves(const TicTacToeGame* game) {
} }
return moves; return moves;
} }
// Funktioin ob das Feld voll ist oder nicht
int BoardFull(const TicTacToeGame* game) { int BoardFull(const TicTacToeGame* game) {
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) { for (int j = 0; j < 3; ++j) {

4
src/main/duellist-spielesammlung-projekt.h

@ -29,9 +29,9 @@ typedef struct {
GameResult makeMove(TicTacToeGame* game, int row, int col); GameResult makeMove(TicTacToeGame* game, int row, int col);
GameResult checkGameResult(const TicTacToeGame* game); GameResult checkGameResult(const TicTacToeGame* game);
GameResult initializeGame(TicTacToeGame* game); GameResult initializeGame(TicTacToeGame* game);
int getNumberOfMoves(const TicTacToeGame* game);
int NumberOfMoves(const TicTacToeGame* game);
int BoardFull(const TicTacToeGame* game); int BoardFull(const TicTacToeGame* game);
Player getCurrentPlayer(const TicTacToeGame* game);
Player CurrentPlayer(const TicTacToeGame* game);
int checkAge(int age); int checkAge(int age);
int initializeRandomGenerator(); int initializeRandomGenerator();
int FieldEmpty(const TicTacToeGame* game, int row, int col); int FieldEmpty(const TicTacToeGame* game, int row, int col);

8
src/test/test_duellist_spielesammlung_projekt.c

@ -146,7 +146,7 @@ void test_invalid_input_overflow_column(void) {
TEST_ASSERT_EQUAL(INVALID_MOVE, result); TEST_ASSERT_EQUAL(INVALID_MOVE, result);
} }
void test_getNumberOfMoves_returns_correct_number_of_moves(void) {
void test_NumberOfMoves_returns_correct_number_of_moves(void) {
// Arrange // Arrange
TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY},
{EMPTY, PLAYER_O, EMPTY}, {EMPTY, PLAYER_O, EMPTY},
@ -154,7 +154,7 @@ void test_getNumberOfMoves_returns_correct_number_of_moves(void) {
.currentPlayer = PLAYER_X }; .currentPlayer = PLAYER_X };
// Act // Act
int moves = getNumberOfMoves(&game);
int moves = NumberOfMoves(&game);
// Assert // Assert
TEST_ASSERT_EQUAL(2, moves); TEST_ASSERT_EQUAL(2, moves);
@ -186,7 +186,7 @@ void test_BoardFull_returns_true_when_board_is_full(void) {
// Assert // Assert
TEST_ASSERT_TRUE(boardFull); TEST_ASSERT_TRUE(boardFull);
} }
void test_getCurrentPlayer_returns_correct_player(void) {
void test_CurrentPlayer_returns_correct_player(void) {
// Arrange // Arrange
TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY}, TicTacToeGame game = { .board = {{PLAYER_X, EMPTY, EMPTY},
{EMPTY, PLAYER_O, EMPTY}, {EMPTY, PLAYER_O, EMPTY},
@ -194,7 +194,7 @@ void test_getCurrentPlayer_returns_correct_player(void) {
.currentPlayer = PLAYER_O }; .currentPlayer = PLAYER_O };
// Act // Act
Player currentPlayer = getCurrentPlayer(&game);
Player currentPlayer = CurrentPlayer(&game);
// Assert // Assert
TEST_ASSERT_EQUAL(PLAYER_O, currentPlayer); TEST_ASSERT_EQUAL(PLAYER_O, currentPlayer);

Loading…
Cancel
Save