From 8bfd95afccc04a23cc4b448e99d3c871ba1c1f93 Mon Sep 17 00:00:00 2001 From: Joe Lukas Kalb Date: Tue, 6 Feb 2024 19:04:46 +0100 Subject: [PATCH] lab_can_move direction N WALL above --- src/main/c/labyrinth.c | 5 ++++- src/test/c/test_labyrinth.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main/c/labyrinth.c b/src/main/c/labyrinth.c index 50db9df..688ef35 100644 --- a/src/main/c/labyrinth.c +++ b/src/main/c/labyrinth.c @@ -56,7 +56,7 @@ 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 >= len_x){ return 1; @@ -64,6 +64,9 @@ short lab_can_move(Field_State** field, unsigned short x, unsigned short y, Dire if (y >= len_y){ return 1; } + if (direction == N && field[x][y] == WALL){ + return 1; + } return 0; } diff --git a/src/test/c/test_labyrinth.c b/src/test/c/test_labyrinth.c index 0d8d6bc..a392006 100644 --- a/src/test/c/test_labyrinth.c +++ b/src/test/c/test_labyrinth.c @@ -475,6 +475,40 @@ void test_lab_can_move_at_0_0_direction_W_target_undefined_expected_1(void) free(field); } +void test_lab_can_move_at_1_1_direction_N_target_WALL_expected_1(void) +{ + /* arrange */ + unsigned short x = 1; + unsigned short y = 1; + unsigned short x_target = 0; + unsigned short y_target = 1; + Direction direction = N; + 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] = WALL; + + /* 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); +} + +