Exemplo n.º 1
0
    def test_rm_perimeter_one_unit(self):
        points_to_elevation = {
            Point(0, 0): 0,
            Point(1, 0): 5,
            Point(2, 0): 0,
            Point(0, 1): 1,
            Point(1, 1): 1,
            Point(2, 1): 2,
            Point(0, 2): 2,
            Point(1, 2): 3,
            Point(2, 2): 3
        }
        tiles = [
            Tile(elevation=elevation, point=point)
            for point, elevation in points_to_elevation.items()
        ]
        the_map = Map(3, 3, tiles)
        listener = PerimeterListener(the_map)
        melee_pt = Point(1, 1)
        listener.set_perimeter(self.melee, melee_pt)

        empty = {pt: set() for pt in points_to_elevation}
        non_empty = {pt: set() for pt in points_to_elevation}
        non_empty[Point(0, 1)] = {self.melee}
        non_empty[Point(2, 1)] = {self.melee}
        non_empty[Point(1, 2)] = {self.melee}

        self.assertEqual(listener._watchers_at_point, non_empty)

        listener.rm_perimeter(self.melee)

        self.assertEqual(listener._watchers_at_point, empty)
Exemplo n.º 2
0
    def test_rm_perimeter_two_units(self):
        points_to_elevation = {
            Point(0, 0): 0,
            Point(1, 0): 5,
            Point(2, 0): 0,
            Point(0, 1): 1,
            Point(1, 1): 1,
            Point(2, 1): 2,
            Point(0, 2): 2,
            Point(1, 2): 3,
            Point(2, 2): 3
        }
        tiles = [
            Tile(elevation=elevation, point=point)
            for point, elevation in points_to_elevation.items()
        ]
        the_map = Map(3, 3, tiles)
        listener = PerimeterListener(the_map)
        melee_pt = Point(1, 1)
        ranged_pt = Point(0, 0)
        listener.set_perimeter(self.melee, melee_pt)
        listener.set_perimeter(self.ranged, ranged_pt)

        with_ranged = {pt: set() for pt in points_to_elevation}
        with_ranged[Point(0, 1)] = {self.ranged, self.melee}
        with_ranged[Point(1, 0)] = {self.ranged}
        with_ranged[Point(0, 2)] = {self.ranged}
        with_ranged[Point(1, 1)] = {self.ranged}

        with_ranged[Point(2, 1)] = {self.melee}
        with_ranged[Point(1, 2)] = {self.melee}

        no_ranged = {pt: set() for pt in points_to_elevation}
        no_ranged[Point(0, 1)] = {self.melee}
        no_ranged[Point(2, 1)] = {self.melee}
        no_ranged[Point(1, 2)] = {self.melee}

        self.assertEqual(listener._watchers_at_point, with_ranged)

        listener.rm_perimeter(self.ranged)

        self.assertEqual(listener._watchers_at_point, no_ranged)