Browse Source

lab_can_move direction W heading SOLUTION

main^2
Joe Lukas Kalb 11 months ago
committed by Peter Wiebe
parent
commit
b5b972bcad
  1. 3
      src/main/c/labyrinth.c
  2. 32
      src/test/c/test_labyrinth.c

3
src/main/c/labyrinth.c

@ -76,6 +76,9 @@ short lab_can_move(Field_State** field, unsigned short x, unsigned short y, Dire
if (direction == S && field[x][y] == SOLUTION){ if (direction == S && field[x][y] == SOLUTION){
return 1; return 1;
} }
if (direction == W && field[x][y] == SOLUTION){
return 1;
}
return 0; return 0;
} }

32
src/test/c/test_labyrinth.c

@ -703,3 +703,35 @@ void test_lab_can_move_at_1_1_direction_S_target_SOLUTION_expected_1(void)
free(field); free(field);
} }
void test_lab_can_move_at_1_1_direction_W_target_SOLUTION_expected_1(void)
{
/* arrange */
unsigned short x = 1;
unsigned short y = 1;
unsigned short x_target = 1;
unsigned short y_target = 0;
Direction direction = W;
short expected = 1;
short actual;
unsigned short len_x = 3, len_y = 3;
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_target][y_target] = SOLUTION;
/* act */
actual = lab_can_move(field, x, y, direction, len_x, len_y);
/* assert */
TEST_ASSERT_EQUAL_INT8(expected, actual);
for (int c_index = 0; c_index < len_x; c_index++)
{
free(field[c_index]);
}
free(field);
}
Loading…
Cancel
Save