def create_machine(material_type_input="input", material_type_output="output", stocking_zone_size=40, rate=1): spec = Specification() config = {"rate_by_minute": rate} spec.add(MaterialInputConstraint(Material(type=material_type_input, quantity=1))) spec.add_output_material(Material(type=material_type_output, quantity=1)) stock_zone = StockingZone(size=stocking_zone_size) machine = ProductionUnit(spec, config, output_stocking_zone=stock_zone) return machine, spec, stock_zone
def create_spec(materials, production_unit): spec = Specification() for input in production_unit.get("inputs", []): spec.add(MaterialInputConstraint(Material(type=input["input_type"], quantity=input["input_quantity"]))) for output in production_unit.get("outputs", []): spec.add_output_material(Material(type=output["input_type"], quantity=output["input_quantity"], price=materials[output["input_type"]]["price"])) return spec
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): spec = Specification() spec.add(MaterialInputConstraint(Material(type="wood", quantity=1))) spec.add_output_material(Material("Furniture", 1)) self.machine = ProductionUnit(spec, config={"rate_by_minute":0.25}) self.worker = Worker() self.input = Material("wood", quantity=3)
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 create_machine(material_type_input="input", material_type_output="output", stocking_zone_size=40, rate=1): spec = Specification() config = {'rate_by_minute': rate} spec.add( MaterialInputConstraint(Material(type=material_type_input, quantity=1))) spec.add_output_material(Material(type=material_type_output, quantity=1)) stock_zone = StockingZone(size=stocking_zone_size) machine = ProductionUnit(spec, config, output_stocking_zone=stock_zone) return machine, spec, stock_zone
def create_spec(materials, production_unit): spec = Specification() for input in production_unit.get("inputs", []): spec.add( MaterialInputConstraint( Material(type=input["input_type"], quantity=input["input_quantity"]))) for output in production_unit.get("outputs", []): spec.add_output_material( Material(type=output["input_type"], quantity=output["input_quantity"], price=materials[output["input_type"]]["price"])) return spec
class SpecificationTest(TestCase): def setUp(self): self.spec = Specification() self.spec.add( MaterialInputConstraint(Material(type="flour", quantity=1))) self.spec.add( MaterialInputConstraint(Material(type="water", quantity=2))) def test_validate_all_spec(self): input1 = Material("flour", quantity=3) input2 = Material("water", quantity=2) input3 = Material("water", quantity=1) self.assertFalse(self.spec.validate_all([input1])) self.assertFalse(self.spec.validate_all([input1, input3])) self.assertTrue(self.spec.validate_all([input1, input2])) def test_str(self): self.assertEquals( self.spec.__str__(), "Validate input is type of flour\nValidate input is type of water") def test_get_inputs(self): self.assertEquals(self.spec.get_inputs()[0], Material("flour", 1)) self.assertEquals(self.spec.get_inputs()[1], Material("water", 2))
class SpecificationTest(TestCase): def setUp(self): self.spec = Specification() self.spec.add(MaterialInputConstraint(Material(type="flour", quantity=1))) self.spec.add(MaterialInputConstraint(Material(type="water", quantity=2))) def test_validate_all_spec(self): input1 = Material("flour", quantity=3) input2 = Material("water", quantity=2) input3 = Material("water", quantity=1) self.assertFalse(self.spec.validate_all([input1])) self.assertFalse(self.spec.validate_all([input1, input3])) self.assertTrue(self.spec.validate_all([input1, input2])) def test_str(self): self.assertEquals(self.spec.__str__(), "Validate input is type of flour\nValidate input is type of water") def test_get_inputs(self): self.assertEquals(self.spec.get_inputs()[0], Material("flour", 1)) self.assertEquals(self.spec.get_inputs()[1], Material("water", 2))
def test_consume(self): spec = Specification() spec.add(MaterialInputConstraint(Material("input", 2))) self.input.consume(spec) self.assertEquals(self.input.quantity, 1)
def setUp(self): self.spec = Specification() self.spec.add( MaterialInputConstraint(Material(type="flour", quantity=1))) self.spec.add( MaterialInputConstraint(Material(type="water", quantity=2)))
def setUp(self): self.spec = Specification() self.spec.add(MaterialInputConstraint(Material(type="flour", quantity=1))) self.spec.add(MaterialInputConstraint(Material(type="water", quantity=2)))