def test_fake_optionals(): feature_model = FeatureModel( name=None, author=None, description=None, features=[ Feature( id=1, name="root", constraints=[ Root(destination=1), Mandatory(destination=3), Optional(destination=4), ], ), Feature(id=3, name="feature_3", constraints=[Mandatory(destination=4)]), Feature(id=4, name="feature_5", constraints=None), ], ) mz = MZFMSolver.from_feature_model(feature_model) assert mz.get_fake_optionals() == ["feature_3"]
def test_mini_store_model(): feature_model = FeatureModel( name=None, author=None, description=None, features=[ Feature(id=28, name="Index", constraints=None), Feature(id=29, name="Product", constraints=None), Feature(id=30, name="ProductStar", constraints=None), Feature( id=27, name="MiniStores", constraints=[ Root(destination=27), Mandatory(destination=28), Mandatory(destination=29), Mandatory(destination=30), ], ), ], ) mz = MZFMSolver.from_feature_model(feature_model) solutions = mz.get_solutions(get_all_solutions=True) assert len(solutions) == 1 assert mz.is_void_model() == False assert mz.is_fake_product_line() == True assert mz.get_dead_features() == None assert mz.get_fake_optionals() == None
async def validate_feature_model( *, solver_name: str, request: ValidateMultiple = Body( ..., example={ "mx_graph": "<mx_graph_xml>", "operations": ["is_void", "dead_features"], }, ) ) -> Validations: mx_graph = request.mx_graph operations = set(request.operations) feature_model = MXGraph.parse_string(mx_graph) feature_model = FeatureModel.create_from_dict(feature_model) solver = minizinc.Solver.lookup(solver_name) mz_fm_solver = MZFMSolver.from_feature_model(feature_model, solver=solver) validations = [] if "is_void" in operations: is_void = Validation(name="is_void", solution=mz_fm_solver.is_void_model()) validations.append(is_void) if "is_fake_product_line" in operations: is_fake_product_line = Validation( name="is_fake_product_line", solution=mz_fm_solver.is_fake_product_line()) validations.append(is_fake_product_line) if "dead_features" in operations: dead_features = mz_fm_solver.get_dead_features() dead_features = Validation( name="dead_features", solution=bool(dead_features), detail=dead_features, ) validations.append(dead_features) if "fake_optionals" in operations: fake_optionals = mz_fm_solver.get_fake_optionals() fake_optionals = Validation( name="fake_optionals", solution=bool(fake_optionals), detail=fake_optionals, ) validations.append(fake_optionals) return Validations(validations=validations, )
def test_mobile_phone_model(): feature_model = FeatureModel( name=None, author=None, description=None, features=[ Feature(id=31, name="Calls", constraints=None), Feature(id=34, name="GPS", constraints=[Excludes(destination=42)]), Feature( id=35, name="Screen", constraints=[ Cardinality(destination=[40, 41, 42], low_threshold="1", high_threshold="1") ], ), Feature(id=36, name="Media", constraints=[Or(destination=[37, 38])]), Feature(id=37, name="Camera", constraints=None), Feature(id=38, name="MP3", constraints=None), Feature(id=40, name="High Resolution", constraints=[Requires(destination=37)]), Feature(id=41, name="Cololur", constraints=None), Feature(id=42, name="Basic", constraints=None), Feature( id=30, name="Mobile Phone", constraints=[ Root(destination=30), Mandatory(destination=31), Optional(destination=34), Mandatory(destination=35), Optional(destination=36), ], ), ], ) mz = MZFMSolver.from_feature_model(feature_model) solutions = mz.get_solutions(get_all_solutions=True) assert len(solutions) == 6 assert mz.is_void_model() == False assert mz.is_fake_product_line() == False assert mz.get_dead_features() == ["feature_34", "feature_42"] assert mz.get_fake_optionals() == None
async def get_fake_optional_features( *, solver_name: str, request: Validate = Body( ..., example={ "feature_model": { "name": "string", "author": "string", "description": "string", "features": [ { "id": 28, "name": "Index" }, { "id": 29, "name": "Product" }, { "id": 30, "name": "ProductStar" }, { "constraints": [ { "destination": 27, "constraint_type": "root" }, { "constraint_type": "mandatory", "destination": 28 }, { "constraint_type": "mandatory", "destination": 29 }, { "constraint_type": "mandatory", "destination": 30 }, ], "id": 27, "name": "MiniStores", }, ], }, }, ) ) -> Validation: feature_model = FeatureModel.create_from_dict(request.feature_model.dict()) solver = minizinc.Solver.lookup(solver_name) mz_fm_solver = MZFMSolver.from_feature_model(feature_model, solver=solver) fake_optionals = mz_fm_solver.get_fake_optionals() return Validation( name="Has fake optionals", solution=bool(fake_optionals), detail=fake_optionals, )
async def get_all_solutions( *, solver_name: str, request: Solve = Body( ..., example={ "feature_model": { "name": "string", "author": "string", "description": "string", "features": [ { "id": 28, "name": "Index" }, { "id": 29, "name": "Product" }, { "id": 30, "name": "ProductStar" }, { "constraints": [ { "destination": 27, "constraint_type": "root" }, { "constraint_type": "mandatory", "destination": 28 }, { "constraint_type": "mandatory", "destination": 29 }, { "constraint_type": "mandatory", "destination": 30 }, ], "id": 27, "name": "MiniStores", }, ], }, }, ) ) -> Solution: feature_model = FeatureModel.create_from_dict(request.feature_model.dict()) solver = minizinc.Solver.lookup(solver_name) mz_fm_solver = MZFMSolver.from_feature_model(feature_model, solver=solver) return Solution(detail=mz_fm_solver.get_solutions(get_all_solutions=True))