Exemple #1
0
 def test_add_cells(self):
     r = Room()
     assert len(r.cells) == 0
     r.add_cells([SquareCell()])
     assert len(r.cells) == 1
     assert len(r.cell_coordinates) == 1
     assert r.cell_coordinates == set(((0, 0), ))
Exemple #2
0
 def test_shift_horizontal(self):
     r = Room(self.cells)
     r.shift_horizontal(100)
     for cell in r.cells:
         assert cell.coordinates[1] >= 100, cell.coordinates
     for i in range(4):
         for j in range(5):
             assert (i, j + 100) in r.cell_coordinates
Exemple #3
0
 def test_shift_vertical(self):
     r = Room(self.cells)
     r.shift_vertical(100)
     for cell in r.cells:
         assert cell.coordinates[0] >= 100, cell.coordinates
     for i in range(4):
         for j in range(5):
             assert (i + 100, j) in r.cell_coordinates
Exemple #4
0
 def test_smoke(self):
     r = Room()
     assert r is not None
     assert r.cells == set()
     assert r.cell_coordinates == set()
     assert r.name == ""
     assert r.entrances == []
Exemple #5
0
 def test_randomize_room_size(self):
     room = Room()
     assert room.cells == set()
     rng = RoomSizeRandomizer()
     rng.randomize_room_size(room)
     assert len(room.cells) >= rng.min_size**2
     assert len(room.cells) <= rng.max_size**2
     for cell in room.cells:
         assert not cell.filled
Exemple #6
0
 def test_randomize_room_entrances(self):
     rr = RoomEntrancesRandomizer()
     # Room in the top left corner
     cell_list = [
         SquareCell(coordinates=(0, 0)),
         SquareCell(coordinates=(0, 1)),
         SquareCell(coordinates=(1, 0)),
         SquareCell(coordinates=(1, 1)),
     ]
     cells = set(cell_list)
     room = Room(cells=cells)
     self.dungeon.add_room(room)
     self.dungeon.emplace_space(room)
     # double check emplace is working
     for ind, cell in enumerate(cell_list):
         i = ind // 2
         j = ind % 2
         assert cell.y == i
         assert cell.x == j
         assert cell.edges is not None
         assert cell in cells
         assert cell is self.dungeon.grid.cells[i][j]
     rr.randomize_room_entrances(room, self.dungeon)
     assert len(room.entrances) > 0
Exemple #7
0
 def setUp(self):
     self.grid = SquareGrid(n_rows=4, n_cols=5)
     self.hexgrid = HexGrid(n_rows=4, n_cols=5)
     self.dungeon = Dungeon(grid=self.grid)
     self.room = Room(cells=set([SquareCell()]))
Exemple #8
0
 def test_no_overlap(self):
     r1 = Room(self.cells)
     cs2 = deepcopy(self.cells)
     r2 = Room(cs2)
     r2.shift_vertical(100)
     assert not r1.overlaps(r2)
Exemple #9
0
 def test_overlaps(self):
     r1 = Room(self.cells)
     r2 = Room(deepcopy(self.cells))
     assert r1.overlaps(r2)
Exemple #10
0
 def test_shift_horizontal_one_col(self):
     r = Room(self.cells)
     r.shift_horizontal(1)
     for i in range(4):
         for j in range(5):
             assert (i, j + 1) in r.cell_coordinates
Exemple #11
0
 def test_shift_vertical_one_row(self):
     r = Room(self.cells)
     r.shift_vertical(1)
     for i in range(4):
         for j in range(5):
             assert (i + 1, j) in r.cell_coordinates
Exemple #12
0
 def test_set_space_to_cells(self):
     r = Room(self.cells)
     for cell in r.cells:
         assert cell.space is r
Exemple #13
0
 def test_set_name(self):
     r = Room()
     r.set_name("catdog")
     assert r.name == "catdog"
Exemple #14
0
 def test_name(self):
     r = Room(name="testroom")
     assert r.name == "testroom"
     r = Room(name=12)
     assert r.name == "12"