class TestSquareRoom: """ Tests for SquareRoomGenerator room generator """ def __init__(self): """ Default constructor """ self.level = None self.section = None self.generator = None self.floor_empty = 0 self.floor_rock = 1 self.wall_empty = 10 self.wall_ground = 11 self.rng = random.Random() def setup(self): """ Setup the test case """ self.level = Level((20, 20), self.floor_rock, self.wall_ground) self.section = Section((5, 5), (15, 15), self.level, self.rng) self.generator = SquareRoomGenerator(self.floor_rock, self.wall_empty, ["crypt"]) def test_generate_simple_room(self): """ Test that generator can create a simple room """ self.generator.generate_room(self.section) room_found = False for y_loc in range(20): for x_loc in range(20): if self.level.get_tile(x_loc, y_loc) != self.wall_empty: room_found = True assert_that(room_found, is_(True)) def test_room_connections_are_placed(self): """ Test that generating a square room will place 4 connectors """ self.generator.generate_room(self.section) assert_that(self.section.room_connections, has_length(4))
class TestCorridor(): """ Tests for Corridor """ def __init__(self): """ Default constructor """ self.level = None self.section = None self.rng = None self.floor_rock = None self.wall_ground = None self.wall_empty = None def setup(self): """ Setup the test case """ self.floor_rock = 1 self.wall_ground = 2 self.wall_empty = 3 self.level = Level(size = (10, 10), floor_type = self.floor_rock, wall_type = self.wall_ground, empty_wall = self.wall_empty) self.rng = random.Random() self.section = Section(corner1 = (0, 0), corner2 = (10, 10), level = self.level, random_generator = self.rng) def test_straight_horizontal(self): """ Test that straight horizontal corridor can be made """ edge_connection = Connection(connection = None, location = (10, 5), direction = "left", section = self.section) room_connection = Connection(connection = None, location = (5, 5), direction = "right", section = self.section) self.section.connections.append(edge_connection) self.section.room_connections.append(room_connection) generator = CorridorGenerator(start_point = edge_connection, end_point = room_connection, tile = self.wall_empty) generator.generate() for x_loc in range(5, 11): assert_that(self.level.get_tile(x_loc, 5), is_(equal_to(self.floor_rock))) def test_straight_vertical(self): """ Test that straight vertical corridor can be made """ edge_connection = Connection(connection = None, location = (5, 0), direction = "down", section = self.section) room_connection = Connection(connection = None, location = (5, 5), direction = "up", section = self.section) self.section.connections.append(edge_connection) self.section.room_connections.append(room_connection) generator = CorridorGenerator(start_point = edge_connection, end_point = room_connection, tile = self.wall_empty) generator.generate() for y_loc in range(0, 6): assert_that(self.level.get_tile(5, y_loc), is_(equal_to(self.floor_rock))) def test_bent_horizontal(self): """ Test that horizontal corridor with bend can be made """ edge_connection = Connection(connection = None, location = (10, 2), direction = "left", section = self.section) room_connection = Connection(connection = None, location = (5, 8), direction = "right", section = self.section) self.section.connections.append(edge_connection) self.section.room_connections.append(room_connection) generator = CorridorGenerator(start_point = edge_connection, end_point = room_connection, tile = self.wall_empty) generator.generate() assert_that(self.level.get_wall_tile(10, 2), is_(equal_to(self.wall_empty))) assert_that(self.level.get_wall_tile(5, 8), is_(equal_to(self.wall_empty))) assert_that(self.level, is_fully_accessible_via(self.wall_empty)) def test_bent_vertical(self): """ Test that horizontal corridor with bend can be made """ edge_connection = Connection(connection = None, location = (9, 0), direction = "down", section = self.section) room_connection = Connection(connection = None, location = (2, 9), direction = "up", section = self.section) self.section.connections.append(edge_connection) self.section.room_connections.append(room_connection) generator = CorridorGenerator(start_point = edge_connection, end_point = room_connection, tile = self.wall_empty) generator.generate() assert_that(self.level.get_wall_tile(9, 0), is_(equal_to(self.wall_empty))) assert_that(self.level.get_wall_tile(2, 9), is_(equal_to(self.wall_empty))) assert_that(self.level, is_fully_accessible_via(self.wall_empty))