def test_territory_take_a_random_unit(self): territory = Territory() troop = Troop(territory=territory) cavalry = Cavalry(territory=territory) self.assertEqual(troop, territory.take_unit(Troop)) self.assertEqual(cavalry, territory.take_unit(Cavalry))
def test_taking_negative_units_is_rejected(self): territory = Territory() for i in range(10): Troop(territory=territory) with self.assertRaises(ValueError): territory.take_unit(Troop, -1)
def test_unit_autoincrement_carries_between_unit_types(self): """If a new unit is created, the id is incremented, even if it is of a different unit type.""" troop = Troop(territory=Territory()) cavalry = Cavalry(territory=Territory()) troop_2 = Troop(territory=Territory()) self.assertEqual(troop.id + 1, cavalry.id) self.assertEqual(troop.id + 2, troop_2.id)
def test_taking_more_units_than_present_is_rejected(self): territory = Territory() for i in range(10): Troop(territory=territory) with self.assertRaises(InsufficientUnitsException): territory.take_unit(Troop, 12)
def test_troops_cavalry_and_generals_are_units(self): """A troop, cavalry or general are a type of unit and should be recognized as such.""" troop = Troop(territory=Territory()) cavalry = Cavalry(territory=Territory()) general = General(territory=Territory()) self.assertIsInstance(troop, Unit) self.assertIsInstance(cavalry, Unit) self.assertIsInstance(general, Unit)
def test_a_territory_with_units_is_not_empty(self): """If a territory contains units, it is not empty. Note that this is different from that territory having an owner. The question that remains is whether a unit in a neutral land can have no owner -- not even Barbarian.""" t = Territory() troop = Troop(territory=t) self.assertFalse(t.is_empty())
def test_territory_id_autoincrement(self): """Territories have an id field that should increment automatically when new instances are created.""" territories = [] for _ in range(10): territories.append(Territory()) first_id = min([t.id for t in territories]) for i, territory in enumerate(territories): self.assertEqual(i + first_id, territory.id)
def generate_territories(self, amount: int = 2, owners: list[Player] = None, complete_graph=True) -> list[Territory]: if owners is None: owners = [None for _ in range(amount)] if len(owners) < amount: # Pad the owner list with Nones if necessary owners += [None for _ in range(amount - len(owners))] # Register the territories into the world. for territory in (territories := [Territory(owner=owner, world=self.world) for owner in owners]): self.world.territories[territory.id] = territory
def test_taking_zero_units_is_permitted(self): territory = Territory() for i in range(10): Troop(territory=territory) self.assertEqual([], territory.take_unit(Troop, 0)) empty_territory = Territory() self.assertEqual([], empty_territory.take_unit(Troop, 0))
def assertTerritoryHasTroops(self, territory: Territory, num_troops: int) -> None: self.assertEqual(num_troops, len(territory.all(Troop)))
def test_a_territory_with_a_construct_is_not_empty(self): t = Territory() Construct(territory=t) self.assertFalse(t.is_empty())
def test_a_territory_without_units_is_neutral(self): """If a territory contains no units, it is neutral.""" t = Territory() self.assertTrue(t.is_neutral())
def test_a_territory_is_land_by_default(self): """When the biome is not specified explicitly, land is assumed.""" t = Territory() self.assertEqual(LandBiome, t.biome)
def test_territory_initialization_without_parameters(self): """A territory can be initialized without parameters.""" territory = Territory() self.assertIsInstance(territory.id, int)
def test_adjacent_territory_detection(self): t1, t2 = Territory(), Territory() t1.world.boundaries.add(Boundary(territories=(t1, t2))) self.assertEqual(t1.adjacent_territories, {t2}) self.assertEqual(t2.adjacent_territories, {t1})
"not question [b]Aluce[/b]'s authority, for you [u]will[/u] be cast down and punished " "for your heresy.", influence_points=0) psycho17 = Player( name="Psycho17", description= "Psycho17. A name most renowned through all the lands. A name synonymous with peace " "and order, but also that of terror... striking fear in the heart of those who " "oppose him. A most humble Lord, one who honors and cherishes his people and " "allies is surmountable to befriend. But if you decide to betray or do evil to his " "people and allies... all hell will come of it, and your lands will have a new " "reigning Lord.", influence_points=0) world_map = World() territories = { Territory(name="Worthless Wasteland"), Territory(name="Magnificent Metropolis", owner=aluce), Territory(name="Omnipotent Oceans", biome=WaterBiome, owner=aluce), } world_map.territories = { territory.id: territory for territory in territories } print(render_struct(aluce)) print(render_struct(psycho17)) print(render_struct(world_map))