|
|
@ -105,4 +105,254 @@ void test_callCommandById_startGame(void){ |
|
|
|
|
|
|
|
// assert |
|
|
|
TEST_ASSERT_EQUAL_PTR( startGame, actualCommand ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void test_initializeBoard(void){ |
|
|
|
// arrange |
|
|
|
bool expectedBoard[BORAD_SIZE][BORAD_SIZE]={ |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0} |
|
|
|
}; |
|
|
|
|
|
|
|
// act |
|
|
|
bool actualBoard[BORAD_SIZE][BORAD_SIZE]; |
|
|
|
initializeBoard(actualBoard); |
|
|
|
|
|
|
|
// assert |
|
|
|
for (size_t i = 0; i < BORAD_SIZE; i++) { |
|
|
|
for (size_t ii = 0; ii < BORAD_SIZE; ii++) { |
|
|
|
TEST_ASSERT_EQUAL_INT(expectedBoard[i][ii], actualBoard[i][ii]); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void test_handleGameInput(void){ |
|
|
|
// arrange |
|
|
|
char* teststring = "set 3,4"; |
|
|
|
int expectedCommand = 1; |
|
|
|
|
|
|
|
// act |
|
|
|
int actualState = handleGameInput( teststring ); |
|
|
|
|
|
|
|
// assert |
|
|
|
TEST_ASSERT_EQUAL_INT( expectedCommand, actualState ); |
|
|
|
} |
|
|
|
|
|
|
|
void test_getMarkerParameters(void){ |
|
|
|
// arrange |
|
|
|
char* teststring = "set 3,3"; |
|
|
|
int expectedParams[2] = {2, 2}; |
|
|
|
|
|
|
|
// act |
|
|
|
int* actualParams = getMarkerParameters( teststring ); |
|
|
|
|
|
|
|
// assert |
|
|
|
for( int i = 0; i < 2; i++ ){ |
|
|
|
TEST_ASSERT_EQUAL_INT( expectedParams[i], actualParams[i] ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void test_setBoardFields(){ |
|
|
|
// arrange |
|
|
|
// arrange |
|
|
|
bool board[3][3]={ |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0} |
|
|
|
}; |
|
|
|
int params[2] = {2,2}; |
|
|
|
|
|
|
|
// act |
|
|
|
setBoardMarker( board, params ); |
|
|
|
|
|
|
|
// assert |
|
|
|
TEST_ASSERT_EQUAL_INT( 1, board[2][2] ); |
|
|
|
} |
|
|
|
|
|
|
|
void test_checkOnWin_vertically(void){ |
|
|
|
// arrange |
|
|
|
bool board1[3][3]={ |
|
|
|
{0,0,1}, |
|
|
|
{0,0,1}, |
|
|
|
{0,0,1} |
|
|
|
}; |
|
|
|
|
|
|
|
bool board2[3][3]={ |
|
|
|
{0,1,0}, |
|
|
|
{0,1,0}, |
|
|
|
{0,1,0} |
|
|
|
}; |
|
|
|
|
|
|
|
bool board3[3][3]={ |
|
|
|
{1,0,0}, |
|
|
|
{1,0,0}, |
|
|
|
{1,0,0} |
|
|
|
}; |
|
|
|
|
|
|
|
// act |
|
|
|
bool result = playerHasWon( board1 ); |
|
|
|
bool result2 = playerHasWon( board2 ); |
|
|
|
bool result3 = playerHasWon( board3 ); |
|
|
|
|
|
|
|
// assert |
|
|
|
TEST_ASSERT_EQUAL_INT( 1, result ); |
|
|
|
TEST_ASSERT_EQUAL_INT( 1, result2 ); |
|
|
|
TEST_ASSERT_EQUAL_INT( 1, result3 ); |
|
|
|
} |
|
|
|
|
|
|
|
void test_negativ_checkOnWin_horizontally(void){ |
|
|
|
// arrange |
|
|
|
bool board1[3][3]={ |
|
|
|
{1,0,0}, |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0} |
|
|
|
}; |
|
|
|
|
|
|
|
bool board2[3][3]={ |
|
|
|
{0,0,0}, |
|
|
|
{0,1,0}, |
|
|
|
{0,0,0} |
|
|
|
}; |
|
|
|
|
|
|
|
bool board3[3][3]={ |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0}, |
|
|
|
{0,0,1} |
|
|
|
}; |
|
|
|
|
|
|
|
// act |
|
|
|
bool result = playerHasWon( board1 ); |
|
|
|
bool result2 = playerHasWon( board2 ); |
|
|
|
bool result3 = playerHasWon( board3 ); |
|
|
|
|
|
|
|
// assert |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result ); |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result2 ); |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result3 ); |
|
|
|
} |
|
|
|
|
|
|
|
void test_negativ_checkOnWin_horizontally2(void){ |
|
|
|
// arrange |
|
|
|
bool board1[3][3]={ |
|
|
|
{1,1,0}, |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0} |
|
|
|
}; |
|
|
|
|
|
|
|
bool board2[3][3]={ |
|
|
|
{0,0,0}, |
|
|
|
{0,1,1}, |
|
|
|
{0,0,0} |
|
|
|
}; |
|
|
|
|
|
|
|
bool board3[3][3]={ |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0}, |
|
|
|
{1,0,1} |
|
|
|
}; |
|
|
|
|
|
|
|
// act |
|
|
|
bool result = playerHasWon( board1 ); |
|
|
|
bool result2 = playerHasWon( board2 ); |
|
|
|
bool result3 = playerHasWon( board3 ); |
|
|
|
|
|
|
|
// assert |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result ); |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result2 ); |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result3 ); |
|
|
|
} |
|
|
|
|
|
|
|
void test_negativ_checkOnWin_vertically(void){ |
|
|
|
// arrange |
|
|
|
bool board1[3][3]={ |
|
|
|
{1,0,0}, |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0} |
|
|
|
}; |
|
|
|
|
|
|
|
bool board2[3][3]={ |
|
|
|
{0,0,0}, |
|
|
|
{1,0,0}, |
|
|
|
{0,0,0} |
|
|
|
}; |
|
|
|
|
|
|
|
bool board3[3][3]={ |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0}, |
|
|
|
{1,0,0} |
|
|
|
}; |
|
|
|
|
|
|
|
// act |
|
|
|
bool result = playerHasWon( board1 ); |
|
|
|
bool result2 = playerHasWon( board2 ); |
|
|
|
bool result3 = playerHasWon( board3 ); |
|
|
|
|
|
|
|
// assert |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result ); |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result2 ); |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result3 ); |
|
|
|
} |
|
|
|
|
|
|
|
void test_negativ_checkOnWin_vertically2(void){ |
|
|
|
// arrange |
|
|
|
bool board1[3][3]={ |
|
|
|
{0,1,0}, |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0} |
|
|
|
}; |
|
|
|
|
|
|
|
bool board2[3][3]={ |
|
|
|
{0,0,0}, |
|
|
|
{0,1,0}, |
|
|
|
{0,0,0} |
|
|
|
}; |
|
|
|
|
|
|
|
bool board3[3][3]={ |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0}, |
|
|
|
{0,1,0} |
|
|
|
}; |
|
|
|
|
|
|
|
// act |
|
|
|
bool result = playerHasWon( board1 ); |
|
|
|
bool result2 = playerHasWon( board2 ); |
|
|
|
bool result3 = playerHasWon( board3 ); |
|
|
|
|
|
|
|
// assert |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result ); |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result2 ); |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result3 ); |
|
|
|
} |
|
|
|
|
|
|
|
void test_negativ_checkOnWin_vertically3(void){ |
|
|
|
// arrange |
|
|
|
bool board1[3][3]={ |
|
|
|
{0,0,1}, |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0} |
|
|
|
}; |
|
|
|
|
|
|
|
bool board2[3][3]={ |
|
|
|
{0,0,0}, |
|
|
|
{0,0,1}, |
|
|
|
{0,0,0} |
|
|
|
}; |
|
|
|
|
|
|
|
bool board3[3][3]={ |
|
|
|
{0,0,0}, |
|
|
|
{0,0,0}, |
|
|
|
{0,0,1} |
|
|
|
}; |
|
|
|
|
|
|
|
// act |
|
|
|
bool result = playerHasWon( board1 ); |
|
|
|
bool result2 = playerHasWon( board2 ); |
|
|
|
bool result3 = playerHasWon( board3 ); |
|
|
|
|
|
|
|
// assert |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result ); |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result2 ); |
|
|
|
TEST_ASSERT_EQUAL_INT( 0, result3 ); |
|
|
|
} |