def test_invalid_input(self):
     input = Material("rocks")
     self.assertRaises(
         InvalidInputLoaded,
         LoadOperation(input,
                       production_unit=self.affected_production_unit,
                       worker=self.worker).run)
 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_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_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_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_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_load_operation(self):
        load_op = LoadOperation(self.input, production_unit=self.machine, time_to_perform=3, worker=self.worker)

        load_op.run(during=1)
        self.assertEquals(self.machine.inputs.count(), 1)

        load_op.run(during=2)
        self.assertEquals(self.machine.inputs.count(), 3)
    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_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_working_hour(self):
     eight_hour_worker = Worker(working_hour = 8 * 60)
     self.assertRaises(Event, LoadOperation(Material(type="wood", quantity=1), production_unit=self.machine, worker=eight_hour_worker).run, during=8*60 + 1)
 def test_has_worker_constraint(self):
     self.assertRaises(NoWorkerToPerformAction, LoadOperation(Material("k"), self.machine).run)
 def test_load_equals(self):
     op1 = LoadOperation(Material("input"),self.machine, self.worker)
     op2 = LoadOperation(Material("other"),self.machine, self.worker)
     op3 = LoadOperation(Material("input"),self.machine, self.worker)
     self.assertFalse(op1==op2)
     self.assertEquals(op1, op3)
 def test_cannot_start_without_worker(self):
     self.assertRaises(
         NoWorkerToPerformAction,
         LoadOperation(self.inputs, self.unaffected_production_unit).run)