def test_init(self):
        test_ph = tr_room_placeholder.TRRoomPlaceholder()
        self.assertTrue(isinstance(test_ph,
                                   tr_room_placeholder.TRRoomPlaceholder),
                        msg="TRRoomPlaceholder did not initialize correctly!")
        self.assertIsNone(
            test_ph.tekton_room,
            msg="TRRoomPlaceholder did not initialize correctly!")
        self.assertIsNone(
            test_ph.room_generator,
            msg="TRRoomPlaceholder did not initialize correctly!")
        self.assertEqual(1, test_ph.width,
                         "TRRoomPlaceholder did not initialize correctly!")
        self.assertEqual(1, test_ph.height,
                         "TRRoomPlaceholder did not initialize correctly!")
        self.assertEqual([[[]]], test_ph.screens,
                         "TRRoomPlaceholder did not initialize correctly!")

        test_ph = tr_room_placeholder.TRRoomPlaceholder(2, 3)
        self.assertTrue(isinstance(test_ph,
                                   tr_room_placeholder.TRRoomPlaceholder),
                        msg="TRRoomPlaceholder did not initialize correctly!")
        self.assertEqual(2, test_ph.width,
                         "TRRoomPlaceholder did not initialize correctly!")
        self.assertEqual(3, test_ph.height,
                         "TRRoomPlaceholder did not initialize correctly!")
        self.assertEqual([[[], [], []], [[], [], []]], test_ph.screens,
                         "TRRoomPlaceholder did not initialize correctly!")
    def test_add_room(self):
        test_data_dir = os.path.join(
            os.path.dirname((os.path.abspath(__file__))), 'fixtures',
            'test_tr_map_grid', 'test_add_room')
        test_data = load_test_data_dir(test_data_dir)

        for test_case in test_data:
            test_grid = tr_map_grid.TRMapGrid(test_case["grid_width"],
                                              test_case["grid_height"])
            test_room_placeholder = tr_room_placeholder.TRRoomPlaceholder()
            test_room_placeholder.width = test_case["room_width"]
            test_room_placeholder.height = test_case["room_height"]
            test_room_placeholder.tekton_room = tekton_room.TektonRoom(
                test_case["room_width"], test_case["room_height"])
            test_grid.add_room_placeholder(test_room_placeholder,
                                           test_case["x_offset"],
                                           test_case["y_offset"])
            self.assertTrue(test_room_placeholder in test_grid.rooms,
                            msg="Room was not added to TRMapGrid.rooms!")
            for col in range(test_case["x_offset"],
                             test_case["x_offset"] + test_case["room_width"]):
                for row in range(
                        test_case["y_offset"],
                        test_case["y_offset"] + test_case["room_height"]):
                    self.assertEqual(
                        test_room_placeholder, test_grid[col][row],
                        "Room was not added to TRMapGrid correctly!")

        with self.assertRaises(tr_map_grid.RoomExceedsGridBoundariesError):
            test_grid = tr_map_grid.TRMapGrid(4, 4)
            test_room_placeholder = tr_room_placeholder.TRRoomPlaceholder()
            test_room_placeholder.width = 4
            test_room_placeholder.height = 4
            test_room_placeholder.tekton_room = tekton_room.TektonRoom(4, 4)
            test_grid.add_room_placeholder(test_room_placeholder, 2, 2)
    def test_attached_door_attach_points(self):
        test_ph = tr_room_placeholder.TRRoomPlaceholder(1, 2)
        expected_results = []
        actual_results = test_ph.attached_door_attach_points
        self.assertEqual(
            expected_results, actual_results,
            "TRRoomPlaceholder did not return correct attached_door_attach_points!"
        )

        test_ph = tr_room_placeholder.TRRoomPlaceholder(9, 5)
        test_door_ap = tr_door_attach_point.TRDoorAttachPoint(
            0, 4, DoorEjectDirection.DOWN)
        test_ph.screens[0][4].append(test_door_ap)
        expected_results = []
        actual_results = test_ph.attached_door_attach_points
        self.assertEqual(
            expected_results, actual_results,
            "TRRoomPlaceholder did not return correct attached_door_attach_points!"
        )

        test_farside_room = tr_room_placeholder.TRRoomPlaceholder(2, 2)
        test_farside_door_ap = tr_door_attach_point.TRDoorAttachPoint(
            1, 1, DoorEjectDirection.UP)
        test_farside_room.screens[1][1].append(test_farside_door_ap)
        test_door_ap.attach(test_farside_room, test_farside_door_ap)
        actual_results = test_ph.attached_door_attach_points
        self.assertEqual(
            1,
            len(actual_results),
            msg=
            "attached_door_attach_points returned incorrect number of results!"
        )
        self.assertEqual(
            test_door_ap, actual_results[0],
            "attached_door_attach_points returned incorrect attach point!")
    def test_room_placement_in_bounds(self):
        test_grid = tr_map_grid.TRMapGrid(16, 16)
        new_room_ph = tr_room_placeholder.TRRoomPlaceholder(1, 1)
        actual_result = test_grid.room_placement_in_bounds(new_room_ph, 0, 0)
        self.assertTrue(
            actual_result,
            msg="room_placement_in_bounds returned the incorrect result!")

        new_room_ph = tr_room_placeholder.TRRoomPlaceholder(4, 4)
        actual_result = test_grid.room_placement_in_bounds(new_room_ph, 8, 8)
        self.assertTrue(
            actual_result,
            msg="room_placement_in_bounds returned the incorrect result!")

        new_room_ph = tr_room_placeholder.TRRoomPlaceholder(24, 24)
        actual_result = test_grid.room_placement_in_bounds(new_room_ph, 0, 0)
        self.assertFalse(
            actual_result,
            msg="room_placement_in_bounds returned the incorrect result!")

        new_room_ph = tr_room_placeholder.TRRoomPlaceholder(2, 12)
        actual_result = test_grid.room_placement_in_bounds(new_room_ph, 15, 15)
        self.assertFalse(
            actual_result,
            msg="room_placement_in_bounds returned the incorrect result!")

        new_room_ph = tr_room_placeholder.TRRoomPlaceholder(2, 2)
        actual_result = test_grid.room_placement_in_bounds(new_room_ph, 19, 18)
        self.assertFalse(
            actual_result,
            msg="room_placement_in_bounds returned the incorrect result!")
    def test_attach(self):
        test_ph_1 = tr_room_placeholder.TRRoomPlaceholder()
        test_ap_1 = tr_door_attach_point.TRDoorAttachPoint(
            0, 0, DoorEjectDirection.RIGHT)
        test_ph_1.screens[0][0].append(test_ap_1)

        test_ph_2 = tr_room_placeholder.TRRoomPlaceholder()
        test_ap_2 = tr_door_attach_point.TRDoorAttachPoint(
            0, 0, DoorEjectDirection.LEFT)
        test_ph_2.screens[0][0].append(test_ap_2)

        test_ap_1.attach(test_ph_2, test_ap_2)
        self.assertEqual(test_ph_2, test_ap_1.farside_room,
                         "Door did not attach correctly to farside room!")
        self.assertEqual(test_ap_2, test_ap_1.farside_door,
                         "Door did not attach correctly to farside room!")

        test_ph_3 = tr_room_placeholder.TRRoomPlaceholder()
        test_ap_3 = tr_door_attach_point.TRDoorAttachPoint(
            0, 0, DoorEjectDirection.UP)
        test_ph_3.screens[0][0].append(test_ap_3)

        with self.assertRaises(tr_door_attach_point.InvalidDoorAttachError):
            test_ap_1.attach(test_ph_3, test_ap_3)

        with self.assertRaises(TypeError):
            test_ap_2.attach("Landing Site", test_ap_1)
        with self.assertRaises(TypeError):
            test_ap_2.attach(test_ph_1, 0)
 def test_get_room_top_left_coords(self):
     test_grid = tr_map_grid.TRMapGrid(16, 16)
     new_room_ph = tr_room_placeholder.TRRoomPlaceholder(3, 3)
     test_grid.add_room_placeholder(new_room_ph, 5, 2)
     expected_result = 5, 2
     actual_result = test_grid.get_room_top_left_coords(new_room_ph)
     self.assertEqual(
         expected_result, actual_result,
         "get_room_top_left_coords did not return correct result!")
    def test_available_door_attach_points(self):
        test_ph = tr_room_placeholder.TRRoomPlaceholder(1, 2)
        expected_results = []
        actual_results = test_ph.available_door_attach_points
        self.assertEqual(
            expected_results, actual_results,
            "TRRoomPlaceholder did not return correct available_door_attach_points!"
        )

        test_ph = tr_room_placeholder.TRRoomPlaceholder(9, 5)
        test_door_ap = tr_door_attach_point.TRDoorAttachPoint(
            0, 4, DoorEjectDirection.RIGHT)
        test_ph.screens[0][4].append(test_door_ap)
        actual_results = test_ph.available_door_attach_points
        self.assertEqual(
            1, len(actual_results),
            "available_door_attach_points returned incorrect number of results!"
        )
        self.assertEqual(
            test_door_ap, actual_results[0],
            "available_door_attach_points returned incorrect attach point!")
    def test_room_placement_overlaps_existing_room(self):
        test_grid = tr_map_grid.TRMapGrid(16, 16)
        new_room_ph = tr_room_placeholder.TRRoomPlaceholder(1, 1)
        actual_result = test_grid.room_placement_overlaps_existing_room(
            new_room_ph, 0, 0)
        self.assertFalse(
            actual_result,
            msg=
            "room_placement_overlaps_existing_room returned the incorrect result!"
        )

        test_grid.add_room_placeholder(new_room_ph, 0, 0)
        actual_result = test_grid.room_placement_overlaps_existing_room(
            new_room_ph, 0, 0)
        self.assertTrue(
            actual_result,
            msg=
            "room_placement_overlaps_existing_room returned the incorrect result!"
        )

        new_room_ph = tr_room_placeholder.TRRoomPlaceholder(4, 4)
        actual_result = test_grid.room_placement_overlaps_existing_room(
            new_room_ph, 8, 8)
        self.assertFalse(
            actual_result,
            msg=
            "room_placement_overlaps_existing_room returned the incorrect result!"
        )

        test_grid.add_room_placeholder(new_room_ph, 8, 8)
        actual_result = test_grid.room_placement_overlaps_existing_room(
            new_room_ph, 5, 7)
        self.assertTrue(
            actual_result,
            msg=
            "room_placement_overlaps_existing_room returned the incorrect result!"
        )
    def test_is_attached(self):
        test_ap = tr_door_attach_point.TRDoorAttachPoint()
        second_ap = tr_door_attach_point.TRDoorAttachPoint()
        test_room_ph = tr_room_placeholder.TRRoomPlaceholder()
        self.assertFalse(
            test_ap.is_attached,
            msg="TRDoorAttachPoint did not return correct attached status!")

        test_ap.farside_door = second_ap
        self.assertFalse(
            test_ap.is_attached,
            msg="TRDoorAttachPoint did not return correct attached status!")

        test_ap.farside_room = test_room_ph
        self.assertTrue(
            test_ap.is_attached,
            msg="TRDoorAttachPoint did not return correct attached status!")
        self.assertFalse(
            second_ap.is_attached,
            msg="TRDoorAttachPoint did not return correct attached status!")
Exemplo n.º 10
0
    def test_create_tekton_door(self):
        test_door_ap = tr_door_attach_point.TRDoorAttachPoint(0, 0, tekton_door.DoorEjectDirection.UP)
        test_farside_door_ap = tr_door_attach_point.TRDoorAttachPoint(3, 3, tekton_door.DoorEjectDirection.DOWN)
        test_farside_room = tr_room_placeholder.TRRoomPlaceholder(5, 5)
        test_farside_room.screens[3][3].append(test_farside_door_ap)
        test_farside_room.tekton_room = tekton_room.TektonRoom(5, 5)
        test_farside_room.tekton_room.header = 0x71234
        test_door_ap.attach(test_farside_room, test_farside_door_ap)

        actual_result = tr_door_generator.create_tekton_door(test_door_ap)
        self.assertTrue(isinstance(actual_result, tekton_door.TektonDoor),
                        msg="create_tekton_door did not return TektonDoor")
        self.assertEqual(0x71234, actual_result.target_room_id, msg="TektonDoor has incorrect target_room_id!")
        self.assertEqual(test_farside_door_ap.h_screen,
                         actual_result.target_room_screen_h,
                         msg="TektonDoor has incorrect target_room_screen_h")
        self.assertEqual(test_farside_door_ap.v_screen,
                         actual_result.target_room_screen_v,
                         msg="TektonDoor has incorrect target_room_screen_v")
        self.assertEqual(test_door_ap.eject_direction,
                         actual_result.eject_direction,
                         msg="TektonDoor has incorrect eject_direction!")