Browse Source

set_wall at any x y

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

2
src/main/c/labyrinth.c

@ -44,6 +44,6 @@ void lab_move(unsigned short *x, unsigned short *y, Direction direction){
}
void set_wall(Field_State** field, unsigned short x, unsigned short y) {
field[0][0] = WALL;
field[x][y] = WALL;
}

31
src/test/c/test_labyrinth.c

@ -231,3 +231,34 @@ void test_set_wall_at_0_0_expected_WALL(void)
free(field);
}
void test_set_wall_at_2_3_expected_WALL(void)
{
/* arrange */
unsigned short x = 2;
unsigned short y = 3;
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] = WAY;
Field_State expected = WALL;
/* act */
set_wall(field, x, 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