예제 #1
0
class TestSectionLevelAccess(object):
    """
    Tests to ensure that client has access to portion of level via Section
    """

    def __init__(self):
        """
        Default constructor
        """
        object.__init__(self)
        self.level = None
        self.section = None
        self.floor_empty = None
        self.floor_rock = None
        self.wall_empty = None
        self.wall_ground = None
        self.rng = random.Random()

    def setup(self):
        """
        Setup the test case
        """
        self.floor_empty = 0
        self.floor_rock = 1
        self.wall_empty = 10
        self.wall_ground = 11
        self.level = Level((10, 10), self.floor_empty, self.wall_empty)
        self.section = Section((0, 0), (10, 10), self.level, self.rng)

    def test_setting_floor(self):
        """
        Test that floor can be set
        """
        self.section.set_floor((5, 5), self.floor_rock, None)

        assert_that(self.level.floor[5][5], is_(equal_to(self.floor_rock)))

    def test_setting_wall(self):
        """
        Test that walls can be set
        """
        self.section.set_wall((2, 2), self.wall_ground, None)

        assert_that(self.level.walls[2][2], is_(equal_to(self.wall_ground)))

    def test_setting_location_type(self):
        """
        Test that location type can be set correctly
        """
        self.section.set_floor((2, 3), self.floor_rock, "corridor")

        assert_that(self.level.get_location_type((2, 3)), is_(equal_to("corridor")))
예제 #2
0
class TestSectionLevelAccessWithOffset(object):
    """
    Tests to ensure that client has access to portion of level via Section that
    has been offset from the level
    """

    def __init__(self):
        """
        Default constructor
        """
        object.__init__(self)
        self.level = None
        self.section = None
        self.rng = random.Random()
        self.floor_empty = None
        self.floor_rock = None
        self.wall_empty = None
        self.wall_ground = None

    def setup(self):
        """
        Setup the test case
        """
        self.floor_empty = 0
        self.floor_rock = 1
        self.wall_empty = 10
        self.wall_ground = 11
        self.level = Level((10, 10), self.floor_empty, self.wall_empty)
        self.section = Section((5, 5), (10, 10), self.level, self.rng)

    def test_setting_floor_with_offset(self):
        """
        Test that off set Section is correctly mapped to the level
        """
        self.section.set_floor((2, 2), self.floor_rock, None)

        assert_that(self.level.floor[7][7], is_(equal_to(self.floor_rock)))

    def test_setting_wall_with_offset(self):
        """
        Test that offset Section is correctly mapped to the level
        """
        self.section.set_wall((3, 2), self.wall_ground, None)

        assert_that(self.level.walls[8][7], is_(equal_to(self.wall_ground)))