def __init__(self): super().__init__() self.container.add_resource_slot(Cabbage, 5) self.container.add_resource_slot(Wood, 5) cabbage_plant = ResourcePlant() cabbage_plant.add_resource_requirement(Wood, 1) cabbage_plant.add_resource_product(Cabbage, 1) self.add_resource_plant(cabbage_plant)
def __init__(self): super().__init__() self.container.add_resource_slot(Wood, 5) self.container.add_resource_slot(Lumber, 5) self.add_producable_resource(Lumber) lumber_plant = ResourcePlant() lumber_plant.add_resource_requirement(Wood, 1) lumber_plant.add_resource_product(Lumber, 1) self.add_resource_plant(lumber_plant)
def test_add_resource_product_raises_error_if_there_is_already_a_product_for_that_resource_type(self): # noqa plant = ResourcePlant() plant.add_resource_product(Fish, 10) with self.assertRaises(ProducerConsumerException) as error_context: plant.add_resource_product(Fish, 12) self.assertEqual( "A resource product of that type has already been added", error_context.exception.message )
def test_can_produce_returns_true_if_the_supplied_container_has_the_necessary_capacity_for_the_products(self): # noqa tray = SlottedCargoContainer() tray.add_resource_slot(Fish, 10) tray.add_resource_slot(Wood, 10) tray.load_cargo(Fish, 3) tray.load_cargo(Wood, 5) plant = ResourcePlant() plant.add_resource_product(Fish, 2) plant.add_resource_product(Wood, 5) self.assertTrue(plant.can_produce(tray))
def test_is_possible_returns_false_if_the_building_has_no_remaining_capacity_of_the_resource(self): building = Building() building.container.add_resource_slot(Fish, 10) building.container.add_resource_slot(Cabbage, 10) building.container.add_resource_slot(Stone, 10) building.receive_cargo(Fish, 10) cabbage_plant = ResourcePlant() cabbage_plant.add_resource_requirement(Fish, 3) cabbage_plant.add_resource_product(Cabbage, 2) building.add_resource_plant(cabbage_plant) produce = Produce(building, Cabbage, 1) self.assertFalse(produce.is_possible(building, 1))
def test_can_produce_returns_false_if_the_supplied_container_lacks_the_necessary_capacity_for_the_products(self): # noqa tray = SlottedCargoContainer() tray.add_resource_slot(Fish, 10) tray.add_resource_slot(Wood, 10) tray.load_cargo(Fish, 3) tray.load_cargo(Wood, 5) plant1 = ResourcePlant() plant1.add_resource_product(Fish, 2) plant1.add_resource_product(Wood, 6) self.assertFalse(plant1.can_produce(tray)) plant2 = ResourcePlant() plant2.add_resource_product(Fish, 2) plant2.add_resource_product(Wood, 5) plant2.add_resource_product(Cabbage, 1) self.assertFalse(plant2.can_produce(tray))
def test__execute_produces_resource_based_on_the_transfer_rate_and_dt(self): building = Building() building.container.add_resource_slot(Fish, 10) building.container.add_resource_slot(Cabbage, 10) building.container.add_resource_slot(Stone, 10) building.receive_cargo(Fish, 10) cabbage_plant = ResourcePlant() cabbage_plant.add_resource_requirement(Fish, 3) cabbage_plant.add_resource_product(Cabbage, 2) building.add_resource_plant(cabbage_plant) produce = Produce(building, Cabbage, 1) self.assertTrue(produce.is_possible(building, 1)) produce._execute(building, 2) self.assertEqual(building.container.current_load(Cabbage), 2)
def test_digest_consumes_required_resources_and_produces_resource_products(self): # noqa tray = SlottedCargoContainer() tray.add_resource_slot(Fish, 10) tray.add_resource_slot(Wood, 10) tray.add_resource_slot(Cabbage, 10) tray.load_cargo(Fish, 3) tray.load_cargo(Wood, 5) tray.load_cargo(Cabbage, 4) plant = ResourcePlant() plant.add_resource_requirement(Fish, 3) plant.add_resource_requirement(Wood, 2) plant.add_resource_product(Cabbage, 6) plant.digest(tray) self.assertEqual(tray.cargo_slots[Fish.name]['load'], 0) self.assertEqual(tray.cargo_slots[Wood.name]['load'], 3) self.assertEqual(tray.cargo_slots[Cabbage.name]['load'], 10)
def test_produce_resources_digests_resources_with_all_the_available_digesters(self): # noqa building = Building() building.container.add_resource_slot(Fish, 10) building.container.add_resource_slot(Wood, 10) building.container.add_resource_slot(Cabbage, 10) building.container.add_resource_slot(Stone, 10) building.receive_cargo(Fish, 10) building.receive_cargo(Wood, 10) cabbage_plant = ResourcePlant() cabbage_plant.add_resource_requirement(Fish, 3) cabbage_plant.add_resource_requirement(Wood, 2) cabbage_plant.add_resource_product(Cabbage, 2) building.add_resource_plant(cabbage_plant) stone_plant = ResourcePlant() stone_plant.add_resource_requirement(Fish, 1) stone_plant.add_resource_requirement(Wood, 3) stone_plant.add_resource_requirement(Cabbage, 5) stone_plant.add_resource_product(Stone, 1) building.add_resource_plant(stone_plant) building.produce_resources() self.assertEqual(building.container.current_load(Fish), 7) self.assertEqual(building.container.current_load(Wood), 8) self.assertEqual(building.container.current_load(Cabbage), 2) self.assertEqual(building.container.current_load(Stone), 0) building.produce_resources() self.assertEqual(building.container.current_load(Fish), 4) self.assertEqual(building.container.current_load(Wood), 6) self.assertEqual(building.container.current_load(Cabbage), 4) self.assertEqual(building.container.current_load(Stone), 0) building.produce_resources() self.assertEqual(building.container.current_load(Fish), 0) self.assertEqual(building.container.current_load(Wood), 1) self.assertEqual(building.container.current_load(Cabbage), 1) self.assertEqual(building.container.current_load(Stone), 1)
def test_add_resource_product_creates_a_new_product_for_a_specified_resource(self): # noqa plant = ResourcePlant() plant.add_resource_product(Fish, 10) self.assertIn(Fish.name, plant.resource_products.keys()) self.assertEqual(plant.resource_products[Fish.name]['load'], 10) self.assertIs(plant.resource_products[Fish.name]['type'], Fish)
def test_digest_does_nothing_if_the_cargo_container_cannot_unload_requirements_or_load_products(self): # noqa tray = SlottedCargoContainer() tray.add_resource_slot(Fish, 10) tray.add_resource_slot(Wood, 10) tray.add_resource_slot(Cabbage, 10) tray.load_cargo(Fish, 3) tray.load_cargo(Wood, 5) tray.load_cargo(Cabbage, 4) plant1 = ResourcePlant() plant1.add_resource_requirement(Fish, 4) plant1.add_resource_requirement(Wood, 2) plant1.add_resource_product(Cabbage, 6) plant1.digest(tray) self.assertEqual(tray.cargo_slots[Fish.name]['load'], 3) self.assertEqual(tray.cargo_slots[Wood.name]['load'], 5) self.assertEqual(tray.cargo_slots[Cabbage.name]['load'], 4) plant2 = ResourcePlant() plant2.add_resource_requirement(Fish, 3) plant2.add_resource_requirement(Wood, 2) plant2.add_resource_product(Cabbage, 7) plant2.digest(tray) self.assertEqual(tray.cargo_slots[Fish.name]['load'], 3) self.assertEqual(tray.cargo_slots[Wood.name]['load'], 5) self.assertEqual(tray.cargo_slots[Cabbage.name]['load'], 4)
def __init__(self): super().__init__() self.container.add_resource_slot(Fish, 10) fish_plant = ResourcePlant() fish_plant.add_resource_product(Fish, 3) self.add_resource_plant(fish_plant)
def __init__(self): super().__init__() self.container.add_resource_slot(IronOre, 5) iron_ore_plant = ResourcePlant() iron_ore_plant.add_resource_product(IronOre, 1) self.add_resource_plant(iron_ore_plant)