From 6bf1d1946fd7a4bc3fecf10973be983cbfe293db Mon Sep 17 00:00:00 2001 From: Joe Lukas Kalb Date: Tue, 6 Feb 2024 19:01:44 +0100 Subject: [PATCH] lab_can_move x undefined over 0 --- src/main/c/labyrinth.c | 2 +- src/test/c/test_labyrinth.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/c/labyrinth.c b/src/main/c/labyrinth.c index 4686b6c..ea27816 100644 --- a/src/main/c/labyrinth.c +++ b/src/main/c/labyrinth.c @@ -58,7 +58,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 == 65535){ + if (x >= len_x){ return 1; } if (y == 1){ diff --git a/src/test/c/test_labyrinth.c b/src/test/c/test_labyrinth.c index aa50607..83abd75 100644 --- a/src/test/c/test_labyrinth.c +++ b/src/test/c/test_labyrinth.c @@ -415,5 +415,36 @@ void test_lab_can_move_at_0_0_direction_E_target_undefined_expected_1(void) free(field); } +void test_lab_can_move_at_0_0_direction_S_target_undefined_expected_1(void) +{ + /* arrange */ + unsigned short x = 0; + unsigned short y = 0; + Direction direction = S; + 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); +} + +