You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
230 lines
3.9 KiB
230 lines
3.9 KiB
#ifdef TEST
|
|
|
|
#include "unity.h"
|
|
#include "unistd.h"
|
|
#include "Modules.c"
|
|
|
|
void setUp(void)
|
|
{
|
|
}
|
|
|
|
void tearDown(void)
|
|
{
|
|
}
|
|
|
|
void test_checkBallPosition_output_if_goal(void)
|
|
{
|
|
/* arrange */
|
|
binX = 1;
|
|
binY = 1;
|
|
|
|
ballX = 1;
|
|
ballY = 3;
|
|
|
|
/* act */
|
|
int output = checkBallPosition();
|
|
|
|
/* assert */
|
|
TEST_ASSERT_EQUAL(1, output);
|
|
}
|
|
|
|
void test_checkBallPosition_output_if_no_goal(void)
|
|
{
|
|
/* arrange */
|
|
binX = 1;
|
|
binY = 1;
|
|
|
|
ballX = 1;
|
|
ballY = 1;
|
|
|
|
/* act */
|
|
int output = checkBallPosition();
|
|
|
|
/* assert */
|
|
TEST_ASSERT_EQUAL(2, output);
|
|
}
|
|
|
|
void test_sortScoreboard_check_if_file_is_created(void) {
|
|
|
|
/* arrange */
|
|
|
|
/* act */
|
|
if (access("ScoreBoard.txt", 0) == 0) {
|
|
remove("ScoreBoard.txt");
|
|
}
|
|
|
|
sortScoreboard();
|
|
|
|
int output = access("ScoreBoard.txt", 0);
|
|
|
|
/* assert */
|
|
TEST_ASSERT_EQUAL(0, output);
|
|
}
|
|
|
|
void test_clearField_check_if_Playgroung_clear(void)
|
|
{
|
|
/* arrange */
|
|
field[3][3]='T';
|
|
int output = 0;
|
|
/* act */
|
|
clearField();
|
|
for (int i = 0; i < fieldWidth; i++)
|
|
{
|
|
for (int j = 0; j < fieldHeigth; j++)
|
|
{
|
|
if(field[i][j] != ' ')
|
|
{
|
|
output=1;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* assert */
|
|
TEST_ASSERT_EQUAL(0, output);
|
|
}
|
|
|
|
void test_getStartPosition_check_given_position(void)
|
|
{
|
|
/* arrange */
|
|
int output = 0;
|
|
int width = 10;
|
|
int heigth = 10;
|
|
/* act */
|
|
buildBin(width, heigth);
|
|
|
|
if (field[width][heigth] != 'V' ||
|
|
field[width + 1][heigth + 1] != '\\' ||
|
|
field[width + 2][heigth + 2] != '\\' ||
|
|
field[width - 1][heigth + 1] != '/' ||
|
|
field[width - 2][heigth + 2] != '/' ||
|
|
field[width][heigth + 1] != ' ')
|
|
output = 1;
|
|
|
|
/* assert */
|
|
TEST_ASSERT_EQUAL(0, output);
|
|
}
|
|
|
|
void test_generateField_check_walls_length_correctly_inserted(void){
|
|
/* arrange */
|
|
int output = 0;
|
|
int wallX = 5;
|
|
int wallY = 5;
|
|
int wallLength = 3;
|
|
int counter = wallLength;
|
|
|
|
int binX = 10;
|
|
/* act */
|
|
generateField();
|
|
for (int i = 0; i < fieldWidth; i++)
|
|
{
|
|
for(int j = 0; j < fieldHeigth; j++){
|
|
if(field[i][j] == '_')
|
|
counter++;
|
|
}
|
|
}
|
|
if(counter != wallLength)
|
|
output = 1;
|
|
|
|
/* assert */
|
|
TEST_ASSERT_EQUAL(0, output);
|
|
}
|
|
|
|
void test_sortScoreboard_check_if_file_is_being_read(void) {
|
|
|
|
/* arrange */
|
|
char Text[4];
|
|
FILE *x;
|
|
int y;
|
|
|
|
/* act */
|
|
if (access("ScoreBoard.txt", 0) == 0) {
|
|
remove("ScoreBoard.txt");
|
|
}
|
|
|
|
sortScoreboard();
|
|
|
|
x = fopen("ScoreBoard.txt", "a+");
|
|
|
|
fputs("Test", x);
|
|
rewind(x);
|
|
for(int i = 0; i < 4; i++) {
|
|
fscanf(x, "%s", &Text[i]);
|
|
}
|
|
|
|
if(strcmp(Text, "Test") == 0) {
|
|
y = 0;
|
|
}
|
|
/* assert */
|
|
TEST_ASSERT_EQUAL(0, y);
|
|
}
|
|
void test_generateField_check_last_position_change_on_score(void)
|
|
{
|
|
/* arrange */
|
|
|
|
scorePoints = 321;
|
|
int output = 1;
|
|
|
|
/* act */
|
|
generateField();
|
|
|
|
if (field[12][1] != '0')
|
|
{
|
|
output = 0;
|
|
}
|
|
/* assert */
|
|
TEST_ASSERT_EQUAL(0, output);
|
|
}
|
|
|
|
void test_generateField_check_middle_position_change_on_score(void)
|
|
{
|
|
/* arrange */
|
|
|
|
scorePoints = 321;
|
|
int output = 1;
|
|
|
|
/* act */
|
|
generateField();
|
|
|
|
if (field[11][1] != '0')
|
|
{
|
|
output = 0;
|
|
}
|
|
/* assert */
|
|
TEST_ASSERT_EQUAL(0, output);
|
|
}
|
|
|
|
void test_generateField_check_first_position_change_on_score(void)
|
|
{
|
|
/* arrange */
|
|
|
|
scorePoints = 321;
|
|
int output = 1;
|
|
|
|
/* act */
|
|
generateField();
|
|
|
|
if (field[10][1] == '3')
|
|
{
|
|
output = 0;
|
|
}
|
|
/* assert */
|
|
TEST_ASSERT_EQUAL(0, output);
|
|
}
|
|
void test_generateField_check_if_first_life_away(void)
|
|
{
|
|
/* arrange */
|
|
int output = 1;
|
|
lifeCount=2;
|
|
|
|
/* act */
|
|
generateField();
|
|
|
|
if (field[3][1] == 'X')
|
|
{
|
|
output = 0;
|
|
}
|
|
/* assert */
|
|
TEST_ASSERT_EQUAL(0, output);
|
|
}
|
|
|
|
#endif // TEST
|