def test_raises_exception_if_number_of_worker_pairs_exceeds_number_of_conveyor_belt_slots(
            self):
        factory_config = FactoryConfigFactory(number_of_worker_pairs=3,
                                              number_of_conveyor_belt_slots=1)
        with pytest.raises(FactoryConfigError) as exception:
            FactoryFloorFactory(factory_config=factory_config)

        assert exception.value.args == (
            'Improperly configured FactoryFloor - check factory_config. number_of_worker_pairs cannot exceed '
            'number_of_conveyor_belt_slots.', )
    def test_basic_run_belt_run_out_of_feed_items(self):
        feeder = SequentialFeederFactory(item_names=['1'])
        factory_floor: FactoryFloor = FactoryFloorFactory(feeder=feeder)

        with pytest.raises(FactoryConfigError) as exception:
            factory_floor.run()

        assert exception.value.args == (
            'Insufficient amount of items available in the feed_input of the Feeder. Please check your configuration.',
        )
    def test_run_factory_two_products_created_by_workers_on_slot_zero(self):
        feeder = SequentialFeederFactory(item_names=[
            'A', 'B', 'A', 'B', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E'
        ])
        factory_floor: FactoryFloor = FactoryFloorFactory(feeder=feeder)
        factory_floor.factory_config.number_of_simulation_steps = 13
        factory_floor.add_workers()
        factory_floor.run()

        assert factory_floor.receiver.received_item_names == [
            'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'P', 'E', 'P', 'E'
        ]
    def test_run_factory_worker_ignores_item_not_required(self):
        feeder = SequentialFeederFactory(item_names=[
            'A', 'A', 'A', 'B', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E', 'E'
        ])
        factory_floor: FactoryFloor = FactoryFloorFactory(feeder=feeder)
        factory_floor.factory_config.number_of_simulation_steps = 13
        factory_floor.factory_config.number_of_worker_pairs = 1
        factory_floor.add_workers()
        factory_floor.run()

        assert factory_floor.receiver.received_item_names == [
            'E', 'E', 'E', 'E', 'E', 'A', 'E', 'E', 'E', 'E', 'E', 'P', 'E'
        ]
    def test_basic_run_belt(self, factory_floor):
        feeder = SequentialFeederFactory(
            item_names=['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'])
        factory_floor: FactoryFloor = FactoryFloorFactory(feeder=feeder)
        factory_floor.run()
        assert factory_floor.receiver.received_item_names == [
            factory_floor.factory_config.empty_code,
            factory_floor.factory_config.empty_code,
            factory_floor.factory_config.empty_code, '1', '2', '3', '4', '5',
            '6', '7'
        ]

        assert factory_floor.time == 10
 def factory_floor(self, factory_config, feeder, receiver,
                   conveyor_belt) -> FactoryFloor:
     return FactoryFloorFactory(factory_config=factory_config,
                                feeder=feeder,
                                receiver=receiver,
                                conveyor_belt=conveyor_belt)