Exemplo n.º 1
0
def test_error_guessing_dead_features_case_1() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)
    feature_4 = Feature("D", None, None, False)
    feature_5 = Feature("E", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 1, 1)
    relation_2 = Relation(feature_1, [feature_3], 1, 1)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    relation_3 = Relation(feature_3, [feature_4, feature_5], 1, 1)

    feature_3.add_relation(relation_3)

    node_1 = Node(ASTOperation.EXCLUDES)
    node_1.left = Node("D")
    node_1.right = Node("B")
    ast_1 = AST(node_1)
    ctc_1 = Constraint("ctc_1", ast_1)

    model = FeatureModel(feature_1, [ctc_1])
    path = normalize_path("error-guessing/dead-features/case1/df-case1")
    run(path, model)
Exemplo n.º 2
0
def test_relationships_mandatory_alternative() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)
    feature_4 = Feature("D", None, None, True)
    feature_5 = Feature("E", None, None, True)
    feature_6 = Feature("F", None, None, True)
    feature_7 = Feature("G", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 1, 1)
    relation_2 = Relation(feature_1, [feature_3, feature_4], 1, 1)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    relation_3 = Relation(feature_2, [feature_5, feature_6], 1, 1)

    feature_2.add_relation(relation_3)

    relation_4 = Relation(feature_3, [feature_7], 1, 1)

    feature_3.add_relation(relation_4)

    model = FeatureModel(feature_1)
    path = normalize_path(
        "relationships/mandatory-alternative/mandatory-alternative")
    run(path, model)
Exemplo n.º 3
0
def test_relationships_requires_excludes() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 0, 1)
    relation_2 = Relation(feature_1, [feature_3], 0, 1)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    node_1 = Node(ASTOperation.REQUIRES)
    node_1.left = Node("B")
    node_1.right = Node("C")
    ast_1 = AST(node_1)
    ctc_1 = Constraint("ctc_1", ast_1)

    node_2 = Node(ASTOperation.EXCLUDES)
    node_2.left = Node("B")
    node_2.right = Node("C")
    ast_2 = AST(node_2)
    ctc_2 = Constraint("ctc_1", ast_2)

    model = FeatureModel(feature_1, [ctc_1, ctc_2])
    path = normalize_path(
        "relationships/requires-excludes/requires-excludes")
    run(path, model)
Exemplo n.º 4
0
def test_relationships_or_alternative() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)
    feature_4 = Feature("D", None, None, True)
    feature_5 = Feature("E", None, None, True)
    feature_6 = Feature("F", None, None, True)
    feature_7 = Feature("G", None, None, True)
    feature_8 = Feature("H", None, None, True)
    feature_9 = Feature("I", None, None, True)

    relation_1 = Relation(feature_1, [feature_2, feature_3], 1, 1)
    relation_2 = Relation(feature_1, [feature_4, feature_5], 1, 2)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    relation_3 = Relation(feature_2, [feature_6, feature_7], 1, 2)

    feature_2.add_relation(relation_3)

    relation_4 = Relation(feature_5, [feature_8, feature_9], 1, 1)

    feature_5.add_relation(relation_4)

    model = FeatureModel(feature_1)
    path = normalize_path(
        "relationships/or-alternative/or-alternative")
    run(path, model)
Exemplo n.º 5
0
def test_error_guessing_redundancies_case_2() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)
    feature_4 = Feature("D", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 0, 1)
    relation_2 = Relation(feature_1, [feature_3], 1, 1)
    relation_3 = Relation(feature_1, [feature_4], 1, 1)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)
    feature_1.add_relation(relation_3)

    node_1 = Node(ASTOperation.REQUIRES)
    node_1.left = Node("C")
    node_1.right = Node("B")
    ast_1 = AST(node_1)
    ctc_1 = Constraint("ctc_1", ast_1)

    node_2 = Node(ASTOperation.REQUIRES)
    node_2.left = Node("D")
    node_2.right = Node("B")
    ast_2 = AST(node_2)
    ctc_2 = Constraint("ctc_2", ast_2)

    model = FeatureModel(feature_1, [ctc_1, ctc_2])
    path = normalize_path(
        "error-guessing/redundancies/case2/r-case2")
    run(path, model)
Exemplo n.º 6
0
def test_refinement_alternative_no_parent_last_child() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)
    feature_4 = Feature("D", None, None, True)
    feature_5 = Feature("E", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 0, 1)
    relation_2 = Relation(feature_1, [feature_5], 1, 1)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    relation_3 = Relation(feature_2, [feature_3, feature_4], 1, 1)

    feature_2.add_relation(relation_3)

    node_1 = Node(ASTOperation.EXCLUDES)
    node_1.left = Node("E")
    node_1.right = Node("B")
    ast_1 = AST(node_1)
    ctc_1 = Constraint("ctc_1", ast_1)

    node_2 = Node(ASTOperation.REQUIRES)
    node_2.left = Node("E")
    node_2.right = Node("D")
    ast_2 = AST(node_2)
    ctc_2 = Constraint("ctc_2", ast_2)

    model = FeatureModel(feature_1, [ctc_1, ctc_2])
    path = normalize_path(
        "refinement/alternative-noParentLastChild/alternative-noParentLastChild")
    run(path, model)
Exemplo n.º 7
0
def test_relationships_optional_or() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)
    feature_4 = Feature("D", None, None, True)
    feature_5 = Feature("E", None, None, True)
    feature_6 = Feature("F", None, None, True)
    feature_7 = Feature("G", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 0, 1)
    relation_2 = Relation(feature_1, [feature_3, feature_4], 1, 2)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    relation_3 = Relation(feature_2, [feature_5, feature_6], 1, 2)

    feature_2.add_relation(relation_3)

    relation_4 = Relation(feature_3, [feature_7], 0, 1)

    feature_3.add_relation(relation_4)

    model = FeatureModel(feature_1)
    path = normalize_path(
        "relationships/optional-or/optional-or")
    run(path, model)
Exemplo n.º 8
0
def test_refinement_df_alternative_excludes() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)
    feature_4 = Feature("D", None, None, True)
    feature_5 = Feature("E", None, None, False)

    relation_1 = Relation(feature_1, [feature_2], 1, 1)
    relation_2 = Relation(feature_1, [feature_3], 0, 1)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    relation_3 = Relation(feature_3, [feature_4, feature_5], 1, 1)

    feature_3.add_relation(relation_3)

    node_1 = Node(ASTOperation.REQUIRES)
    node_1.left = Node("B")
    node_1.right = Node("D")
    ast_1 = AST(node_1)
    ctc_1 = Constraint("ctc_1", ast_1)

    model = FeatureModel(feature_1, [ctc_1])
    path = normalize_path(
        "refinement/df-alternative-excludes/df-alternative-excludes")
    run(path, model)
Exemplo n.º 9
0
def test_relationships_mandatory_optional() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)
    feature_4 = Feature("D", None, None, True)
    feature_5 = Feature("E", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 1, 1)
    relation_2 = Relation(feature_1, [feature_3], 0, 1)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    relation_3 = Relation(feature_2, [feature_4], 0, 1)

    feature_2.add_relation(relation_3)

    relation_4 = Relation(feature_3, [feature_5], 1, 1)

    feature_3.add_relation(relation_4)

    model = FeatureModel(feature_1)
    path = normalize_path(
        "relationships/mandatory-optional/mandatory-optional")
    run(path, model)
Exemplo n.º 10
0
def test_refinement_or_no_alternative() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)
    feature_4 = Feature("D", None, None, True)
    feature_5 = Feature("E", None, None, False)

    relation_1 = Relation(feature_1, [feature_2], 1, 1)
    relation_2 = Relation(feature_1, [feature_5], 1, 1)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    relation_3 = Relation(feature_2, [feature_3, feature_4], 1, 2)

    feature_2.add_relation(relation_3)

    node_1 = Node(ASTOperation.REQUIRES)
    node_1.left = Node("E")
    node_1.right = Node("D")
    ast_1 = AST(node_1)
    ctc_1 = Constraint("ctc_1", ast_1)

    node_2 = Node(ASTOperation.REQUIRES)
    node_2.left = Node("E")
    node_2.right = Node("C")
    ast_2 = AST(node_2)
    ctc_2 = Constraint("ctc_2", ast_2)

    model = FeatureModel(feature_1, [ctc_1, ctc_2])
    path = normalize_path(
        "refinement/or-noAlternative/or-noAlternative")
    run(path, model)
Exemplo n.º 11
0
 def execute(self, model: FeatureModel) -> 'FMCountLeafs':
     number = 0
     for feat in model.get_features():
         if len(feat.get_relations()) == 0:
             number += 1
     self.number_of_leafs = number
     return self
Exemplo n.º 12
0
def test_error_guessing_false_optional_features_case_3() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, False)
    feature_4 = Feature("D", None, None, False)
    feature_5 = Feature("E", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 1, 1)
    relation_2 = Relation(feature_1, [feature_3], 0, 1)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    relation_3 = Relation(feature_3, [feature_4, feature_5], 1, 2)

    feature_3.add_relation(relation_3)

    node_1 = Node(ASTOperation.REQUIRES)
    node_1.left = Node("B")
    node_1.right = Node("D")
    ast_1 = AST(node_1)
    ctc_1 = Constraint("ctc_1", ast_1)

    model = FeatureModel(feature_1, [ctc_1])
    path = normalize_path(
        "error-guessing/false-optional-features/case3/fof-case3")
    run(path, model)
Exemplo n.º 13
0
def test_error_guessing_dead_features_case_8() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, False)
    feature_3 = Feature("C", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 0, 1)
    relation_2 = Relation(feature_1, [feature_3], 0, 1)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    node_1 = Node(ASTOperation.EXCLUDES)
    node_1.left = Node("B")
    node_1.right = Node("C")
    ast_1 = AST(node_1)
    ctc_1 = Constraint("ctc_1", ast_1)

    node_2 = Node(ASTOperation.REQUIRES)
    node_2.left = Node("B")
    node_2.right = Node("C")
    ast_2 = AST(node_2)
    ctc_2 = Constraint("ctc_1", ast_2)

    model = FeatureModel(feature_1, [ctc_1, ctc_2])
    path = normalize_path("error-guessing/dead-features/case8/df-case8")
    run(path, model)
Exemplo n.º 14
0
 def execute(self, model: FeatureModel) -> 'FMAverageBranchingFactor':
     features = model.get_features()
     childrens = 0
     for feat in features:
         for relation in feat.get_relations():
             childrens += len(relation.children)
     self.average_branching_factor = round(childrens / len(features))
     return self
def average_branching_factor(feature_model: FeatureModel,
                             precision: int = 2) -> float:
    nof_branches = 0
    nof_children = 0
    for feature in feature_model.get_features():
        if feature.get_relations():
            nof_branches += 1
            nof_children += sum(
                len(r.children) for r in feature.get_relations())
    return round(nof_children / nof_branches, precision)
Exemplo n.º 16
0
def test_relationships_mandatory() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 1, 1)

    feature_1.add_relation(relation_1)

    model = FeatureModel(feature_1)
    path = normalize_path(
        "relationships/mandatory/mandatory")
    run(path, model)
Exemplo n.º 17
0
def test_relationships_optional() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 0, 1)

    feature_1.add_relation(relation_1)

    model = FeatureModel(feature_1)
    path = normalize_path(
        "relationships/optional/optional")
    run(path, model)
Exemplo n.º 18
0
    def parse_features(self, words: list[str], model: FeatureModel) -> Feature:
        name = words[0].replace(':', '')
        words.pop(0)

        if name in self.parents:
            print('This AFM contains duplicated feature names',
                  file=sys.stderr)
            raise DuplicatedFeature
        self.parents.append(name)

        feature_parent = Feature(name, [])
        if name in self.name_feature:
            feature_parent = self.name_feature[name]
        else:
            model.features.append(feature_parent)
            model.root = feature_parent
            self.name_feature[name] = feature_parent

        is_grouped = False
        is_or = False
        for word in words:
            if is_grouped:
                if is_or:
                    relation.card_max += 1
                if word.__contains__('}'):
                    word = word.replace('}', '').replace(';', '')
                    self.add_feature(relation, word, model)
                    is_or = False
                    is_grouped = False
                else:
                    word = word.replace('{', '').replace(';', '')
                    self.add_feature(relation, word, model)
            else:
                if word.__contains__('[1,'):
                    is_grouped = True
                    relation = self.parse_relation('Alternative/Or',
                                                   feature_parent)
                    if not word.__eq__('[1,1]'):
                        relation.card_max = 0
                        is_or = True
                    continue
                elif word.__contains__('[') and word.__contains__(']'):
                    relation = self.parse_relation('Optional', feature_parent)
                    word = word.replace('[', '').replace(']',
                                                         '').replace(';', '')
                    self.add_feature(relation, word, model)
                else:
                    relation = self.parse_relation('Mandatory', feature_parent)
                    word = word.replace(';', '')
                    self.add_feature(relation, word, model)
            model.relations.append(relation)
        return feature_parent
Exemplo n.º 19
0
def test_relationships_alternative() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)

    relation_1 = Relation(feature_1, [feature_2, feature_3], 1, 1)

    feature_1.add_relation(relation_1)

    model = FeatureModel(feature_1)
    path = normalize_path(
        "relationships/alternative/alternative")
    run(path, model)
Exemplo n.º 20
0
    def transform(self):
        rootcounter = 1
        tree = ElementTree.parse(self.path)
        xml_root = tree.getroot()
        # iterate over child of the xml root element
        for child in xml_root:
            if child.tag.casefold() == 'feature':
                rootcounter += 1
                root = self.parse_feature(child)
                fm = FeatureModel(root,[])
            elif child.tag.casefold() == 'excludes' or child.tag.casefold() == 'requires':
                ctc=self.parse_ctc(child)
                fm.ctcs.append(ctc)
            else:
                print("This XML contains non supported elements", file=sys.stderr)

        return fm
Exemplo n.º 21
0
def test_error_guessing_core_features_case_2() -> None:
    feature_1 = Feature("A", None, None, False)
    feature_2 = Feature("B", None, None, False)

    relation_1 = Relation(feature_1, [feature_2], 0, 1)

    feature_1.add_relation(relation_1)

    node_1 = Node(ASTOperation.REQUIRES)
    node_1.left = Node("A")
    node_1.right = Node("B")
    ast_1 = AST(node_1)

    ctc_1 = Constraint("ctc_1", ast_1)

    model = FeatureModel(feature_1, [ctc_1])
    path = normalize_path("error-guessing/core-features/case2/cf-case2")
    run(path, model)
Exemplo n.º 22
0
def test_refinement_optional_alternative_valid_p() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)
    feature_4 = Feature("D", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 0, 1)

    feature_1.add_relation(relation_1)

    relation_2 = Relation(feature_2, [feature_3, feature_4], 1, 1)

    feature_2.add_relation(relation_2)

    model = FeatureModel(feature_1)
    path = normalize_path(
        "refinement/optional-alternativeValidP/optional-alternativeVP")
    run(path, model)
def get_false_optional_features(sat_model: PySATModel, feature_model: FeatureModel) -> list[Any]:
    real_optional_features = [f for f in feature_model.get_features() 
                              if not f.is_root() and not f.is_mandatory()]

    result = []
    solver = Glucose3()
    for clause in sat_model.get_all_clauses():
        solver.add_clause(clause)

    for feature in real_optional_features:
        variable = sat_model.variables.get(feature.name)
        parent_variable = sat_model.variables.get(feature.get_parent().name)
        assert variable is not None
        satisfiable = solver.solve(assumptions=[parent_variable, -variable])
        if not satisfiable:
            result.append(feature.name)
    solver.delete()
    return result
Exemplo n.º 24
0
def test_relationships_alternative_requires() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)

    relation_1 = Relation(feature_1, [feature_2, feature_3], 1, 1)

    feature_1.add_relation(relation_1)

    node_1 = Node(ASTOperation.REQUIRES)
    node_1.left = Node("B")
    node_1.right = Node("C")
    ast_1 = AST(node_1)
    ctc_1 = Constraint("ctc_1", ast_1)

    model = FeatureModel(feature_1, [ctc_1])
    path = normalize_path(
        "relationships/alternative-requires/alternative-requires")
    run(path, model)
Exemplo n.º 25
0
def test_relationships_or_excludes() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)

    relation_1 = Relation(feature_1, [feature_2, feature_3], 1, 2)

    feature_1.add_relation(relation_1)

    node_1 = Node(ASTOperation.EXCLUDES)
    node_1.left = Node("B")
    node_1.right = Node("C")
    ast_1 = AST(node_1)
    ctc_1 = Constraint("ctc_1", ast_1)

    model = FeatureModel(feature_1, [ctc_1])
    path = normalize_path(
        "relationships/or-excludes/or-excludes")
    run(path, model)
Exemplo n.º 26
0
    def parse_features(self, words: list[str], model: FeatureModel) -> Feature:
        name = words[0].replace(":", "")
        words.pop(0)

        if name in self.parents:
            print("This AFM contains duplicated feature names", file=sys.stderr)
            raise DuplicatedFeature
        self.parents.append(name)

        feature_parent = Feature(name, [])
        if name in self.name_feature:
            feature_parent = self.name_feature[name]
        else:
            model.features.append(feature_parent)
            model.root = feature_parent
            self.name_feature[name] = feature_parent

        alternative_rel = "[1,1]"
        or_rel = "[1," + str(len(words) - 1) + "]"
        if words.__contains__(alternative_rel) or words.__contains__(or_rel):
            if words.__contains__(alternative_rel):
                words.remove(alternative_rel)
                relation = self.parse_relation("Alternative", feature_parent)
            elif words.__contains__(or_rel):
                words.remove(or_rel)
                relation = self.parse_relation("Or", feature_parent, len(words))
            model.relations.append(relation)
            for word in words:
                word = word.replace("{", "").replace("}", "").replace(";", "")
                self.add_feature(relation, word, model)
        else:
            for word in words:
                if word.__contains__("[") and word.__contains__("]"):
                    relation = self.parse_relation("Optional", feature_parent)
                    word = word.replace("[", "").replace("]", "").replace(";", "")
                    self.add_feature(relation, word, model)
                else:
                    relation = self.parse_relation("Mandatory", feature_parent)
                    word = word.replace(";", "")
                    self.add_feature(relation, word, model)
                model.relations.append(relation)
        return feature_parent
Exemplo n.º 27
0
def test_error_guessing_core_features_case_6() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 1, 1)
    relation_2 = Relation(feature_1, [feature_3], 1, 1)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    node_1 = Node(ASTOperation.EXCLUDES)
    node_1.left = Node("B")
    node_1.right = Node("C")
    ast_1 = AST(node_1)
    ctc_1 = Constraint("ctc_1", ast_1)

    model = FeatureModel(feature_1, [ctc_1])
    path = normalize_path("error-guessing/core-features/case6/cf-case6")
    run(path, model)
Exemplo n.º 28
0
def test_relationships_allrelationships() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)
    feature_4 = Feature("D", None, None, True)
    feature_5 = Feature("E", None, None, True)
    feature_6 = Feature("F", None, None, True)
    feature_7 = Feature("G", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 1, 1)
    relation_2 = Relation(feature_1, [feature_3], 0, 1)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    relation_3 = Relation(feature_2, [feature_4, feature_5], 1, 1)

    feature_2.add_relation(relation_3)

    relation_4 = Relation(feature_3, [feature_6, feature_7], 1, 2)

    feature_3.add_relation(relation_4)

    node_1 = Node(ASTOperation.REQUIRES)
    node_1.left = Node("E")
    node_1.right = Node("F")
    ast_1 = AST(node_1)
    ctc_1 = Constraint("ctc_1", ast_1)

    node_2 = Node(ASTOperation.EXCLUDES)
    node_2.left = Node("D")
    node_2.right = Node("G")
    ast_2 = AST(node_2)
    ctc_2 = Constraint("ctc_2", ast_2)

    model = FeatureModel(feature_1, [ctc_1, ctc_2])
    path = normalize_path(
        "relationships/allrelationships/allrelationships")
    run(path, model)
Exemplo n.º 29
0
    def transform(self):
        with open(self.path, 'r') as lines:
            lines = [line.strip() for line in lines.readlines() if line.strip() != ""]
        for line in lines:
            if line.__contains__("%Relationships"):
                index_r = lines.index(line)
            if line.__contains__("%Constraints"):
                index_c = lines.index(line)
        relations = lines[index_r + 1:index_c]
        constraints = lines[index_c + 1:]

        feature_model = FeatureModel(Feature("", []))
        for relation in relations:
            words = relation.split(" ")
            self.parse_features(words, feature_model)

        for constraint in constraints:
            constraint = constraint.replace(";", "")
            ctc = self.parse_ctc(constraint)
            feature_model.ctcs.append(ctc)

        return feature_model
Exemplo n.º 30
0
def test_refinement_alternative_odd_children() -> None:
    feature_1 = Feature("A", None, None, True)
    feature_2 = Feature("B", None, None, True)
    feature_3 = Feature("C", None, None, True)
    feature_4 = Feature("D", None, None, True)
    feature_5 = Feature("E", None, None, True)
    feature_6 = Feature("F", None, None, True)
    feature_7 = Feature("G", None, None, True)
    feature_8 = Feature("H", None, None, True)

    relation_1 = Relation(feature_1, [feature_2], 1, 1)
    relation_2 = Relation(feature_1, [feature_8], 1, 1)

    feature_1.add_relation(relation_1)
    feature_1.add_relation(relation_2)

    relation_3 = Relation(
        feature_2, [feature_3, feature_4, feature_5, feature_6, feature_7], 1, 1)

    feature_2.add_relation(relation_3)

    node_1 = Node(ASTOperation.REQUIRES)
    node_1.left = Node("H")
    node_1.right = Node("G")
    ast_1 = AST(node_1)
    ctc_1 = Constraint("ctc_1", ast_1)

    node_2 = Node(ASTOperation.REQUIRES)
    node_2.left = Node("H")
    node_2.right = Node("E")
    ast_2 = AST(node_2)
    ctc_2 = Constraint("ctc_2", ast_2)

    model = FeatureModel(feature_1, [ctc_1, ctc_2])
    path = normalize_path(
        "refinement/alternative-oddChildren/alternative-oddChildren")
    run(path, model)