Browse Source

set_wall at 0 0

main^2
Joe Lukas Kalb 11 months ago
committed by Peter Wiebe
parent
commit
c6e2986865
  1. 4
      src/main/c/global.h
  2. 4
      src/main/c/labyrinth.c
  3. 1
      src/main/c/labyrinth.h
  4. 31
      src/test/c/test_labyrinth.c

4
src/main/c/global.h

@ -5,4 +5,8 @@ typedef enum {
N, E, S, W N, E, S, W
} Direction; } Direction;
typedef enum {
WAY, WALL, SOLUTION
} State;
#endif #endif

4
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;
}

1
src/main/c/labyrinth.h

@ -5,5 +5,6 @@
void turn_direction_right(Direction *direction); void turn_direction_right(Direction *direction);
void lab_move(unsigned short *x, unsigned short *y, 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 #endif // TEST_H

31
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); 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);
}
Loading…
Cancel
Save