From 7f3925512d86b424006fdec789cb07bab4d3acc9 Mon Sep 17 00:00:00 2001 From: Joe Lukas Kalb Date: Tue, 6 Feb 2024 19:08:55 +0100 Subject: [PATCH] lab_can_move direction S heading WALL --- src/main/c/labyrinth.c | 3 +++ src/test/c/test_labyrinth.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/main/c/labyrinth.c b/src/main/c/labyrinth.c index 004c661..7b9a2a8 100644 --- a/src/main/c/labyrinth.c +++ b/src/main/c/labyrinth.c @@ -70,6 +70,9 @@ short lab_can_move(Field_State** field, unsigned short x, unsigned short y, Dire if (direction == E && field[x][y] == WALL){ return 1; } + if (direction == S && 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 3c00353..de5b7c6 100644 --- a/src/test/c/test_labyrinth.c +++ b/src/test/c/test_labyrinth.c @@ -541,6 +541,40 @@ void test_lab_can_move_at_1_1_direction_E_target_WALL_expected_1(void) free(field); } +void test_lab_can_move_at_1_1_direction_S_target_WALL_expected_1(void) +{ + /* arrange */ + unsigned short x = 1; + unsigned short y = 1; + unsigned short x_target = 2; + unsigned short y_target = 1; + Direction direction = S; + 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); +} + +