From a9872e34a116fcdf93e4c1d2e30576cdb6a014d3 Mon Sep 17 00:00:00 2001 From: Joe Lukas Kalb Date: Tue, 6 Feb 2024 18:52:27 +0100 Subject: [PATCH] init_field any x y --> WAY --- src/main/c/labyrinth.c | 4 +++- src/test/c/test_labyrinth.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/main/c/labyrinth.c b/src/main/c/labyrinth.c index 4c10c06..63d9f94 100644 --- a/src/main/c/labyrinth.c +++ b/src/main/c/labyrinth.c @@ -49,7 +49,9 @@ 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){ for (int x = 0; x < len_x; x++){ - field[x][0] = WAY; + for (int y = 0; y < len_y; y++){ + field[x][y] = WAY; + } } } diff --git a/src/test/c/test_labyrinth.c b/src/test/c/test_labyrinth.c index c8fa6cf..2027c8b 100644 --- a/src/test/c/test_labyrinth.c +++ b/src/test/c/test_labyrinth.c @@ -323,3 +323,35 @@ void test_init_field_at_2_0_expected_WAY(void) } free(field); } + +void test_init_field_at_2_3_expected_WAY(void) +{ + /* arrange */ + unsigned short x = 2; + unsigned short y = 3; + + unsigned short len_x = 5, len_y = 5; + 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][y] = WALL; + + Field_State expected = WAY; + + /* act */ + init_field(field, len_x, len_y); + + /* assert */ + TEST_ASSERT_TRUE(field[x][y] == expected); + + for (int c_index = 0; c_index < len_x; c_index++) + { + free(field[c_index]); + } + free(field); +} +