From 5f2941c3f7d0e9d462883909e5a98c10a81f2904 Mon Sep 17 00:00:00 2001 From: Joe Lukas Kalb Date: Tue, 6 Feb 2024 18:43:15 +0100 Subject: [PATCH] set_wall at 0 0 --- src/main/c/global.h | 4 ++++ src/main/c/labyrinth.c | 4 ++++ src/main/c/labyrinth.h | 1 + src/test/c/test_labyrinth.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/src/main/c/global.h b/src/main/c/global.h index 556a1f1..1dea8db 100644 --- a/src/main/c/global.h +++ b/src/main/c/global.h @@ -5,4 +5,8 @@ typedef enum { N, E, S, W } Direction; +typedef enum { + WAY, WALL, SOLUTION +} State; + #endif \ No newline at end of file diff --git a/src/main/c/labyrinth.c b/src/main/c/labyrinth.c index ba08944..7b13e6e 100644 --- a/src/main/c/labyrinth.c +++ b/src/main/c/labyrinth.c @@ -43,3 +43,7 @@ void lab_move(unsigned short *x, unsigned short *y, Direction direction){ } +void set_wall(State** field, unsigned short x, unsigned short y) { + field[0][0] = WALL; +} + diff --git a/src/main/c/labyrinth.h b/src/main/c/labyrinth.h index 3bd9821..15cd364 100644 --- a/src/main/c/labyrinth.h +++ b/src/main/c/labyrinth.h @@ -5,5 +5,6 @@ void turn_direction_right(Direction *direction); void lab_move(unsigned short *x, unsigned short *y, Direction direction); +void set_wall(State** field, unsigned short x, unsigned short y); #endif // TEST_H diff --git a/src/test/c/test_labyrinth.c b/src/test/c/test_labyrinth.c index 98d4f2f..f950838 100644 --- a/src/test/c/test_labyrinth.c +++ b/src/test/c/test_labyrinth.c @@ -200,3 +200,34 @@ void test_lab_move_from_5_5_W_expected_5_4(void) TEST_ASSERT_TRUE(x == x_expected && y == y_expected); } +void test_set_wall_at_0_0_expected_WALL(void) +{ + /* arrange */ + unsigned short x = 0; + unsigned short y = 0; + + unsigned short len_x = 1, len_y = 1; + 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; + + 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); +} +