def setUp(self):
        self.unaffected_production_unit, spec, zone = create_machine(
            material_type_input="yarn")

        self.worker = Worker()
        self.affected_production_unit = ProductionUnit(spec)

        self.inputs = Material("yarn")
        self.started_production_unit = ProductionUnit(spec)
        self.started_production_unit.perform_next_operation(self.worker)

        self.loaded_production_unit = ProductionUnit(spec)
        self.loaded_production_unit.perform_next_operation(self.worker)
        self.loaded_production_unit.perform_next_operation(self.worker)

        config = {'rate_by_minute': 0.2}
        spec_four = Specification()
        spec_four.add(
            MaterialInputConstraint(Material(type="flour", quantity=2)))
        spec_four.add(
            MaterialInputConstraint(Material(type="water", quantity=1)))
        spec_four.add_output_material(Material("bread", 1))

        self.four_a_pain = ProductionUnit(spec_four, config)

        self.four_a_pain.perform_next_operation(self.worker)
        self.four_a_pain.perform_next_operation(self.worker)
    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_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_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_add_skill_constraint_to_operation(self):
        tech_production_unit, spec, zone = create_machine(material_type_input="iron")

        start_op = StartOperation(tech_production_unit, worker=self.worker)
        start_op.add_constraint(SkillConstraint(skill_name="blacksmith"))

        self.assertRaises(CannotPerformOperation, start_op.run)

        blacksmith = Worker()
        blacksmith.skills.append("blacksmith")
        StartOperation(tech_production_unit, worker=blacksmith).run()
        self.assertEquals(tech_production_unit.get_state(), ProductionUnit.STARTED)
    def test_24_hours_shifts(self):
        # 1 hour to load, 1 hour to produce
        # produce 2 every 2 hours
        # ie 24 - 1 (1 to start the machine) / 2 = 10
        machine, spec, stock = create_machine(stocking_zone_size=None)
        factory = Factory()
        factory.add_worker(Worker(working_hour = 8 * 60))
        factory.add_worker(Worker(working_hour = 8 * 60))
        factory.add_worker(Worker(working_hour = 8 * 60))
        factory.add_production_unit(machine)
        factory.run(24 * 60)

        self.assertEquals(stock.count(), 720 - 1)
    def test_add_skill_constraint_to_operation(self):
        tech_production_unit, spec, zone = create_machine(
            material_type_input="iron")

        start_op = StartOperation(tech_production_unit, worker=self.worker)
        start_op.add_constraint(SkillConstraint(skill_name="blacksmith"))

        self.assertRaises(CannotPerformOperation, start_op.run)

        blacksmith = Worker()
        blacksmith.skills.append("blacksmith")
        StartOperation(tech_production_unit, worker=blacksmith).run()
        self.assertEquals(tech_production_unit.get_state(),
                          ProductionUnit.STARTED)
    def setUp(self):
        self.unaffected_production_unit, spec, zone = create_machine(material_type_input="yarn")

        self.worker = Worker()
        self.affected_production_unit = ProductionUnit(spec)

        self.inputs = Material("yarn")
        self.started_production_unit = ProductionUnit(spec)
        self.started_production_unit.perform_next_operation(self.worker)

        self.loaded_production_unit = ProductionUnit(spec)
        self.loaded_production_unit.perform_next_operation(self.worker)
        self.loaded_production_unit.perform_next_operation(self.worker)

        config = {'rate_by_minute': 0.2}
        spec_four = Specification()
        spec_four.add(MaterialInputConstraint(Material(type="flour", quantity=2)))
        spec_four.add(MaterialInputConstraint(Material(type="water", quantity=1)))
        spec_four.add_output_material(Material("bread", 1))

        self.four_a_pain = ProductionUnit(spec_four, config)

        self.four_a_pain.perform_next_operation(self.worker)
        self.four_a_pain.perform_next_operation(self.worker)
 def setUp(self):
     self.machine, spec, self.stock_zone = create_machine(material_type_input="wood", material_type_output="plank")
     self.worker = Worker()
     StartOperation(production_unit=self.machine, time_to_perform=1, worker=self.worker).run(during=1)
Exemple #11
0
 def setUp(self):
     machine, spec, stock = create_machine(stocking_zone_size=None)
     self.factory = get_factory(config)
     self.http_client = tornado.httpclient.AsyncHTTPClient()
 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 setUp(self):
     machine, spec, stock = create_machine(stocking_zone_size=None)
     self.factory = get_factory(config)
     self.http_client = tornado.httpclient.AsyncHTTPClient()