Exemple #1
0
class RoomAddTest(TestCase):
    def setUp(self):
        self.room = Room(width=1, height=3)

    def test_add_turf_without_coordinates(self):
        door = Door()
        with self.assertRaises(Room.TurfCoordinatesRequired):
            self.room.add(door)

    def test_add_turf_with_coordinates_in_a_room(self):
        door = Door()
        door.x, door.y = 0, 1
        self.room.add(door)
        turfs = self.room.get(x=door.x, y=door.y)
        self.assertIn(door, turfs)
        self.assertEqual(len(turfs), 2)
        self.assertEqual(door.z, 1)

    def test_add_turf_with_unadjustable_z_level(self):
        floor = Floor()
        floor.x, floor.y = 0, 1
        with self.assertRaises(Room.TurfZLevelNotAdjustable):
            self.room.add(floor)

    def test_add_turf_outside_the_room(self):
        door = Door()
        door.x, door.y = 9, 9
        with self.assertRaises(Room.TurfCoordinatesOutsideRoomBoundaries):
            self.room.add(door)
 def test_two_diagonaly_adjacent_rooms(self):
     """
     Rooms are not considered to be adjacent if they touch diagonaly.
     """
     for x, y in [(0, 0), (1, 1)]:
         room = Room(width=1, height=1)
         room.x, room.y = x, y
         self.level.add(room)
         turf = iter(room.get(x=0, y=0)).next()
         self.assertEqual(turf.exits, {})
     self.assertEqual(len(self.level.rooms), 2)
Exemple #3
0
class RoomGetTest(TestCase):
    def setUp(self):
        self.room = Room(width=2, height=2)

    def test_get_all_turfs_in_a_room(self):
        self.assertEqual(self.room.get(), set(self.room.objects))

    def test_get_one_specific_turf(self):
        turfs = self.room.get(x=0, y=0)
        self.assertEqual(len(turfs), 1)
        turf = iter(turfs).next()
        self.assertEqual((turf.x, turf.y), (0, 0))

    def test_get_a_set_of_turfs(self):
        turfs = self.room.get(x=0)
        self.assertEqual(len(turfs), 2)
        for turf in turfs:
            self.assertEqual(turf.x, 0)

    def test_get_with_nonexistent_kwargs(self):
        self.assertEqual(self.room.get(x=0, invalid_kwarg=True), set())
 def test_level_with_two_fully_adjacent_rooms(self):
     """Exits are added to adjacent turfs."""
     a, b = Room(width=1, height=1), Room(width=1, height=1)
     a.x, a.y, b.x, b.y = 0, 0, 1, 0
     self.level.add(a)
     self.level.add(b)
     turf_a = iter(a.get(x=0, y=0)).next()
     turf_b = iter(b.get(x=0, y=0)).next()
     self.assertEqual(len(self.level.rooms), 2)
     self.assertEqual(len(turf_a.exits), 1)
     self.assertEqual(len(turf_b.exits), 1)
     self.assertEqual(turf_a.exits[(1, 0)], turf_b)
     self.assertEqual(turf_b.exits[(-1, 0)], turf_a)
 def test_level_with_three_adjacent_rooms(self):
     a, b, c = Room(width=1, height=1), Room(1, 1), Room(1, 1)
     a.x, a.y, b.x, b.y, c.x, c.y = 0, 0, 1, 0, 0, 1
     for room in (a, b, c):
         self.level.add(room)
     turf_a = iter(a.get(x=0, y=0)).next()
     turf_b = iter(b.get(x=0, y=0)).next()
     turf_c = iter(c.get(x=0, y=0)).next()
     self.assertEqual(len(turf_a.exits), 2)
     for turf in (turf_b, turf_c):
         self.assertEqual(len(turf.exits), 1)
     self.assertEqual(turf_a.exits, {(1, 0): turf_b, (0, 1): turf_c})
     self.assertEqual(turf_b.exits[(-1, 0)], turf_a)
     self.assertEqual(turf_c.exits[(0, -1)], turf_a)
 def test_level_with_two_partially_adjacent_rooms(self):
     """Non-adjacent turfs do not become exits."""
     a, b = Room(width=3, height=3), Room(width=3, height=3)
     a.x, a.y, b.x, b.y = 3, 1, 0, 0
     self.level.add(a)
     self.level.add(b)
     exits = set([((0, 0), (2, 1)), ((0, 1), (2, 2))])
     for ((a_x, a_y), (b_x, b_y)) in exits:
         turf_a = iter(a.get(x=a_x, y=a_y)).next()
         turf_b = iter(b.get(x=b_x, y=b_y)).next()
         self.assertEqual(len(turf_a.exits), 1)
         self.assertEqual(len(turf_b.exits), 1)
         self.assertEqual(turf_a.exits[(-1, 0)], turf_b)
         self.assertEqual(turf_b.exits[(1, 0)], turf_a)
     no_exits = {
         a: set([(0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]),
         b: set([(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0)])}
     for room, coordinates in no_exits.items():
         for (x, y) in coordinates:
             turf = iter(room.get(x=x, y=y)).next()
             self.assertEqual(len(turf.exits), 0)