diff --git a/src/main/c/labyrinth.c b/src/main/c/labyrinth.c index 9259093..8087c3b 100644 --- a/src/main/c/labyrinth.c +++ b/src/main/c/labyrinth.c @@ -55,3 +55,13 @@ void init_field(Field_State** field, unsigned short len_x, unsigned short len_y) } } +short lab_can_move(Field_State** field, unsigned short x, unsigned short y, Direction direction, unsigned short len_x, unsigned short len_y){ + + lab_move(&x, &y, direction); + if (x == 65535){ + return 1; + } + + return 0; +} + diff --git a/src/main/c/labyrinth.h b/src/main/c/labyrinth.h index 19b1835..ef19e30 100644 --- a/src/main/c/labyrinth.h +++ b/src/main/c/labyrinth.h @@ -7,5 +7,6 @@ void turn_direction_right(Direction *direction); void lab_move(unsigned short *x, unsigned short *y, Direction direction); 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); +short lab_can_move(Field_State** field, unsigned short x, unsigned short y, Direction direction, unsigned short len_x, unsigned short len_y); #endif // TEST_H diff --git a/src/test/c/test_labyrinth.c b/src/test/c/test_labyrinth.c index 2027c8b..7192ff4 100644 --- a/src/test/c/test_labyrinth.c +++ b/src/test/c/test_labyrinth.c @@ -355,3 +355,34 @@ void test_init_field_at_2_3_expected_WAY(void) free(field); } +void test_lab_can_move_at_0_0_direction_N_target_undefined_expected_1(void) +{ + /* arrange */ + unsigned short x = 0; + unsigned short y = 0; + Direction direction = N; + short expected = 1; + short actual; + + unsigned short len_x = 1, len_y = 1; + 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]); + } + + /* 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); +} + +