def test_produce_consume_inputs(self):
     LoadOperation(Material("water", 1),
                   self.four_a_pain,
                   worker=self.worker).run()
     ProduceOperation(self.four_a_pain, worker=self.worker).run(during=5)
     self.assertRaises(InvalidInputLoaded,
                       ProduceOperation(self.four_a_pain,
                                        worker=self.worker).run,
                       during=5)
 def test_chained_production_in_sequence(self):
     # Machine A -> Machine B
     machine_b, spec, stock_zone = create_machine(material_type_input="plank", material_type_output="furniture")
     machine_b.inputs_stocking_zone = self.machine.output_stocking_zone
     StartOperation(production_unit=machine_b, time_to_perform=1, worker=self.worker).run(during=1)
     LoadOperation(Material(type="wood", quantity=1), production_unit=self.machine, worker=self.worker).run()
     ProduceOperation(production_unit=self.machine, worker=self.worker).run()
     ProduceOperation(production_unit=machine_b, worker=self.worker).run()
     self.assertEquals(len(machine_b.get_outputs()), 1)
    def test_production_unit_with_stocking_area(self):
        stock_zone = StockingZone()
        self.loaded_production_unit.output_stocking_zone = stock_zone

        ProduceOperation(self.loaded_production_unit, worker=self.worker).run()

        self.assertEquals(stock_zone.count(), 1)
 def test_produce_operation(self):
     ProduceOperation(self.loaded_production_unit, worker=self.worker).run()
     self.assertEquals(self.loaded_production_unit.get_state(),
                       ProductionUnit.PRODUCING)
     self.assertEquals(len(self.loaded_production_unit.get_outputs()), 1)
     self.assertEquals(self.loaded_production_unit.get_outputs()[0].type,
                       "output")
    def test_slower_machine_configuration(self):
        slower_gp, spec, zone = create_machine(material_type_input="yarn",
                                               rate=0.5)
        slower_gp.perform_next_operation(self.worker)
        slower_gp.perform_next_operation(self.worker)

        ProduceOperation(slower_gp, worker=self.worker).run(during=2)
        self.assertEquals(len(slower_gp.get_outputs()), 1)
 def test_production_unit_create_a_protocol(self):
     self.machine, spec, zone = create_machine(material_type_input="yarn")
     self.assertEquals(self.machine.protocol.next(),
                       StartOperation(production_unit=self.machine))
     self.assertEquals(
         self.machine.protocol.next(),
         LoadOperation(Material("yarn"), production_unit=self.machine))
     self.assertEquals(self.machine.protocol.next(),
                       ProduceOperation(production_unit=self.machine))
    def test_complete_failure(self):
        ProduceOperation(production_unit=self.loaded_production_unit,
                         worker=self.worker).run()
        self.loaded_production_unit.add_event(Failure())
        self.assertEquals(self.loaded_production_unit.get_state(),
                          ProductionUnit.FAILURE)

        self.loaded_production_unit.add_event(Fix())
        self.assertEquals(self.loaded_production_unit.get_state(),
                          ProductionUnit.STARTED)
    def test_hour_of_production_scenario_with_more_load(self):
        # load then produce then load, etc
        # 1 minute to load 2, 2 minutes to produce 2, sequentially
        # leading to 40 produce in one hour
        load_op = LoadOperation(Material(type="wood", quantity=2), time_to_perform=1, production_unit=self.machine, worker=self.worker)
        product_op = ProduceOperation(production_unit=self.machine)

        operation_list = [load_op, product_op]
        process = Process(self.machine, operation_list)
        process.run(60)

        self.assertEquals(self.stock_zone.count(), 40)
    def test_hour_of_production_scenario(self):
        # load then produce then load, etc
        # 1 minute to load, 1 minute to produce 1, sequentially
        # leading to 30 produce in one hour
        load_op = LoadOperation(Material(type="wood", quantity=1), production_unit=self.machine, worker=self.worker)
        product_op = ProduceOperation(production_unit=self.machine, worker=self.worker)

        operation_list = [load_op, product_op]
        process = Process(self.machine, operation_list)
        process.run(60)

        self.assertEquals(self.stock_zone.count(), 30)
    def test_hour_of_production_with_unloading(self):
        # Load for 1 minute, produce for 1 minute, unload for 1 minute
        load_op = LoadOperation(Material(type="wood", quantity=1), time_to_perform=1, production_unit=self.machine, worker=self.worker)

        secondary_area = StockingZone()
        unload_op = UnloadOperation(quantity=1, zone=secondary_area, time_to_perform=1, production_unit=self.machine, worker=self.worker)
        product_op = ProduceOperation(production_unit=self.machine)

        operation_list = [load_op, product_op, unload_op]
        process = Process(self.machine, operation_list)
        process.run(180)

        self.assertEquals(secondary_area.count(), 60)
    def test_production_unit_with_limited_stocking_area(self):
        stock_zone = StockingZone(size=3)
        self.loaded_production_unit.output_stocking_zone = stock_zone

        LoadOperation(Material("yarn", 10),
                      self.loaded_production_unit,
                      worker=self.worker).run()
        try:
            ProduceOperation(self.loaded_production_unit,
                             worker=self.worker).run(during=5)
        except Event:
            pass

        self.assertEquals(stock_zone.count(), 3)
    def test_process_step_by_step(self):
        # load then produce then load, etc
        # 1 minute to load, 1 minute to produce 1, sequentially
        # leading to 30 produce in one hour
        load_op = LoadOperation(Material(type="wood", quantity=1), time_to_perform=1, production_unit=self.machine, worker=self.worker)
        product_op = ProduceOperation(production_unit=self.machine, worker=self.worker)

        operation_list = [load_op, product_op]
        process = Process(self.machine, operation_list)
        process.run( 1)

        self.assertEquals(self.stock_zone.count(), 0)

        process.run(1)
        self.assertEquals(self.stock_zone.count(), 1)
    def test_produce_operation(self):
        StartOperation(production_unit=self.machine,worker=self.worker).run(during=1)
        LoadOperation(self.input, production_unit=self.machine, time_to_perform=1, worker=self.worker).run(during=1)
        produce_op = ProduceOperation(production_unit=self.machine)

        produce_op.run(during=1)
        self.assertEquals(len(self.machine.get_outputs()), 0)

        produce_op.run(during=3)
        self.assertEquals(len(self.machine.get_outputs()), 1)
    def test_parallel_process(self):
        load_op = LoadOperation(Material(type="wood", quantity=1), production_unit=self.machine, worker=self.worker)

        secondary_area = StockingZone()
        unload_op = UnloadOperation(quantity=10, zone=secondary_area, production_unit=self.machine, worker=self.worker)
        product_op = ProduceOperation(production_unit=self.machine, worker=self.worker)

        process_1_operations = [load_op, product_op]
        process_2_operations = [unload_op]
        process_1 = Process(self.machine, process_1_operations)
        process_2 = Process(self.machine, process_2_operations)

        main_process = ParallelProcess([process_1, process_2])
        main_process.run(1)

        self.assertEquals(secondary_area.count(), 0)

        main_process.run(3)
        self.assertEquals(secondary_area.count(), 2)

        main_process.run(56)
        self.assertEquals(secondary_area.count(), 30)
 def test_multiple_inputs(self):
     self.assertRaises(InvalidInputLoaded,
                       ProduceOperation(self.four_a_pain,
                                        worker=self.worker).run,
                       during=5)
 def test_out_of_stock(self):
     self.assertRaises(InvalidInputLoaded,
                       ProduceOperation(self.loaded_production_unit,
                                        worker=self.worker).run,
                       during=3)
 def test_produce_without_input(self):
     self.assertRaises(InvalidInputLoaded,
                       ProduceOperation(
                           production_unit=self.started_production_unit,
                           worker=self.worker).run,
                       during=1)