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); +} +