Browse Source

init_field with all x --> WAY

main^2
Joe Lukas Kalb 11 months ago
committed by Peter Wiebe
parent
commit
6e7d15b4c1
  1. 4
      src/main/c/labyrinth.c
  2. 31
      src/test/c/test_labyrinth.c

4
src/main/c/labyrinth.c

@ -48,6 +48,8 @@ void set_wall(Field_State** field, unsigned short x, unsigned short y) {
}
void init_field(Field_State** field, unsigned short len_x, unsigned short len_y){
field[0][0] = WAY;
for (int x = 0; x < len_x; x++){
field[x][0] = WAY;
}
}

31
src/test/c/test_labyrinth.c

@ -292,3 +292,34 @@ void test_init_field_at_0_0_expected_WAY(void)
}
free(field);
}
void test_init_field_at_2_0_expected_WAY(void)
{
/* arrange */
unsigned short x = 2;
unsigned short y = 0;
unsigned short len_x = 5, len_y = 5;
Field_State **field;
field = malloc(len_x * sizeof *field);
for (int c_index = 0; c_index < len_x; c_index++){
field[c_index] = malloc(len_y * sizeof field[c_index]);
}
field[x][y] = WALL;
Field_State expected = WAY;
/* act */
init_field(field, len_x, len_y);
/* assert */
TEST_ASSERT_TRUE(field[x][y] == expected);
for (int c_index = 0; c_index < len_x; c_index++)
{
free(field[c_index]);
}
free(field);
}
Loading…
Cancel
Save