From ab6ef224ab00618584be653c27dafcda434b47ee Mon Sep 17 00:00:00 2001 From: Joe Lukas Kalb Date: Tue, 6 Feb 2024 18:48:59 +0100 Subject: [PATCH] init_field with WAY at 0 0 --- src/main/c/labyrinth.c | 4 ++++ src/main/c/labyrinth.h | 1 + src/test/c/test_labyrinth.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/main/c/labyrinth.c b/src/main/c/labyrinth.c index 8afa959..75c718b 100644 --- a/src/main/c/labyrinth.c +++ b/src/main/c/labyrinth.c @@ -47,3 +47,7 @@ void set_wall(Field_State** field, unsigned short x, unsigned short y) { field[x][y] = WALL; } +void init_field(Field_State** field, unsigned short len_x, unsigned short len_y){ + field[0][0] = WAY; +} + diff --git a/src/main/c/labyrinth.h b/src/main/c/labyrinth.h index 5b789f4..19b1835 100644 --- a/src/main/c/labyrinth.h +++ b/src/main/c/labyrinth.h @@ -6,5 +6,6 @@ void turn_direction_right(Direction *direction); void lab_move(unsigned short *x, unsigned short *y, Direction direction); 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); #endif // TEST_H diff --git a/src/test/c/test_labyrinth.c b/src/test/c/test_labyrinth.c index b5d9091..3658ce2 100644 --- a/src/test/c/test_labyrinth.c +++ b/src/test/c/test_labyrinth.c @@ -262,3 +262,33 @@ void test_set_wall_at_2_3_expected_WALL(void) free(field); } +void test_init_field_at_0_0_expected_WAY(void) +{ + /* arrange */ + unsigned short x = 0; + unsigned short y = 0; + + 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]); + } + + 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); +}