def test(self): cache = ConnectedAreaCache() self.assertEquals(0, len(cache.areas)) cache.add_area([(0, 0), (1, 1)]) self.assertEquals(2, len(cache.areas)) self.assertEquals(set([(0, 0)]), cache.areas[cache.area_numbers[(0, 0)]]) self.assertEquals(set([(1, 1)]), cache.areas[cache.area_numbers[(1, 1)]]) cache.add_area([(1, 4), (1, 3), (1, 2)]) self.assertEquals(2, len(cache.areas)) self.assertEquals(set([(0, 0)]), cache.areas[cache.area_numbers[(0, 0)]]) self.assertEquals(set([(1, 1), (1, 2), (1, 3), (1, 4)]), cache.areas[cache.area_numbers[(1, 1)]]) cache.add_area([(0, 1)]) self.assertEquals(1, len(cache.areas)) self.assertEquals(set([(0, 0), (0, 1), (1, 1), (1, 2), (1, 3), (1, 4)]), cache.areas[cache.area_numbers[(0, 0)]]) cache.remove_area([(0, 1)]) self.assertEquals(2, len(cache.areas)) self.assertEquals(set([(0, 0)]), cache.areas[cache.area_numbers[(0, 0)]]) self.assertEquals(set([(1, 1), (1, 2), (1, 3), (1, 4)]), cache.areas[cache.area_numbers[(1, 1)]]) cache.remove_area([(0, 0)]) self.assertFalse((0, 0) in cache.area_numbers) self.assertEquals(1, len(cache.areas)) self.assertEquals(set([(1, 1), (1, 2), (1, 3), (1, 4)]), cache.areas[cache.area_numbers[(1, 1)]]) cache.remove_area([(1, 2), (1, 3)]) self.assertEquals(2, len(cache.areas)) self.assertEquals(set([(1, 1)]), cache.areas[cache.area_numbers[(1, 1)]]) self.assertEquals(set([(1, 4)]), cache.areas[cache.area_numbers[(1, 4)]]) cache.remove_area([(1, 1), (1, 4)]) self.assertEquals(0, len(cache.areas))
def __init__(self, area_builder): self._area_builder = area_builder self._land_manager = area_builder.land_manager self._settlement_ground_map = area_builder.settlement.ground_map self._cache = ConnectedAreaCache() self.area_numbers = self._cache.area_numbers # {(x, y): area id, ...}