From 318d572d470810f7a9d21a76e824612055b6ba97 Mon Sep 17 00:00:00 2001 From: Joe Lukas Kalb Date: Tue, 6 Feb 2024 18:47:01 +0100 Subject: [PATCH] set_wall at any x y --- 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 71ccb5c..8afa959 100644 --- a/src/main/c/labyrinth.c +++ b/src/main/c/labyrinth.c @@ -44,6 +44,6 @@ void lab_move(unsigned short *x, unsigned short *y, Direction direction){ } void set_wall(Field_State** field, unsigned short x, unsigned short y) { - field[0][0] = WALL; + field[x][y] = WALL; } diff --git a/src/test/c/test_labyrinth.c b/src/test/c/test_labyrinth.c index 9ef1074..b5d9091 100644 --- a/src/test/c/test_labyrinth.c +++ b/src/test/c/test_labyrinth.c @@ -231,3 +231,34 @@ void test_set_wall_at_0_0_expected_WALL(void) free(field); } +void test_set_wall_at_2_3_expected_WALL(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] = WAY; + + Field_State expected = WALL; + + /* act */ + set_wall(field, x, 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); +} +